- Notifications
You must be signed in to change notification settings - Fork47
📒 the bare-bones i18n library used by yargs
License
yargs/y18n
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The bare-bones internationalization library used by yargs.
Inspired byi18n.
simple string translation:
const__=require('y18n')().__;console.log(__('my awesome string %s','foo'));
output:
my awesome string foo
using tagged template literals
const__=require('y18n')().__;conststr='foo';console.log(__`my awesome string${str}`);
output:
my awesome string foo
pluralization support:
const__n=require('y18n')().__n;console.log(__n('one fish %s','%d fishes %s',2,'foo'));
output:
2 fishes foo
As ofv5
y18n
supportsDeno:
importy18nfrom"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.File names correspond to locales, e.g.,en.json
,pirate.json
.
When strings are observed for the first time they will beadded 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, defaulttrue
.locale
: what locale should be used.fallbackToLanguage
: should fallback to a language-only file (e.g.en.json
)be allowed if a file matching the locale does not exist (e.g.en_US.json
),defaulttrue
.
Print a localized string,%s
will be replaced witharg
s.
This function can also be used as a tag for a template literal. You can use itlike this:__`hello ${'world'}`
. This will be equivalent to__('hello %s', 'world')
.
Print a localized string with appropriate pluralization. If%d
is providedin the string, thecount
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 inobj
.
Libraries in this ecosystem make a best effort to trackNode.js' release schedule. Here'sapost on why we think this is important.
ISC
About
📒 the bare-bones i18n library used by yargs