Is there a way to translate hard coded words in twig when selecting a language from the language dropdown? I have used the |t ({{ myword|t }}) function but it doesn't seem to be work when selecting another language.

Is there a way to do this?

  • 1
    eh? yeah, that's what the whole localization set of modules is for. go to modules section and in the localization enable translations and then you will have translation UI available. – user21641 Aug 2 '18 at 17:37
  • Could you please explain more. I didn’t get what you said – i am batman Aug 2 '18 at 17:51
  • 1
    thanks @IvanJaros. It worked. There is a module named interface translations. It should be enabled. Then the translations can be updated in .PO files – i am batman Aug 3 '18 at 10:12

{{ myword }} is a variable, not a string. You need to use {{ 'myword'|t }} (with quotes)

  • Still no luck :( It doesn’t get translated. It still shows the english word when on translations – i am batman Aug 2 '18 at 17:50
  • Make sure you have: Cleared cache, then loaded page in the default language, once you have done this, you can go to the Trans UI and add a translation for 'myword'. You may need to clear cache as well before it will show up on the new lang node. – CG Monroe Aug 2 '18 at 17:59
  • @iambatman What is the status 'myword' show up in the list of strings for that language? – mpdonadio Aug 2 '18 at 18:26

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.