-1

I'm working on JavaScript based web app. I want JSON based multiple language integration. Which one is best library (without jQuery) to provide multi language support?

user2782972
  • 17
  • 1
  • 5
  • I think this link can help you http://stackoverflow.com/questions/228835/best-practice-javascript-and-multilanguage – nhannv Jan 05 '16 at 07:39

2 Answers2

1

Actually working with angularjs and angular-translate has covered all my needs on that field. You can get the translations from a js or a JSON as you please. It sometimes has problems with scopes and cached translations but everything is easily solvable. Have a look at it: http://angular-translate.github.io/

1

You can do it without any library, but just using js objects:

var hi = {"english": "hi",
          "italian": "ciao",
          "spanish": "hola"};
var LANGUAGE = "spanish"; // choose language with your code
alert(hi[LANGUAGE]);

Returns

hola

Moreover, you could use different files for each language:

// spanish.js
texts = {"hi": "hola",
         "howareyou": "¿Que tal?"};

// italian.js
texts = {"hi": "ciao",
         "howareyou": "Come stai?"};

// main html file (for example):
<script src="italian.js"></script> <!-- choose language file with your code -->
<script>    
     alert(texts["howareyou"]);
</script>

Returns

Come stai?

However, there are many ways to do this, as explained in this answer.

P.S. Sorry for any language mistake :)

Community
  • 1
  • 1
moonknight
  • 334
  • 1
  • 7