However, doing the actual translations into multiple languages will still be very painful, especially for complex apps. Using some kind of an Node.js I18n library will greatly help you as a developer.
Npm install i18next-node-fs-backend -save Translation Management System Npm install i18next-express-middleware -save Let’s start by installing the necessary modules: In this article we are going to use I18next: a full-fledged internationalization framework supporting both vanilla JavaScript applications, client-side frameworks, and Node.js. Some of them automatically translate dates, weekdays, months, and other standard things.Use pluralization formats, where forms of words change depends on object counts.Understands formats of resource files, allow us to use embedded variables and nesting.Providing translation functions or helpers which help us implement translation logic.Translation libraries on some stage of application work replace these labels with text from resource files. Typically we have some labels in our application that define parts where some text should be translated in a specific language. Such libraries are helping us with a few things: Next, we want to have some sort of a Node.js i18n library. P It's a translation article application Installing Node.js I18n Library: I18next You may change something in the views/index.pug file, for example add: Therefore, open your browser and navigate to: Do it with the following command:īy default the web server starts on TCP port 3000. package.json contains meta-information about your application.įirst, you need to install all packages listed in package.json along with their dependencies.app.js is the root file of your application.routes here we map paths of URI to the logic inside your application.public here lives your static files like robots.txt, CSS, or images.node_modules is a legendary black hole with all installed Node.js libraries for your application.The command creates a folder with the following structure: Let’s install express-generator globally and create a new app: So if you are going to create some production application, I encourage you to follow guidelines and practices to use patterns, extract different logic to separate files, use inheritance etc. A small disclaimer: in this article I’m going to cover mostly translation staff. Let’s start with creating a primitive application based on Express.js by using an express-generator to scaffold it. Downloading Translation Files From Lokalise.Configuring I18next Localization Library.Installing Node.js I18n Library: I18next.In this particular article, we are going to cover i18next library which enables Node.js i18n. Therefore, Node.js i18n simply means Node.js internationalization. For this reason, often programming libraries to keep names short use this abbreviation. If you are wondering what i18n is about it’s just an abbreviation of the word “internationalization”. JavaScript also doesn’t stand still, and new, more modern specifications of the scripting language appear. Notable examples are TypeScript and CoffeeScript. As JavaScript has some shortcomings popularized by many online meme pictures, several such languages appear. That’s why many services are now using JavaScript or languages that are transcompiled into JavaScript as a backend language. Traditionally JavaScript was evolving as an in-browser language and Node.js opened a broad range of other valuable applications. Node.js is a popular cross-platform open-source JavaScript runtime environment. That’s why even if you not planning to support a multi-language interface right now, it is a good idea to know how you can quickly create a localization solution with Node.js i18n libraries. Therefore, if you start developing your app with localization in mind, it dramatically reduces potential pain. It turns out that one of the most productive sources of new users is localization of your app. When you have a successful application sooner or later, you need to find new sources of growth.