y18n
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The y18n
JavaScript library, which is frequently utilized by the yargs
package, provides a bare-bones solution for internationalization of your projects. This lightweight library allows you to maintain localization support within your application by offering both singular and plural string translation functionalities along with JSON language file handling. Drawing inspiration from the i18n package, y18n
assists in creating an application with a global reach by taking care of language-specific translations.
To successfully adopt y18n in your coding projects, you need to import it and initialize an instance. Here are a few snippets demonstrating its usage:
const __ = require('y18n')().__;
console.log(__('my awesome string %s', 'foo'));
The output for this will be: my awesome string foo
const __ = require('y18n')().__;
const str = 'foo';
console.log(__`my awesome string ${str}`);
The output for this will be: my awesome string foo
const __n = require('y18n')().__n;
console.log(__n('one fish %s', '%d fishes %s', 2, 'foo'));
The output for this will be: 2 fishes foo
JSON language files should be placed in a directory, typically ./locales
. The file name signifies the locale, such as en.json
, pirate.json
and so on.
The documentation for y18n
can be found within its npm package description here, and more comprehensive details are available on its GitHub repository at git+https://github.com/yargs/y18n.git. The README on the GitHub page mirrors the npm package documentation, and it provides a detailed view of creating an instance of y18n
with necessary configurations, an understanding of its methods including translation, pluralization, locale management, and the use of JSON language files.