@proulr/rosetta 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -2
- package/src/resolve-locale.test.ts +44 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proulr/rosetta",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
"validate:locales": "node ./scripts/validate-locales.mjs",
|
|
26
26
|
"validate:locales:strict": "node ./scripts/validate-locales.mjs --strict",
|
|
27
27
|
"typecheck": "npm run locale:generate && npm run validate:locales && tsc --noEmit",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest",
|
|
28
30
|
"prepublishOnly": "npm run typecheck",
|
|
29
31
|
"lint": "eslint .",
|
|
30
32
|
"lint:fix": "eslint . --fix",
|
|
@@ -41,7 +43,8 @@
|
|
|
41
43
|
"husky": "^9.1.7",
|
|
42
44
|
"lint-staged": "^16.4.0",
|
|
43
45
|
"typescript": "~6.0.3",
|
|
44
|
-
"typescript-eslint": "^8.61.1"
|
|
46
|
+
"typescript-eslint": "^8.61.1",
|
|
47
|
+
"vitest": "^3.2.7"
|
|
45
48
|
},
|
|
46
49
|
"engines": {
|
|
47
50
|
"node": ">=22"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_PROULR_LOCALE,
|
|
4
|
+
resolveLocaleFromPref,
|
|
5
|
+
resolveLocaleFromQuery,
|
|
6
|
+
resolveLocaleFromSystemTag,
|
|
7
|
+
t,
|
|
8
|
+
tFormat,
|
|
9
|
+
} from './index';
|
|
10
|
+
|
|
11
|
+
describe('resolveLocaleFromQuery', () => {
|
|
12
|
+
it('defaults when query is empty', () => {
|
|
13
|
+
expect(resolveLocaleFromQuery(null)).toBe(DEFAULT_PROULR_LOCALE);
|
|
14
|
+
expect(resolveLocaleFromQuery({})).toBe(DEFAULT_PROULR_LOCALE);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('prefers locale over app_locale', () => {
|
|
18
|
+
expect(resolveLocaleFromQuery({ locale: 'en', app_locale: 'pt-BR' })).toBe('en');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('resolveLocaleFromPref / system tag', () => {
|
|
23
|
+
it('uses system locale when pref is system', () => {
|
|
24
|
+
expect(resolveLocaleFromPref('system', 'en')).toBe('en');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('maps language tags to supported locales', () => {
|
|
28
|
+
expect(resolveLocaleFromSystemTag('pt-BR')).toBe('pt-BR');
|
|
29
|
+
expect(resolveLocaleFromSystemTag('en-US')).toBe('en');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('t / tFormat', () => {
|
|
34
|
+
it('returns a non-empty string for a known key', () => {
|
|
35
|
+
const value = t('alerts.attention', 'pt-BR');
|
|
36
|
+
expect(value).toBe('Atenção');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('interpolates placeholders when present', () => {
|
|
40
|
+
expect(tFormat('alerts.soonFeature', 'pt-BR', { feature: 'Chat' })).toBe(
|
|
41
|
+
'Chat ainda não está disponível.',
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
});
|