Giter VIP home page Giter VIP logo

rosetty's Introduction

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('date-fns/locale');

const r = rosetty(
  {
    en: {
      dict: {
        test: 'This is a test',
      },
      locale: enGB,
    },
  },
  '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>, 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 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 https://date-fns.org/v3.3.0/docs/format
formatRelative Documentation Represent the date in words relative to the given base date. https://date-fns.org/v3.3.0/docs/formatRelative
formatDistance Documentation Return the distance between the given dates in words. https://date-fns.org/v3.3.0/docs/formatDistance
formatDistanceToNow Documentation Return the distance between the given date and now in words. https://date-fns.org/v3.3.0/docs/formatDistanceToNow
formatDuration Documentation Return human-readable duration string i.e. "9 months 2 days" https://date-fns.org/v3.3.0/docs/formatDuration

WARNING FOR LOCALE !

You need to import locale from date-fns package.

const { enGB } = require('date-fns/locale');

Maintain

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

rosetty's People

Contributors

qlaffont avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

rosetty's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/main.yml
  • actions/checkout v4
  • actions/setup-node v4
  • pnpm/action-setup v3.0.0
  • actions/checkout v4
  • actions/setup-node v4
  • pnpm/action-setup v3.0.0
  • paambaati/codeclimate-action v5.0.0
.github/workflows/publish.yml
  • dorny/paths-filter v3
  • actions/checkout v4
  • actions/setup-node v4
  • pnpm/action-setup v3.0.0
  • qzb/standard-version-action v1.0.13
  • JS-DevTools/npm-publish v3
npm
package.json
  • date-fns ^3.3.0
  • rosetta ^1.1.0
  • @jest/globals 29.7.0
  • @size-limit/preset-small-lib 11.0.2
  • @types/jest 29.5.12
  • @typescript-eslint/eslint-plugin 7.1.1
  • @typescript-eslint/parser 7.1.1
  • eslint 8.57.0
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • eslint-plugin-prettier 5.1.3
  • eslint-plugin-simple-import-sort 12.0.0
  • husky 9.0.11
  • jest ^29.5.0
  • jest-environment-jsdom ^29.5.0
  • prettier 3.2.5
  • size-limit 11.0.2
  • ts-jest ^29.1.0
  • tsdx 0.14.1
  • tslib 2.6.2
  • tsup ^8.0.1
  • tsup-preset-solid ^2.2.0
  • typescript 5.3.3
  • node >=10
  • typescript 5.3.3
nvm
.nvmrc
  • node 20.11.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.