Make use of the translation methods in browser
See original GitHub issueHi!
I’m using i18n-node in my KoaJS server. It works great! But sometimes I need to make some translations browser side (for example, when a toast is generated from a javascript function, and including some data that the user just filled in some field).
As I don’t want to hit the server every time I need a translation, what I managed to do was adding a copy of the translations in local storage, and refreshing it only when it’s necessary (ie., a text in en.js was modified).
To handle the translations in the browser now I’m using Polyglot, that allows me to load an object with the translations and call a simple .t()
method to translate something… But the thing is that I want to use all the good things in i18n-node, like Plurals translations, message format, etc.
Is there a way to make i18n work in browser by loading the translations from a JS object instead of from a file?
Thanks! Luciano
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
In the meantime, a note on how we achieved this is to create an endpoint on the server which will serve up the JSON file of the user’s current locale.
You can then create a fairly simple function for retrieving values from your locale object.
I just stumbled upon this https://github.com/gammasoft/browser-i18n