I am using gettext in my PHP code, but I have a big problem. All my JavaScript files are not affected by the translation, can somebody tell me an easy way to get the translations in the chosen language into JavaScript as well.
I am using gettext in my PHP code, but I have a big problem.
Share
The easiest way is having a PHP file write the translations from
gettextinto JavaScript variables.js_lang.php:
and then include it:
I would also recommend this method in conjunction with the translation plugins S.Mark mentions (which are very interesting!).
You can define the dictionary in the current page’s header, too, without including an external file, but that way, you would have to look up and send the data on every page load – quite unnecessary, as a dictionary tends to change very rarely.