Complete Intl/I18n solution for browser and node. Old Owner: @flexper
- React Implementation : Rosetty React
const{ rosetty }=require('rosetty');constr=rosetty({en: {dict: {test: 'This is a test',},locale: 'en-GB',},},'en');console.log(r.t('test'));// This is a testOptions
| 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) |
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 localeconstconfig={en: {dict: {},locale: 'en-GB'}};// Using Intl.Localeconstconfig={en: {dict: {},locale: newIntl.Locale('en-GB')}};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).
This package use TSdx. Please check documentation to update this package.