i21n
Tiny string internationalization and interpolation library.
Features:
- Named-variable interpolation
- Flexible configuration format
- Set default and fallback locale
- Load additional locale data at any time
- Works in Node.js and browser
- Small, no external dependencies
Install
npm install i21n
Usage
const i21n = const i21n = /* Basic */ 'hello.world': 'Hello world' /* With variables */ 'hello.fullname': 'Hello {name}, your full name is {name} {surname}' /* Nested */ 'hello.world.and': 'goodbye': 'name': 'Hello world, goodbye {name}' // "Hello world"i21n // "Hello Ram, your full name is Ram Bo"i21n // "Hello world, goodbye Ram"i21n
Different language translation versions (i.e. locales):
const i21n = 'good': 'day': 'en-gb': 'Good day {name}' 'de': 'Guten tag {name}' 'my': 'name.is': 'en-gb': 'My name is {name}' 'zh-TW': '我叫{name}' /** Locale to use when not explicitly specified or when specified locale version not found */ defaultLocale: 'en-gb' // Default locale// "Good day Ram"i21n // Override with a specific locale// "Guten tag Ram"i21n // Override with a specific locale for which there is no string - it uses the default locale instead!// "My name is Ram"i21n // Load additional locale datai21n// "你好Ram"i21n
License
MIT - see LICENSE.md