Skip to content

Commit 942782d

Browse files
authored
Merge pull request #397 from qlaffont/v4
2 parents 898eabd + 7d149e1 commit 942782d

File tree

12 files changed

+3220
-3666
lines changed

12 files changed

+3220
-3666
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ${{ matrix.os }}
88
strategy:
99
matrix:
10-
node: ["20.x"]
10+
node: ["22.x"]
1111
os: [ubuntu-latest]
1212

1313
steps:
@@ -40,7 +40,7 @@ jobs:
4040
- uses: actions/checkout@v4
4141
- uses: actions/setup-node@v4
4242
with:
43-
node-version: "20"
43+
node-version: "22"
4444
- uses: pnpm/action-setup@v4.1.0
4545
- name: Install deps and build (with cache)
4646
run: pnpm install --no-frozen-lockfile

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ${{ matrix.os }}
1414
strategy:
1515
matrix:
16-
node: ["20.x"]
16+
node: ["22.x"]
1717
os: [ubuntu-latest]
1818

1919
steps:

README.md

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ Complete Intl/I18n solution for browser and node. Old Owner: [@flexper](https://
1010

1111
```js
1212
const { rosetty } = require('rosetty');
13-
const { enGB } = require('date-fns/locale');
1413

1514
const r = rosetty(
1615
{
1716
en: {
1817
dict: {
1918
test: 'This is a test',
2019
},
21-
locale: enGB,
20+
locale: 'en-GB',
2221
},
2322
},
2423
'en'
@@ -35,36 +34,60 @@ console.log(r.t('test')); // This is a test
3534

3635
| Field Name | Type | Description |
3736
| ----------------- | ------------------------ | -------------------------------------------------------------- |
38-
| config | Record<string, Language> | Specify dictionnary and locale to use for each lang |
37+
| config | Record<string, Language> | Specify dictionary and locale to use for each lang |
3938
| defaultLang | string? | Specify default language to use (should be the same as config) |
4039
| translateFallback | boolean? | Return fallback if translation is not defined |
4140

4241
**Return**
4342

44-
| Field Name | Type | Description |
45-
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
46-
| changeLang | (newLang: string) => void | Change current lang |
47-
| languages | string[] | List of languages who can be selected |
48-
| getCurrentLang | () => string | Return current lang |
49-
| 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. |
50-
| 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 <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames> |
51-
| listFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat) | Language-sensitive list formatting <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat> |
52-
| numberFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat) | Language-sensitive list formatting <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat> |
53-
| 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 <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules> |
54-
| format | [Documentation](https://date-fns.org/v3.3.0/docs/format) | Return the formatted date string in the given format <https://date-fns.org/v3.3.0/docs/format> |
55-
| formatRelative | [Documentation](https://date-fns.org/v3.3.0/docs/formatRelative) | Represent the date in words relative to the given base date. <https://date-fns.org/v3.3.0/docs/formatRelative> |
56-
| formatDistance | [Documentation](https://date-fns.org/v3.3.0/docs/formatDistance) | Return the distance between the given dates in words. <https://date-fns.org/v3.3.0/docs/formatDistance> |
57-
| formatDistanceToNow | [Documentation](https://date-fns.org/v3.3.0/docs/formatDistanceToNow) | Return the distance between the given date and now in words. <https://date-fns.org/v3.3.0/docs/formatDistanceToNow> |
58-
| formatDuration | [Documentation](https://date-fns.org/v3.3.0/docs/formatDuration) | Return human-readable duration string i.e. "9 months 2 days" <https://date-fns.org/v3.3.0/docs/formatDuration> | |
59-
60-
### WARNING FOR LOCALE !
61-
62-
**You need to import locale from `date-fns` package.**
43+
| Field Name | Type | Description |
44+
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
45+
| changeLang | (newLang: string) => void | Change current lang |
46+
| languages | string[] | List of languages who can be selected |
47+
| getCurrentLang | () => string | Return current lang |
48+
| 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. |
49+
| 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 |
50+
| listFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat) | Language-sensitive list formatting |
51+
| numberFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat) | Language-sensitive number formatting |
52+
| 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 |
53+
| dateTimeFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) | Language-sensitive date and time formatting |
54+
| relativeTimeFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat) | Language-sensitive relative time formatting |
55+
| collator | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator) | Language-sensitive string comparison |
56+
| segmenter | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter) | Language-sensitive text segmentation |
57+
| durationFormat | [Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat) | Language-sensitive duration formatting (Experimental) |
58+
59+
### Locale Configuration
60+
61+
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.
6362

6463
```js
65-
const { enGB } = require('date-fns/locale');
64+
// Using string locale
65+
const config = {
66+
en: {
67+
dict: {},
68+
locale: 'en-GB'
69+
}
70+
};
71+
72+
// Using Intl.Locale
73+
const config = {
74+
en: {
75+
dict: {},
76+
locale: new Intl.Locale('en-GB')
77+
}
78+
};
6679
```
6780

81+
### Polyfill Support (Node.JS OR Browser)
82+
83+
To use this library, you maybe need to add polyfills as some features are still experimental.
84+
85+
To fix this :
86+
87+
- Install [missing polyfills](https://formatjs.github.io/docs/polyfills)
88+
- Use [polyfill-fastly.io](https://polyfill-fastly.io/) to get the polyfills
89+
- Use your bundler to import the polyfills (webpack, [vite](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy), etc).
90+
6891
## Maintain
6992

7093
This package use [TSdx](https://github.com/jaredpalmer/tsdx). Please check documentation to update this package.

eslint.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import eslint from '@eslint/js';
2+
import tseslint from '@typescript-eslint/eslint-plugin';
3+
import tsParser from '@typescript-eslint/parser';
4+
import prettier from 'eslint-plugin-prettier';
5+
import simpleImportSort from 'eslint-plugin-simple-import-sort';
6+
7+
export default [
8+
{
9+
ignores: ['dist/**', 'coverage/**', 'node_modules/**']
10+
},
11+
eslint.configs.recommended,
12+
{
13+
files: ['**/*.ts', '**/*.tsx'],
14+
languageOptions: {
15+
parser: tsParser,
16+
parserOptions: {
17+
ecmaVersion: 2020,
18+
sourceType: 'module'
19+
},
20+
globals: {
21+
console: 'readonly'
22+
}
23+
},
24+
plugins: {
25+
'@typescript-eslint': tseslint,
26+
'simple-import-sort': simpleImportSort,
27+
'prettier': prettier
28+
},
29+
rules: {
30+
'prettier/prettier': 'error',
31+
'no-unused-vars': 'off',
32+
'@typescript-eslint/no-unused-vars': ['error', {
33+
'argsIgnorePattern': '^_',
34+
'varsIgnorePattern': '^_',
35+
'ignoreRestSiblings': true,
36+
'args': 'none'
37+
}],
38+
'simple-import-sort/imports': 'error',
39+
'simple-import-sort/exports': 'error',
40+
'@typescript-eslint/no-var-requires': 'off'
41+
}
42+
}
43+
];

example/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
const { rosetty, locales } = require('rosetty');
22

3-
const { enGB: enLocale } = locales;
43

54
const r = rosetty(
65
{
76
en: {
87
dict: {
98
test: 'This is a test',
109
},
11-
locale: enLocale,
10+
locale: 'en-GB',
1211
},
1312
},
1413
'en'

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "3.1.32",
2+
"version": "4.0.0",
33
"license": "MIT",
44
"main": "./dist/index.cjs",
55
"typings": "dist/index.d.ts",
@@ -49,28 +49,30 @@
4949
"typescript": "5.5.3"
5050
},
5151
"devDependencies": {
52+
"@eslint/js": "^9.24.0",
53+
"@formatjs/intl-durationformat": "^0.7.4",
5254
"@jest/globals": "29.7.0",
5355
"@types/jest": "29.5.14",
54-
"@typescript-eslint/eslint-plugin": "7.16.0",
55-
"@typescript-eslint/parser": "7.16.0",
56-
"eslint": "8.57.0",
57-
"eslint-config-prettier": "9.1.0",
56+
"@typescript-eslint/eslint-plugin": "8.30.1",
57+
"@typescript-eslint/parser": "8.30.1",
58+
"eslint": "9.24.0",
59+
"eslint-config-prettier": "10.1.2",
5860
"eslint-plugin-import": "2.29.1",
5961
"eslint-plugin-prettier": "5.1.3",
6062
"eslint-plugin-simple-import-sort": "12.1.1",
6163
"husky": "9.0.11",
62-
"jest": "^29.5.0",
63-
"jest-environment-jsdom": "^29.5.0",
64+
"jest": "^29.7.0",
65+
"jest-environment-jsdom": "^29.7.0",
6466
"prettier": "3.3.3",
65-
"ts-jest": "^29.1.0",
67+
"ts-jest": "^29.3.2",
6668
"tsdx": "0.14.1",
6769
"tslib": "2.6.3",
68-
"tsup": "^8.0.1",
70+
"tsup": "^8.4.0",
6971
"tsup-preset-solid": "^2.2.0",
7072
"typescript": "5.5.3"
7173
},
7274
"dependencies": {
73-
"date-fns": "^4.0.0",
75+
"date-fns": "^4.1.0",
7476
"rosetta": "^1.1.0"
7577
},
7678
"types": "./dist/index.d.ts",

0 commit comments

Comments
 (0)