i18n-node v0.10.0 Release Notes
Release Date: 2020-05-24 // almost 4 years ago-
๐ Thanks to @einfallstoll i18n got much more developer friendly by adding two extra configuration options for working with translation files catalogs.
โ Added
- โ Adds support for priming i18n with static catalogs (PR #432)
- โ Adds support for custom callback/hook on missing translations thru
missingKeyFn
option โ #433 )
Examples
staticCatalog
๐ Instead of letting i18n load translations from a given directory you may now pass your js object right on configuration, ie:
// DEMO: quick add yaml support on your ownconst yaml = require('js-yaml');const fs= require('fs');// configure and load translations from different locationsi18n.configure({staticCatalog: {de: require('../../locales/de.json'),en: require('../../locales/wired-en-filename.js'),fr: yaml.safeLoad(fs.readFileSync('../../locales/yaml/fr/server.yml', 'utf8'));},defaultLocale: 'de'})
๐ This opens up for a ton of possible ways to handle translations in your very own desired way. But be warned: "Great power comes with great responsibility".
missingKeyFn
๐ Want to get a warning on missing translations? Add missing translations with an indicator? Or even want to try an external service (like deepl.com) to provide an automated translated proposal of a missing phrase?
i18n.configure({missingKeyFn(locale, value) {console.warn(`missing translation of "${value}" in [${locale}]!`)return `${value}-[${locale}]`;},defaultLocale: 'de'})