Reputation: 5476
My project should support different languages for the GUI (spanish, english, german, etc). I'm using CodeIgniter, so I haven't got any problem with PHP views using Language Class. I can load some previously defined vars on PHP to create views in different languages.
The problem comes here:
Some features (a lot of them actually) use Javascript: personalized context menu for some items, differents DIVs created dynamically, etc. The most of this features are created dynamically, so I can't know the language selected (I can create a lot of duplicated code, one for each language, but this is too redundant).
I need to find a way to translate this content into the new language previously selected by user.
For example:
The user right-click and the context menu have the following options (created dynamically using Javascript):
When the user change the page language to 'Spanish', the context menu should show:
Is there any way to save some variables with all the names in different languages, and then load to create the menus?
Sorry for the big post. I hope everyone can help me or bring me a little tip.
Upvotes: 1
Views: 6371
Reputation: 532
there are several systems to use when you want i18n (short for "internationalization") to work in a server side language as well as in client side Javascript.
this is an example I found for PHP and JavaScript: http://doc.silverstripe.org/sapphire/en/topics/i18n
I've done this in PHP, Ruby and Python. In general there is one way this is done. You create a library of text. this library has pointers to specific pieces of that text. In your code you use that pointer to refer to that piece of text. What the example above does provide you a way to create a library in PHP that can be compiled to a JavaScript equivalent that you can call in JavaScript. Basically it completely separates copywriting and other text from the code.
I hope this helps you on your way.
Upvotes: 1
Reputation: 8306
Is there any way to save some variables with all the names in different languages, and then load to create the menus?
I assume you're asking if you can save these user preferences?
If so store it as a cookie on the user's computer
If you don't mean this, and you want to store all of the variations of languages, then you could store it in an array which can be loaded by javascript
Upvotes: 0