Node.js i18n: Agile Localization for Developers

10 mins read
Node.js i18n: Agile Localization for Developers

In today’s market, people seek personalization. They expect your app to speak their native language. In this article, we will cover how you can translate your Node.js app using a developer-friendly localization platform. Learn about the i18n framework and how to integrate your repository with a localization system to automate Node.js localization.

Make Your App Multilingual and Grow Your Revenue

Language connects people. The same principle is applied to your app development. Having localized versions of your app can grow and generate great revenue for your app by opening new markets.

The internet is somewhat similar to the real world. When you visit a place where no one speaks your mother language, you feel isolated and lost. Making your app multilingual help your customers use it more effectively and opens up opportunities to reach new audiences.

According to a recent study by Preply, most of the top apps in each tech category are also the most language-inclusive ones.

Node.js Web Application Framework

Node.js is a server-side platform built on Google Chrome’s JavaScript Engine. The official documentation of Node.js states the following – ‘’Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.’’

If you choose Node.js as a development environment and are curious about how you can implement localization as a part of your workflow – you’re in the right place.

Node.js i18n: Localization Starting Point

If you plan to create a multilingual version of your app, you should use one of the Node.js internationalization libraries available, for example on Openbase. This article will cover the i18n-node as an example. You may choose another library according to your preferences. They do implement localization functionality pretty much in the same way.

Here are a few first steps you need to take to begin the localization of your Node.js app with i18n-node library.

The first step would be to install the package

$ npm install i18n

Then, create an i18n config object

Before we use the library, we need to configure it.

$ touch app/i18n.config.js

File: app/i18n.config.js

const { I18n } = require('i18n');
const path = require('path');

const i18n = new I18n({
  locales: ['en', 'uk'],
  defaultLocale: 'en',
  directory: path.join('./', 'locales')
});

module.exports = i18n;

We added support for 2 languages, with the default one being en (English) and the second one being uk (Ukrainian). View the whole list of all configuration options for the library to learn more.

Watch this 4-minute video to learn about Crowdin

Node.js i18n: Create an i18n object

$ touch index.js

File: index.js

const i18n = require('./app/i18n.config');

console.log(i18n.getLocales()); // ['en', 'uk']
console.log(i18n.getLocale()); // 'en'
console.log(i18n.__('Hello')); // 'Hello'
console.log(i18n.__n('You have %s message', 5)); // 'You have 5 messages'

Then in the command line, run the following:

$ node index.js

This will automatically generate a locales’ directory on the root folder. It will contain the relevant translation strings for the current language:

$ tree locales 
locales
├── uk.json
└── en.json

File: locales/en.json

{
   "Hello": "Hello",
   "You have %s message": {
      "one": "You have %s message",
      "other": "You have %s messages"
   }
}

Add the following line in the index.js to test the generation of translatable strings for the other language:

i18n.setLocale('uk')

File: locales/uk.json

{
   "Hello": "Привіт",
   "You have %s message": {
      "one": "Ви маєте %s повідомлення",
      "other": "Ви маєте %s повідомлень"
   }
}

Rerun the app to verify translations

$ node index.js
Привіт
Ви маєте 5 повідомлень

Automate Node.js Localization with Crowdin

Node.js localization library was created to help and save your time as a developer. However, as you can assume from a small example above, doing the actual translations into multiple languages can still be very challenging, especially for complex apps.

You will face several challenges like making sure that:

  • your translators do not edit the same file simultaneously or break the code
  • translation values are present for each language
  • you don’t have to spend time copy-pasting translations

You don’t have to deal with all the extra work. And why would you if there is a solution? Make localization part of your workflow and forget about those issues.

Watch this 4-minute video to learn about Crowdin

Integrate Your Repo and Localization Project

Set up an integration with your repo. Crowdin integrates with GitHub, GitLab, Bitbucket, and Azure Repos. You can also install Crowdin Console Client (CLI) which allows you to integrate with GIT, SVN, Mercurial, and more.

Crowdin will get the localization files from your repo and upload them to the Editor, where all strings from your app will look user-friendly and include the comments you provided. Once the translations are done, the system compiles them into a file and syncs them with your code as a merge request. Translations do not get to the master branch before you merge them. You can also integrate multiple branches with Crowdin at the same time, so translators can work with the texts from your feature branch before it’s rolled out, and you can release them into multiple languages at the same time.

In case you have more than one app or several products that share similar features and texts, you can share their translations and avoid translating the same content twice, saving time and money. Usually, iOS and Android app versions have much of the same content. In Crowdin, you can easily detect duplicate strings to reuse their translations.

Use Machine Translation and Translation Memory Pre-Translation

Both machine translation (MT) and translation memory (TM) will help you translate content faster and reduce translation costs. With their help, you can reduce the duration of the project even before the translators begin their work. To do this, configure pre-translation via TM or MT. You can also leverage MT to get translations of non-critical content. To reduce project length, but maintain the quality, you can still use MT, but add machine translation post-editing as the next step. This way your translation team will review auto-generated translations instead of translating everything from scratch.

On Crowdin, you can localize your product with the help of more than 40 machine engines like Microsoft Translator, Google Translate, DeepL Translator. View the list of machine engines you can use with Crowdin today.

Ensure Context for Translators

Simply put, context ensures the quality of the localized version of your app. Crowdin has created a few ways to help you provide context for translators and reduce manual work.

You can provide context using:

  • WYSIWYG editor view
  • Context for strings. Add text descriptions or labels, use Glossary terms to get relevant translations faster.
  • Screenshots. You can upload your game or app screenshots manually or using different integrations or add-ons, like Crowdin SDK for example. This way, translators know the location and context for each string.
  • In-Context Localization tool. Translators can work as if in the real app interface and preview the translations they make right there. Translations are stored within your Crowdin project, and you can decide when to pull the strings to your application.

You can learn more about the Crowdin platform by watching a short on-demand demo.

Localize Your Product with Crowdin

Automate localization by internationalizing your texts and integrating your repo with Crowdin New source strings are automatically sent to translators, and you receive translations as a merge after the work is done. Let your customers access your product in several languages. Get started and register a Crowdin account.

Make your app multilingual with Crowdin

Reach a wider audience by speaking their language. Start your free 14-day trial of Crowdin.
Diana Voroniak