What is i18n-node-2 and how does it work for localization and internationalization?
File Extensions | .js |
API Extension | node_json |
Import | Yes |
Export | Yes |
Pluralization supported? | Yes |
Descriptions supported? | No |
I18n-node-2 is a library based on Node.js that can work out of the box with Express.js. I18n-node-2 integrates seamlessly with your application by providing an on-the-fly way of string extraction. In other words, using i18n-node-2, all you need to do is to wrap strings pending translation with the default _(“…”) method. While running, i18n-node-2 will automatically generate multiple JSON files depending on your predefined locales.
I18n-node-2 uses the auto-generated JSON format to store translatable data. Therefore, prior to translation, it is best to have a sanity check of the files. Since i18n-node-2 supports pluralization, you also need to make sure that all variables remain unchanged during translation.
Code Sample
{
"boolean_key": "--- true\n",
"empty_string_translation": "",
"key_with_description": "Check it out! This key has a description! (At least in some formats)",
"key_with_line-break": "This translations contains\na line-break.",
"nested.deeply.key": "I'm a deeply nested key.",
"nested.key": "This key is nested inside a namespace.",
"null_translation": null,
"pluralized_key": {
"one": "Only one pluralization found.",
"other": "Wow, you have %s pluralizations!",
"zero": "You have no pluralization."
},
"sample_collection": [
"first item",
"second item",
"third item"
],
"simple_key": "simple key, simple message, so simple.",
"unverified_key": "This translation is not yet verified and waits for it. (In some formats we also export this status)"
}
More Information
i18n-node-2 library is one of the most popular libraries to localize node applications.