npm i18n 0.10.0
0.10.0 - Feature Release

latest releases: 0.15.1, 0.15.0, 0.14.2...
3 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 own
const yaml = require('js-yaml');
const fs   = require('fs');

// configure and load translations from different locations
i18n.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'
})

Don't miss a new i18n release

NewReleases is sending notifications on new releases.