2

I've a problem about string translations.

I've built a multi-language site and in a custom module, in a JS file, I've used the function t() to make translatable some strings. These strings appear in /admin/config/regional/translate and I'm able to edit their value, but then, after cleared cache when I visit the site I see the strings not translated.

The strangest things is that for other elements the system works. I'm not able to debug this, my apache error and access logs are clear, nothing also in the message log of Drupal.

Anyone can help me? Thank u in advance

1
  • Hey hey, please show us some of your JS code. And your *.libraries.yml. And please verify as suggested below, if using Drupal.t() fixed it for you.
    – leymannx
    Commented May 31, 2018 at 10:07

1 Answer 1

3

Which string you want to translate before that you can use Drupal.t

like

var optionsList = '<option value="" selected>' + Drupal.t('Navigate...') + '</option>';
3
  • Not to forget to add the correct dependencies in *.libraries.yml.
    – leymannx
    Commented May 31, 2018 at 10:07
  • Also don’t forget the context argument.
    – Kevin
    Commented May 31, 2018 at 11:24
  • Complete sample from menu_ui.js: stackoverflow.com/a/49939159/2199525.
    – leymannx
    Commented Dec 15, 2018 at 22:41

Your Answer

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

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