I'm trying to make a translation in JavaScript on a Drupal site. I'm using the js function Drupal.t()
. Everything seems to work; Drupal is loaded, the function gets called, placeholders get replaced, but the translation doesn't happen. The words stay in English, and the words aren't added to the translations database. Does anybody know why this happens and how to get solve it?
I know your post is rather old, but my answer might help others.
I've noticed that Drupal.locale.strings
doesn't get populated with the JavaScript calls.
So what I usually do is simply create a portion of PHP code that does this work on the server side. You can do it anywhere in your PHP code. But the best is to do it in the module you are coding. It will then be easier to export it with the Potx module so that you can have your strings in some *.po
files for a later use of your module.
If you are in a hurry, you can simply do it in the body of a dummy node (just do a "preview") with the PHP input format:
<?php
print t('Example : %variable', array('%variable' => 'test'));
?>
Once this has been done, you should be able to find your strings and translate them in the admin page.
To regenerate the JavaScript file, you'll have to clear all your cache (with Devel or by visiting the modules page).