qlaffont / rosetty

Complete Intl/I18n solution for browser and node

Home Page:https://www.npmjs.com/package/rosetty

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 enGB = require('dayjs/locale/en-gb');

const r = rosetty(
  {
    en: {
      dict: {
        test: 'This is a test',
      },
      locale: enLocale,
    },
  },
  'en'
);

console.log(r.t('test')); // This is a test

API

rosetty(config, defaultLang?)

Options

Field Name Type Description
config Record<string, Language> Specify dictionnary 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>) => string OR undefined Return translated text https://github.com/lukeed/rosetta#rosettatkey-params-lang
displayNames Documentation Consistent translation of language, region and script display names https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames
listFormat Documentation Language-sensitive list formatting https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat
numberFormat Documentation Language-sensitive list formatting https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
pluralRules Documentation Plural-sensitive formatting and plural-related language rules https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules
format Documentation Return the formatted date string in the given format
formatDistance Documentation Return the distance between the given dates in words.
formatDistanceToNow Documentation Return the distance between the given date and now in words.
formatDuration Documentation Return human-readable duration string i.e. "9 months 2 days"

WARNING FOR LOCALE !

You need to import locale from dayjs package.

const enGB = require('dayjs/locale/en-gb');

Maintain

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

About

Complete Intl/I18n solution for browser and node

https://www.npmjs.com/package/rosetty

License:MIT License


Languages

Language:TypeScript 98.2%Language:JavaScript 1.8%