1

I created a custom page, with my custom module.

Hook_Menu

$items['registered-products/%'] = array(
    'title' => t('Hello World'), // TRANSLATES FINE
    'page callback' => 'mymodule_product_page',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'file' => 'includes/mymodule.product_page.inc',
);

Template File

I created a template file (.tpl.php) for my custom page, in here I have:

<?php print t('hello world'); ?> <!-- DOES NOT TRANSLATE -->

RESULT

enter image description here

The t() translates in hook_menu, but on the template file it does not.

What do I have to do so the t() works to on template file?

  • 2
    Have you actually gone in and translated the word in the system? It won't happen automatically, you actually have to translate it. Some translations are provided by Drupal.org, which is why you're seeing - None - translated, but the rest needs to be done manually. – Jaypan Feb 12 '17 at 1:29
  • what do you want? Solution for this case or why function t doesn't work on template? – Jonh Apr 11 '18 at 8:28
  • @Jonh a solution that works on template file. – No Sssweat Apr 11 '18 at 8:29
  • @NoSssweat in Drupal 7 each t() invocation might create a seperate entry in the translation table ... did you check that there is no "Hello World" untranslated ? – GiorgosK Apr 11 '18 at 8:32
  • @GiorgosK if you are referring to the Translate Interface, I only see this and when I click edit, I see this. – No Sssweat Apr 11 '18 at 8:47
1
+50

The problem should be solved as soon as the strings are identical. In the provided code, hello world is not equal to Hello World.

Matching strings for translation is case sensitive.

| improve this answer | |
  • <?php print t('Hello World'); ?> Does not solve it. – No Sssweat Apr 11 '18 at 9:21
  • Is the context language for this call to t() German? E.g. access from a /de/node/XX URL? – Stefanos Petrakis Apr 11 '18 at 9:23
  • It's a custom page, from custom module, as my question mentions. /de/registration-products/{ product_id } – No Sssweat Apr 11 '18 at 9:23
  • 1
    Could you try this then t('Hello World', array(), array('langcode' => 'de')) inside the tpl file? – Stefanos Petrakis Apr 11 '18 at 9:25
  • 1
    The problem is the active language itself @StefanosPetrakis - if you look at t(), it gets the current language from $GLOBALS['language']->language if none is provided. There's nowhere else to get that from, so it looks like something is overriding the real current language code with an inaccurate one before the template is reached – Clive Apr 11 '18 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.