A
A
Azat S.2015-12-24 02:56:24
JavaScript
Azat S., 2015-12-24 02:56:24

Best way to implement multilingualism in Node.js?

Hello!
Can you please tell me the best way to implement multilingualism in a Node.js application?
Let's say if we have something like this index.js file:

if (language == 'english') {
    console.log(phrases.Hello);
  }
  else if (language = 'russian') {
    var phrases = require('./ru');
    console.log(phrases.Hello);
  }

Accordingly, I also created a ru.json file for it , which contains:
{
  "Hello": "Привет"
}

And everything seems to work when choosing the Russian language, but in this case, how can it be done, for example, so that some language is the default and there is no need to create an en.json file? And with long phrases it is not entirely clear how best to proceed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
HoHsi, 2015-12-24
@azat-io

i18n

A
Arman, 2015-12-24
@Arik

Basically, all such text is sent to one common function, it knows the current language, it has a storage (key-value) and it will already return the text in the desired language, if it does not find it, it will return what was sent before

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question