I have blocked out my HTML for Views UI Fields, Headers, and Footers. This is done in an attempt to be able to use t(string) and call functions, among other things. Here's an example:

In a Drupal field I have something like this:

<?php
print pg_render_degrees_details_header($nid) 
?>

And in degrees-details.rendered_html.inc I have this:

<?php
function pg_render_degrees_details_header ($nid) {
  $imgpath_logo = $base_path.'/sites/all/themes/SITE_NAME/images/Logo.png';
  $imgpath_replay = $base_path.'/sites/all/themes/SITE_NAME/images/keyboard_arrow_left_teal_48x48.png';
  $imgpath_save_exit = $base_path.'/sites/all/themes/SITE_NAME/images/save-exit.png';

  print('<div class="picture-game-modal-header">
    <img class="picture-game-modal-logo" src="'.$imgpath_logo.'" alt="logo" height="80" />
    <a class="picture-game-back-button ctools-use-modal" href="/picture-game-page/top-careers/degrees/'.$nid.'/nojs"><img class="replay-icon" src="'.$imgpath_replay.'">BACK</a>
  </div>
  <a class="picture-game-save-exit-button ctools-use-modal ga--pg-exit" href="/picture-game-page/save-and-exit/nojs">'.t('SAVE AND EXIT').'<img class="save-exit-icon" src="'.$imgpath_save_exit.'">
  </a>
  <div class="picture-game-save-details">Last Saved: '.t(get_time_last_saved()).'</div>
  <div class="modal-separator"></div>
</div>');
};
?>

Idiosyncratic, no?

Anyway, when I try to translate strings in Drupal land, I am given the entire block of HTML to translate. Drupal does not "find" the t(string)'s that I have in the .inc file. How can I get Drupal to find and incorporate those into the translation set? Or must I seriously restructure my architecture to get this to function properly?

Regards

Comments

Jaypan’s picture

There are possibly two issues here. The first is that you are using the t() function wrong. You should never pass variables through the t() function, only strings. You are not passing your string through, and you are passing a variable through. What you should be doing is this:

t('Last Saved: %last_saved', array('%last_saved' => get_time_last_saved()))

The other thing is that you will need to visit the page in the non-default language before the string is available for translation.

jamesbecker’s picture

Your suggestions helped immensely, thanks.