Skip to content

Repository files navigation

MaintainabilityTest CoveragenpmnpmSnyk Vulnerabilities for npm packageNPM

Rosetty

Complete Intl/I18n solution for browser and node. Old Owner: @flexper

Usage

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 test

API

rosetty(config, defaultLang?)

Options

Field NameTypeDescription
configRecord<string, Language>Specify dictionary and locale to use for each lang
defaultLangstring?Specify default language to use (should be the same as config)
translateFallbackboolean?Return fallback if translation is not defined

Return

Field NameTypeDescription
changeLang(newLang: string) => voidChange current lang
languagesstring[]List of languages who can be selected
getCurrentLang() => stringReturn current lang
t(key: string, params?: Record<string, any>, dict?: Record<string, any>) => string OR undefinedReturn translated text https://github.com/lukeed/rosetta#rosettatkey-params-lang. If dict is defined, he will use dict.
displayNamesDocumentationConsistent translation of language, region and script display names
listFormatDocumentationLanguage-sensitive list formatting
numberFormatDocumentationLanguage-sensitive number formatting
pluralRulesDocumentationPlural-sensitive formatting and plural-related language rules
dateTimeFormatDocumentationLanguage-sensitive date and time formatting
relativeTimeFormatDocumentationLanguage-sensitive relative time formatting
collatorDocumentationLanguage-sensitive string comparison
segmenterDocumentationLanguage-sensitive text segmentation
durationFormatDocumentationLanguage-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 localeconstconfig={en: {dict: {},locale: 'en-GB'}};// Using Intl.Localeconstconfig={en: {dict: {},locale: newIntl.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 :

Maintain

This package use TSdx. Please check documentation to update this package.

About

Complete Intl/I18n solution for browser and node

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Used by

Contributors

Languages