I need a web-application to be translated from English to Portuguese. Since the servers on which this application runs have no internet access, is there a way to achieve this without using a 3rd Party API. Is there a JS Library that can translate from say Language A to Language B on the client side ?
1 Answers
You can definitely use Java Script for that.
The library well known for translations is the i18next
You can integrate with jQuery, but I strongly recommend you using something like AngularJS or Mustache for customise your template.
If you choose use AngularJS you can have a different JSON file with your expressions, and depending on the language you are navigating, loads a different JSON file, like:
en.json, es.json, pt.json
You can use JS Cookies for saving the language as same you would do with any backend language.
Mustache is used to create templates front-side with double brackets {{custom_text}}. AngularJS uses the same idea.
The only issue if you want to use AJAX. Read more about Google Chrome --allow-file-access-from-files disabled for Chrome Beta 8

- 1
- 1

- 1,667
- 1
- 22
- 35
-
Seems like this can help, but this requires additional configurations as appears from the samples and documentation. Do we have an option like, Everything on page in Language A gets Converted to Language B (So that only input I need to provide is "from" and "to") , Do we have something as simple as that ? – sainiankit May 26 '15 at 07:36
-
@sainiankit are you looking for an automatic service without using internet? I believe it'll be a little hard. To translate with JS, you can use all content of your app as variables. So each language has their group of variables as a JavaScript Object (or json file as I suggested). In this case, would have an English and a Spanish file/object. For each language the user choose, you'll load their language file/object. Does it work for you? Don't need much setting. – Leo Caseiro May 26 '15 at 12:48
-
Check this example using Mustache.js http://code.tutsplus.com/tutorials/using-the-mustache-template-library--net-14590 – Leo Caseiro May 26 '15 at 12:50