rosetty
TypeScript icon, indicating that this package has built-in type declarations

4.0.5 • Public • Published

Maintainability Test Coverage npm npm Snyk Vulnerabilities for npm package NPM

Rosetty

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

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 test

API

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 :

Maintain

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

/rosetty/

    Package Sidebar

    Install

    npm i rosetty

    Weekly Downloads

    51

    Version

    4.0.5

    License

    MIT

    Unpacked Size

    24.7 kB

    Total Files

    8

    Last publish

    Collaborators

    • qlaffont