rosetty
v4.0.10
Published
[](https://codeclimate.com/github/qlaffont/rosetty/maintainability) [](
Downloads
73
Readme
Rosetty
Complete Intl/I18n solution for browser and node. Old Owner: @flexper
- React Implementation : Rosetty React
Usage
const { rosetty } = require('rosetty');
const r = rosetty(
{
en: {
dict: {
test: 'This is a test',
},
locale: 'en-GB',
},
},
'en'
);
console.log(r.t('test')); // This is a testAPI
rosetty(config, defaultLang?)
Options
| Field Name | Type | Description | | ----------------- | ------------------------ | -------------------------------------------------------------- | | config | Record<string, Language> | Specify dictionary and locale to use for each lang | | defaultLang | string? | Specify default language to use (should be the same as config) | | translateFallback | boolean? | Return fallback if translation is not defined |
Return
| Field Name | Type | Description | | ------------------ | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | | changeLang | (newLang: string) => void | Change current lang | | languages | string[] | List of languages who can be selected | | getCurrentLang | () => string | Return current lang | | t | (key: string, params?: Record<string, any>, dict?: Record<string, any>) => string OR undefined | Return translated text https://github.com/lukeed/rosetta#rosettatkey-params-lang. If dict is defined, he will use dict. | | displayNames | Documentation | Consistent translation of language, region and script display names | | listFormat | Documentation | Language-sensitive list formatting | | numberFormat | Documentation | Language-sensitive number formatting | | pluralRules | Documentation | Plural-sensitive formatting and plural-related language rules | | dateTimeFormat | Documentation | Language-sensitive date and time formatting | | relativeTimeFormat | Documentation | Language-sensitive relative time formatting | | collator | Documentation | Language-sensitive string comparison | | segmenter | Documentation | Language-sensitive text segmentation | | durationFormat | Documentation | Language-sensitive duration formatting (Experimental) |
Locale Configuration
The locale field in the configuration should be a valid BCP 47 language tag (e.g., 'en-GB', 'fr', 'de-DE') or an Intl.Locale instance.
// Using string locale
const config = {
en: {
dict: {},
locale: 'en-GB'
}
};
// Using Intl.Locale
const config = {
en: {
dict: {},
locale: new Intl.Locale('en-GB')
}
};Polyfill Support (Node.JS OR Browser)
To use this library, you maybe need to add polyfills as some features are still experimental.
To fix this :
- Install missing polyfills
- Use polyfill-fastly.io to get the polyfills
- Use your bundler to import the polyfills (webpack, vite, etc).
Maintain
This package use TSdx. Please check documentation to update this package.
