1

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):

  • Hi
  • Goodbye

When the user change the page language to 'Spanish', the context menu should show:

  • Hola
  • Adios

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Probably this is the solution closer to what I'm looking for. Thanks yopefonic, I'll give it a try to i18n.
0

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

1 Comment

Yeah, that's one of the solution I thinked. Thanks for the tip!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.