- Issue created by @HasinaNjaratin
I have a custom trad file *.po
- mybestmodule.info.yml
interface translation project: mybestmodule
interface translation server pattern: modules/mybestmodule/translations/mybestmodule.%language.po
- translations/mybestmodule.fr.po
msgid ""
msgstr ""
"Project-Id-Version: mybestmodule(1.0.0)\n"
"POT-Creation-Date: 2024-01-03 09:50+0200\n"
"PO-Revision-Date: 2024-01-03 09:50+0200\n"
"Language-Team: French\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n!=1);\n"
msgid "mybestmodule.greeting"
msgstr "salut"
When I do the translation on the controller side via the
$this->t('mybestmodule.greeting')
or
t('mybestmodule.greeting')
function.
=> it works correctly.
the same, at the branch level, if I do
{{ 'mybestmodule.greeting'|t }}
or
{{ 'mybestmodule.greeting'|trans }}
=> it works very well.
on the other hand, when I use it at the javascript level in library with dependencies : core/drupal, core/drupalSettings, core/once, core/jquery
(function ($, Drupal, once) {
Drupal.behaviors.myBestModule = {
attach: function (context, settings) {
once('myBestModule', 'body', context).forEach(function () {
console.log(Drupal.t('mybestmodule.greeting'));
});
}
};
})(jQuery, Drupal, once);
=> it does not work. it does not translate the word (returns mybestmodule.greeting). and when I check in the global js variable of window.drupalTranslations , it is not there.
I can see the word clearly from the translation BO /admin/config/regional/translate
I did several times drush locale-check && drush locale-update && drush cr
but yet it doesn't work; and that only on the JS part.
Any ideas?
THANKS
Active
10.1 ✨