Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qlaffont/rosetty
Complete Intl/I18n solution for browser and node
https://github.com/qlaffont/rosetty
datefns formatjs i18n intl rosetta typescript
Last synced: about 1 month ago
JSON representation
Complete Intl/I18n solution for browser and node
- Host: GitHub
- URL: https://github.com/qlaffont/rosetty
- Owner: qlaffont
- License: mit
- Created: 2022-04-19T07:08:40.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-11-13T16:35:14.000Z (about 1 month ago)
- Last Synced: 2024-11-13T17:32:14.881Z (about 1 month ago)
- Topics: datefns, formatjs, i18n, intl, rosetta, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/rosetty
- Size: 1.27 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Maintainability](https://api.codeclimate.com/v1/badges/1ff0c28615640d86e758/maintainability)](https://codeclimate.com/github/qlaffont/rosetty/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/1ff0c28615640d86e758/test_coverage)](https://codeclimate.com/github/qlaffont/rosetty/test_coverage) ![npm](https://img.shields.io/npm/v/rosetty) ![npm](https://img.shields.io/npm/dm/rosetty) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/rosetty) ![NPM](https://img.shields.io/npm/l/rosetty)
# Rosetty
Complete Intl/I18n solution for browser and node. Old Owner: [@flexper](https://github.com/flexper)
- React Implementation : [Rosetty React](https://github.com/qlaffont/rosetty-react)
## Usage
```js
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 | 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, dict?: Record) => string OR undefined | Return translated text . If dict is defined, he will use dict. |
| displayNames | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames) | Consistent translation of language, region and script display names |
| listFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat) | Language-sensitive list formatting |
| numberFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat) | Language-sensitive list formatting |
| pluralRules | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules) | Plural-sensitive formatting and plural-related language rules |
| format | [Documentation](https://date-fns.org/v3.3.0/docs/format) | Return the formatted date string in the given format |
| formatRelative | [Documentation](https://date-fns.org/v3.3.0/docs/formatRelative) | Represent the date in words relative to the given base date. |
| formatDistance | [Documentation](https://date-fns.org/v3.3.0/docs/formatDistance) | Return the distance between the given dates in words. |
| formatDistanceToNow | [Documentation](https://date-fns.org/v3.3.0/docs/formatDistanceToNow) | Return the distance between the given date and now in words. |
| formatDuration | [Documentation](https://date-fns.org/v3.3.0/docs/formatDuration) | Return human-readable duration string i.e. "9 months 2 days" | |### WARNING FOR LOCALE !
**You need to import locale from `date-fns` package.**
```js
const { enGB } = require('date-fns/locale');
```## Maintain
This package use [TSdx](https://github.com/jaredpalmer/tsdx). Please check documentation to update this package.