Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the recommended way to enable multiple language support for Javascript displayed text

A number of times I have needed to support multiple languages when building web sites but have yet to come up with a good way of passing the language strings from the server to the client so that they can be used in Javascript for dialogs, messages, etc.

What are your recommendations or experience with this?

EDIT: I'm leaning towards generating the javascript language files on the fly and would appreciate it if anyone knows any third party libraries that can do this.

like image 931
eaglestorm Avatar asked Oct 14 '22 17:10

eaglestorm


1 Answers

I usually move all string specification to separate files and then include the appropriate one on the page, something like this:

In st/js/messages-ru.js:

hello = "Привет"
bye = "Пока"

In st/js/messages-en.js:

hello = "Hello!"
bye = "Good bye!"

When the page is generated, you can determine the language and insert the appropriate js file on the page.

like image 100
Maxim Sloyko Avatar answered Oct 18 '22 01:10

Maxim Sloyko