Question

I am checking this example.

Actually, it changes the text when user clicks the button (in other language ).

But what if user has 3 different languages? (some type of menu option) and on change the option it changes the text.

I have name(in english) but I want to change it to spanish and german also on click. How can I do it?

In example there is a toggle for languages when user clicks the button. If he wants to switch between three or four language - how do implement such a feature? Thanks

Was it helpful?

Solution

Yes, you can do it. There is jsFiddle.

Firstly, create new button with different id in your HTML.

  1. <input type='button' id='translate_button2' value='Internationalize to Russian!'>
  2. Then, you have to make some changes in provided javascript. Create new Object with strings translated to third language. Name it i18n_dict2, for example. Simply copy everything from i18n_dict and just translate needed strings.
  3. And the last you should do is to define event handler to second button(code that will run after click to button). Copy everything inside $('input#translate_button').click(function (event) { and paste after it. But don't forget to change input#translate_button to input#translate_button2(it's id of your newly created button).
  4. And one more. You have to make your new object avaiable inside second event handler. Just insert $.i18n.setDictionary(i18n_dict2); inside $('input#translate_button').click(function (event) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top