Sometimes it would be really handy to have the Rails localization files available in JavaScript. Same is true for for the routes helpers.
I found these two plugins which are exactly doing this:
My questions:
Thanks for any input!
I use the first plugin you listed (i18n-js) and recommend it highly. It does exactly what you are asking -- make localizations available to javascript -- with very little fuss.
At its core it does two things:
You include a <script>
tag for messages.js and then in your other .js files you can just write I18n.t('some.i18n.path', {interpolation_key: "value", ...})
, which will return the translated string.
It also provides some formatting helpers, like for adding commas to numerals. And the author is very responsive to questions and bug reports.
I'm not sure what you are getting at with meta tags or data- attributes. I haven't needed those for internationalization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With