0

Alright, this one is probably easy but I found online documentation only little helpful and couldn't figure it out myself.

I run a custom module that renders a custom block programatically via function hook_block_view(). Assume that $block['content'] = 'Hello';. The custom string 'Hello' does not appear in the list of translatable strings (config/regional/translate/translate) but I want to display it in, say, Spanish ('Hola') when the site language is set to Spanish.

How do I translate it / make it appear in the list?

1 Answer 1

1

In order to make strings translation possible you need to pass it through the t function.

$block['content'] = t('Hello');
2
  • Thank you, this works. Unfortunately, if I use the same English string in two places it automatically uses the same Spanish translation in both places, which might not always be feasible. What is the right way to distinguish between two t('Hello')'s when I want to have two translations of the same word? I tried to add a custom context via t('Hello', array(), array('context' => 'custom context')) but the string does not appear on the translation interface when I search for it. Do I have to create custom contexts somewhere else before I can use them?
    – deinqwertz
    Jul 28, 2013 at 10:27
  • And even better, could I assign all strings from my custom module to a new text group "Custom Module" and still distinguish all strings from my custom module into contexts? Something like t('Hello', array(), array('textgroup' => 'custom module', 'context' => 'custom context'))?
    – deinqwertz
    Jul 28, 2013 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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