the bare-bones internationalization library used by yargs
npm install y18n[![NPM version][npm-image]][npm-url]
[![js-standard-style][standard-image]][standard-url]

The bare-bones internationalization library used by yargs.
Inspired by i18n.
_simple string translation:_
``js
const __ = require('y18n')().__;
console.log(__('my awesome string %s', 'foo'));
`
output:
my awesome string foo
_using tagged template literals_
`js
const __ = require('y18n')().__;
const str = 'foo';
console.log(__my awesome string ${str});`
output:
my awesome string foo
_pluralization support:_
`js
const __n = require('y18n')().__n;
console.log(__n('one fish %s', '%d fishes %s', 2, 'foo'));
`
output:
2 fishes foo
As of v5 y18n supports Deno:
`typescript
import y18n from "https://deno.land/x/y18n/deno.ts";
const __ = y18n({
locale: 'pirate',
directory: './test/locales'
}).__
console.info(__Hi, ${'Ben'} ${'Coe'}!)`
You will need to run with --allow-read to load alternative locales.
The JSON language files should be stored in a ./locales folder.en.json
File names correspond to locales, e.g., , pirate.json.
When strings are observed for the first time they will be
added to the JSON file corresponding to the current locale.
Create an instance of y18n with the config provided, options include:
* directory: the locale directory, default ./locales.updateFiles
* : should newly observed strings be updated in file, default true.locale
* : what locale should be used.fallbackToLanguage
* : should fallback to a language-only file (e.g. en.json)en_US.json
be allowed if a file matching the locale does not exist (e.g. ),true
default .
Print a localized string, %s will be replaced with args.
This function can also be used as a tag for a template literal. You can use it
like this: __`hello ${'world'}`. This will be equivalent to
__('hello %s', 'world').
Print a localized string with appropriate pluralization. If %d is providedcount
in the string, the will replace this placeholder.
Set the current locale being used.
What locale is currently being used?
Update the current locale with the key value pairs in obj`.
Libraries in this ecosystem make a best effort to track
Node.js' release schedule. Here's a
post on why we think this is important.
ISC
[npm-url]: https://npmjs.org/package/y18n
[npm-image]: https://img.shields.io/npm/v/y18n.svg
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
[standard-url]: https://github.com/feross/standard