question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make use of the translation methods in browser

See original GitHub issue

Hi!

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:open
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
emmerichcommented, Aug 3, 2016

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.

router.get('/i18n.js', (req, res) => {
  var catalog = i18n.getCatalog(req)
  res.send('window.i18nCatalog = ' + JSON.stringify(catalog))
})

You can then create a fairly simple function for retrieving values from your locale object.

1reaction
thenitaicommented, Dec 15, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Translate a Web Page: 3 Best Methods to Use | Phrase
Let's have a look at the 3 main methods to translate a site, ... Most web browsers, including Google Chrome, Microsoft Edge, and...
Read more >
The 7 Best Browser Tools to Translate Web Pages - MakeUseOf
The 7 Best Browser Tools to Translate Web Pages · 1. Google Translate · 2. ImTranslator · 3. DeepL Translator · 4. TranslateMe...
Read more >
How To Translate Your Entire Website - Localize
Firefox users should add a plugin to the browser for translation. Mozilla officially recommends the To Google Translate add-on. Safari When you use...
Read more >
How to Translate a Website in 2022 (9 Easy Ways) - Kinsta
Whether you need to translate a site that you're browsing or make your site accessible to non-English speakers, you can use a few...
Read more >
5 Ways to Translate a Web Page - wikiHow
1. Go to your webpage. In any web browser of your choice, find and open the webpage you want to translate. 2. Copy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found