I have no idea how to handle localization with JQuery. I want to set an innerHTML with German text, but if the browser is configured to use English, then I want to set English text.
In PHP I use gettext for such stuff, but how to do it in JavaScript/jQuery?
There is no easy solution for that. What I would probably do is create several scripts with language texts for every language and include proper one in PHP. So if someone is using english version of your site you would include only english file, if someone is using german version you would include german language file etc.
Example:
You can define all language files like that:
Make sure you are including only one of those in your HTML and make sure to include language file first i.e.
Then you can use those localized texts in your main script for example:
What’s best about it is that your logic (
myscript.jsin this example) doesn’t have to worry about localization and you won’t have to change it if you want to add a new language file.