0

In the following question on multilingual website design, it is suggested to use a PHP "pre-processor" in order to generate localized PHP files. The generation would only be triggered once, and on each update to underlying content.

https://stackoverflow.com/questions/19249159/best-practice-multi-language-website/19425499#19425499

I am currently adapting a website for localization using this approach, but I'm wondering what suggestions people have for dealing with javascript files within this framework.

Community
  • 1
  • 1

1 Answers1

0

I'm working with ASP.NET, so I'm not the PHP Expert. But as in PHP we have resource files (.resx instead of .po) and what we do is automatically add all entries in a certain .resx file to the page as Javascript variables.
So we have all localized files in one place and format. Works well for us.

I saw similar ideas for PHP:
Translation in JavaScript like gettext in PHP?

Maybe there are complete solutions out there, otherwise you just have to build something that would do this:

var var1 = "<?php echo gettext("Var1 text"); ?>";
Community
  • 1
  • 1
Remy
  • 12,555
  • 14
  • 64
  • 104
  • Thanks Remy, the strategy I'm using right now actually preprocesses and caches localized versions on the file level, rather than calling gettext at the string level. Each php file requires the localizer.php containing the translate() function. Each time another php file is invoked, the call references the return variable (localized file name) from the translate function. The full details are in the SO answer linked in my question. So, what I'm curious about is whether I should treat .js files in the same way as .php, or if best practice would indicate an alternative approach. – James Hodson May 14 '16 at 02:42
  • 1
    Personally, if you use this preprocessing for your PHP file, I would use something similar for your .js files. Lots of Javascript libraries come with a file for each culture. Eg. translations.en-us.js – Remy May 17 '16 at 07:20