@chipmobilesdk/rn-i18n 0.2.0 → 0.4.0
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/CHANGELOG.md +173 -0
- package/README.md +48 -17
- package/lib/commonjs/config/catalog.js +29 -0
- package/lib/commonjs/config/catalog.js.map +1 -0
- package/lib/commonjs/config/diagnostics.js +56 -0
- package/lib/commonjs/config/diagnostics.js.map +1 -0
- package/lib/commonjs/config/errors.js +35 -0
- package/lib/commonjs/config/errors.js.map +1 -0
- package/lib/commonjs/config/types.js +13 -0
- package/lib/commonjs/config/types.js.map +1 -0
- package/lib/commonjs/config/validateConfig.js +134 -0
- package/lib/commonjs/config/validateConfig.js.map +1 -0
- package/lib/commonjs/format/currency.js +35 -0
- package/lib/commonjs/format/currency.js.map +1 -0
- package/lib/commonjs/format/date.js +36 -0
- package/lib/commonjs/format/date.js.map +1 -0
- package/lib/commonjs/format/invalid.js +24 -0
- package/lib/commonjs/format/invalid.js.map +1 -0
- package/lib/commonjs/format/number.js +29 -0
- package/lib/commonjs/format/number.js.map +1 -0
- package/lib/commonjs/format/units.js +184 -0
- package/lib/commonjs/format/units.js.map +1 -0
- package/lib/commonjs/i18n.js +234 -0
- package/lib/commonjs/i18n.js.map +1 -0
- package/lib/commonjs/index.js +93 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/locale/activeLocale.js +37 -0
- package/lib/commonjs/locale/activeLocale.js.map +1 -0
- package/lib/commonjs/locale/deviceLocale.js +52 -0
- package/lib/commonjs/locale/deviceLocale.js.map +1 -0
- package/lib/commonjs/locale/keyValueStorage.js +29 -0
- package/lib/commonjs/locale/keyValueStorage.js.map +1 -0
- package/lib/commonjs/locale/persistence.js +74 -0
- package/lib/commonjs/locale/persistence.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/react/I18nProvider.js +36 -0
- package/lib/commonjs/react/I18nProvider.js.map +1 -0
- package/lib/commonjs/react/hooks.js +47 -0
- package/lib/commonjs/react/hooks.js.map +1 -0
- package/lib/commonjs/translation/interpolate.js +24 -0
- package/lib/commonjs/translation/interpolate.js.map +1 -0
- package/lib/commonjs/translation/plurals.js +122 -0
- package/lib/commonjs/translation/plurals.js.map +1 -0
- package/lib/commonjs/translation/resolver.js +124 -0
- package/lib/commonjs/translation/resolver.js.map +1 -0
- package/lib/commonjs/translation/runtimeKeys.js +55 -0
- package/lib/commonjs/translation/runtimeKeys.js.map +1 -0
- package/lib/module/config/catalog.js +25 -0
- package/lib/module/config/catalog.js.map +1 -0
- package/lib/module/config/diagnostics.js +51 -0
- package/lib/module/config/diagnostics.js.map +1 -0
- package/lib/module/config/errors.js +30 -0
- package/lib/module/config/errors.js.map +1 -0
- package/lib/module/config/types.js +26 -0
- package/lib/module/config/types.js.map +1 -0
- package/lib/module/config/validateConfig.js +131 -0
- package/lib/module/config/validateConfig.js.map +1 -0
- package/lib/module/format/currency.js +32 -0
- package/lib/module/format/currency.js.map +1 -0
- package/lib/module/format/date.js +33 -0
- package/lib/module/format/date.js.map +1 -0
- package/lib/module/format/invalid.js +21 -0
- package/lib/module/format/invalid.js.map +1 -0
- package/lib/module/format/number.js +26 -0
- package/lib/module/format/number.js.map +1 -0
- package/lib/module/format/units.js +171 -0
- package/lib/module/format/units.js.map +1 -0
- package/lib/module/i18n.js +230 -0
- package/lib/module/i18n.js.map +1 -0
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/locale/activeLocale.js +33 -0
- package/lib/module/locale/activeLocale.js.map +1 -0
- package/lib/module/locale/deviceLocale.js +46 -0
- package/lib/module/locale/deviceLocale.js.map +1 -0
- package/lib/module/locale/keyValueStorage.js +25 -0
- package/lib/module/locale/keyValueStorage.js.map +1 -0
- package/lib/module/locale/persistence.js +66 -0
- package/lib/module/locale/persistence.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/I18nProvider.js +29 -0
- package/lib/module/react/I18nProvider.js.map +1 -0
- package/lib/module/react/hooks.js +42 -0
- package/lib/module/react/hooks.js.map +1 -0
- package/lib/module/translation/interpolate.js +20 -0
- package/lib/module/translation/interpolate.js.map +1 -0
- package/lib/module/translation/plurals.js +114 -0
- package/lib/module/translation/plurals.js.map +1 -0
- package/lib/module/translation/resolver.js +118 -0
- package/lib/module/translation/resolver.js.map +1 -0
- package/lib/module/translation/runtimeKeys.js +50 -0
- package/lib/module/translation/runtimeKeys.js.map +1 -0
- package/lib/typescript/commonjs/config/catalog.d.ts +18 -0
- package/lib/typescript/commonjs/config/catalog.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/diagnostics.d.ts +21 -0
- package/lib/typescript/commonjs/config/diagnostics.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/errors.d.ts +16 -0
- package/lib/typescript/commonjs/config/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/types.d.ts +127 -0
- package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/validateConfig.d.ts +8 -0
- package/lib/typescript/commonjs/config/validateConfig.d.ts.map +1 -0
- package/lib/typescript/commonjs/format/currency.d.ts +12 -0
- package/lib/typescript/commonjs/format/currency.d.ts.map +1 -0
- package/lib/typescript/commonjs/format/date.d.ts +14 -0
- package/lib/typescript/commonjs/format/date.d.ts.map +1 -0
- package/lib/typescript/commonjs/format/invalid.d.ts +12 -0
- package/lib/typescript/commonjs/format/invalid.d.ts.map +1 -0
- package/lib/typescript/commonjs/format/number.d.ts +8 -0
- package/lib/typescript/commonjs/format/number.d.ts.map +1 -0
- package/lib/typescript/commonjs/format/units.d.ts +23 -0
- package/lib/typescript/commonjs/format/units.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n.d.ts +46 -0
- package/lib/typescript/commonjs/i18n.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +27 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/locale/activeLocale.d.ts +17 -0
- package/lib/typescript/commonjs/locale/activeLocale.d.ts.map +1 -0
- package/lib/typescript/commonjs/locale/deviceLocale.d.ts +19 -0
- package/lib/typescript/commonjs/locale/deviceLocale.d.ts.map +1 -0
- package/lib/typescript/commonjs/locale/keyValueStorage.d.ts +13 -0
- package/lib/typescript/commonjs/locale/keyValueStorage.d.ts.map +1 -0
- package/lib/typescript/commonjs/locale/persistence.d.ts +24 -0
- package/lib/typescript/commonjs/locale/persistence.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/react/I18nProvider.d.ts +16 -0
- package/lib/typescript/commonjs/react/I18nProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/react/hooks.d.ts +21 -0
- package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
- package/lib/typescript/commonjs/translation/interpolate.d.ts +8 -0
- package/lib/typescript/commonjs/translation/interpolate.d.ts.map +1 -0
- package/lib/typescript/commonjs/translation/plurals.d.ts +13 -0
- package/lib/typescript/commonjs/translation/plurals.d.ts.map +1 -0
- package/lib/typescript/commonjs/translation/resolver.d.ts +24 -0
- package/lib/typescript/commonjs/translation/resolver.d.ts.map +1 -0
- package/lib/typescript/commonjs/translation/runtimeKeys.d.ts +16 -0
- package/lib/typescript/commonjs/translation/runtimeKeys.d.ts.map +1 -0
- package/lib/typescript/module/config/catalog.d.ts +18 -0
- package/lib/typescript/module/config/catalog.d.ts.map +1 -0
- package/lib/typescript/module/config/diagnostics.d.ts +21 -0
- package/lib/typescript/module/config/diagnostics.d.ts.map +1 -0
- package/lib/typescript/module/config/errors.d.ts +16 -0
- package/lib/typescript/module/config/errors.d.ts.map +1 -0
- package/lib/typescript/module/config/types.d.ts +127 -0
- package/lib/typescript/module/config/types.d.ts.map +1 -0
- package/lib/typescript/module/config/validateConfig.d.ts +8 -0
- package/lib/typescript/module/config/validateConfig.d.ts.map +1 -0
- package/lib/typescript/module/format/currency.d.ts +12 -0
- package/lib/typescript/module/format/currency.d.ts.map +1 -0
- package/lib/typescript/module/format/date.d.ts +14 -0
- package/lib/typescript/module/format/date.d.ts.map +1 -0
- package/lib/typescript/module/format/invalid.d.ts +12 -0
- package/lib/typescript/module/format/invalid.d.ts.map +1 -0
- package/lib/typescript/module/format/number.d.ts +8 -0
- package/lib/typescript/module/format/number.d.ts.map +1 -0
- package/lib/typescript/module/format/units.d.ts +23 -0
- package/lib/typescript/module/format/units.d.ts.map +1 -0
- package/lib/typescript/module/i18n.d.ts +46 -0
- package/lib/typescript/module/i18n.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +27 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/locale/activeLocale.d.ts +17 -0
- package/lib/typescript/module/locale/activeLocale.d.ts.map +1 -0
- package/lib/typescript/module/locale/deviceLocale.d.ts +19 -0
- package/lib/typescript/module/locale/deviceLocale.d.ts.map +1 -0
- package/lib/typescript/module/locale/keyValueStorage.d.ts +13 -0
- package/lib/typescript/module/locale/keyValueStorage.d.ts.map +1 -0
- package/lib/typescript/module/locale/persistence.d.ts +24 -0
- package/lib/typescript/module/locale/persistence.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/react/I18nProvider.d.ts +16 -0
- package/lib/typescript/module/react/I18nProvider.d.ts.map +1 -0
- package/lib/typescript/module/react/hooks.d.ts +21 -0
- package/lib/typescript/module/react/hooks.d.ts.map +1 -0
- package/lib/typescript/module/translation/interpolate.d.ts +8 -0
- package/lib/typescript/module/translation/interpolate.d.ts.map +1 -0
- package/lib/typescript/module/translation/plurals.d.ts +13 -0
- package/lib/typescript/module/translation/plurals.d.ts.map +1 -0
- package/lib/typescript/module/translation/resolver.d.ts +24 -0
- package/lib/typescript/module/translation/resolver.d.ts.map +1 -0
- package/lib/typescript/module/translation/runtimeKeys.d.ts +16 -0
- package/lib/typescript/module/translation/runtimeKeys.d.ts.map +1 -0
- package/package.json +41 -18
- package/skills/sdk-rn-i18n/SKILL.md +27 -0
- package/src/config/diagnostics.ts +2 -0
- package/src/format/currency.ts +5 -0
- package/src/format/date.ts +10 -4
- package/src/i18n.ts +93 -9
- package/src/index.ts +5 -3
- package/src/locale/activeLocale.ts +10 -0
- package/src/locale/persistence.ts +19 -0
- package/src/translation/plurals.ts +74 -5
- package/src/translation/runtimeKeys.ts +28 -1
- package/src/tooling/cli.ts +0 -76
- package/src/tooling/generateKeys.ts +0 -62
- package/src/tooling/index.ts +0 -27
- package/src/tooling/report.ts +0 -109
- package/src/tooling/runner.ts +0 -111
- package/src/tooling/scan.ts +0 -193
- package/src/tooling/sync.ts +0 -193
- package/src/tooling/types.ts +0 -119
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export const PLURAL_CATEGORIES = ['zero', 'one', 'two', 'few', 'many', 'other'];
|
|
4
|
+
const oneOtherRule = count => count === 1 ? 'one' : 'other';
|
|
5
|
+
const otherOnlyRule = () => 'other';
|
|
6
|
+
/** French and Brazilian Portuguese: 0 and 1 are both singular. */
|
|
7
|
+
const zeroOneRule = count => count === 0 || count === 1 ? 'one' : 'other';
|
|
8
|
+
|
|
9
|
+
/** Russian, Ukrainian, Polish, Czech and their neighbours (CLDR). */
|
|
10
|
+
const slavicRule = count => {
|
|
11
|
+
if (!Number.isInteger(count)) {
|
|
12
|
+
return 'many';
|
|
13
|
+
}
|
|
14
|
+
const mod10 = Math.abs(count) % 10;
|
|
15
|
+
const mod100 = Math.abs(count) % 100;
|
|
16
|
+
if (mod10 === 1 && mod100 !== 11) {
|
|
17
|
+
return 'one';
|
|
18
|
+
}
|
|
19
|
+
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) {
|
|
20
|
+
return 'few';
|
|
21
|
+
}
|
|
22
|
+
return 'many';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Arabic (CLDR), which uses every category. */
|
|
26
|
+
const arabicRule = count => {
|
|
27
|
+
if (count === 0) return 'zero';
|
|
28
|
+
if (count === 1) return 'one';
|
|
29
|
+
if (count === 2) return 'two';
|
|
30
|
+
const mod100 = Math.abs(count) % 100;
|
|
31
|
+
if (mod100 >= 3 && mod100 <= 10) return 'few';
|
|
32
|
+
if (mod100 >= 11 && mod100 <= 99) return 'many';
|
|
33
|
+
return 'other';
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Package-owned plural rules, a compact subset of CLDR. Intl.PluralRules is not
|
|
38
|
+
* implemented by Hermes, so rules are resolved from configuration to keep
|
|
39
|
+
* behavior identical across devices and test environments.
|
|
40
|
+
*
|
|
41
|
+
* A language that is not here falls back to `count === 1 ? one : other`, which
|
|
42
|
+
* is wrong for most of the world — Korean and Thai have no singular, French
|
|
43
|
+
* calls 0 singular, Russian has `few` and `many` — so the fallback now reports
|
|
44
|
+
* a diagnostic once per locale rather than being silently applied (I18N-12).
|
|
45
|
+
*/
|
|
46
|
+
const BUILT_IN_RULES = {
|
|
47
|
+
// one/other
|
|
48
|
+
en: oneOtherRule,
|
|
49
|
+
de: oneOtherRule,
|
|
50
|
+
es: oneOtherRule,
|
|
51
|
+
it: oneOtherRule,
|
|
52
|
+
nl: oneOtherRule,
|
|
53
|
+
sv: oneOtherRule,
|
|
54
|
+
da: oneOtherRule,
|
|
55
|
+
nb: oneOtherRule,
|
|
56
|
+
fi: oneOtherRule,
|
|
57
|
+
el: oneOtherRule,
|
|
58
|
+
he: oneOtherRule,
|
|
59
|
+
// other only
|
|
60
|
+
ja: otherOnlyRule,
|
|
61
|
+
vi: otherOnlyRule,
|
|
62
|
+
ko: otherOnlyRule,
|
|
63
|
+
zh: otherOnlyRule,
|
|
64
|
+
th: otherOnlyRule,
|
|
65
|
+
id: otherOnlyRule,
|
|
66
|
+
ms: otherOnlyRule,
|
|
67
|
+
// 0 and 1 are singular
|
|
68
|
+
fr: zeroOneRule,
|
|
69
|
+
pt: zeroOneRule,
|
|
70
|
+
// Slavic
|
|
71
|
+
ru: slavicRule,
|
|
72
|
+
uk: slavicRule,
|
|
73
|
+
pl: slavicRule,
|
|
74
|
+
cs: slavicRule,
|
|
75
|
+
sk: slavicRule,
|
|
76
|
+
// Every category
|
|
77
|
+
ar: arabicRule
|
|
78
|
+
};
|
|
79
|
+
export const DEFAULT_PLURAL_RULE = oneOtherRule;
|
|
80
|
+
|
|
81
|
+
/** True when this package has a rule for the language, or the locale brought one. */
|
|
82
|
+
export function hasPluralRule(locale) {
|
|
83
|
+
if (locale.pluralRule) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
const language = locale.code.split('-')[0]?.toLowerCase() ?? '';
|
|
87
|
+
return language in BUILT_IN_RULES;
|
|
88
|
+
}
|
|
89
|
+
export function resolvePluralRule(locale) {
|
|
90
|
+
if (locale.pluralRule) {
|
|
91
|
+
return locale.pluralRule;
|
|
92
|
+
}
|
|
93
|
+
const language = locale.code.split('-')[0]?.toLowerCase() ?? '';
|
|
94
|
+
return BUILT_IN_RULES[language] ?? DEFAULT_PLURAL_RULE;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A plural group is an object whose keys are all plural categories, whose
|
|
99
|
+
* values are all strings, and which provides the required `other` variant.
|
|
100
|
+
*/
|
|
101
|
+
export function isPluralGroup(node) {
|
|
102
|
+
if (typeof node !== 'object' || node === null) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const keys = Object.keys(node);
|
|
106
|
+
if (keys.length === 0 || !('other' in node)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return keys.every(key => PLURAL_CATEGORIES.includes(key) && typeof node[key] === 'string');
|
|
110
|
+
}
|
|
111
|
+
export function selectPluralVariant(group, category) {
|
|
112
|
+
return group[category] ?? group.other;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=plurals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PLURAL_CATEGORIES","oneOtherRule","count","otherOnlyRule","zeroOneRule","slavicRule","Number","isInteger","mod10","Math","abs","mod100","arabicRule","BUILT_IN_RULES","en","de","es","it","nl","sv","da","nb","fi","el","he","ja","vi","ko","zh","th","id","ms","fr","pt","ru","uk","pl","cs","sk","ar","DEFAULT_PLURAL_RULE","hasPluralRule","locale","pluralRule","language","code","split","toLowerCase","resolvePluralRule","isPluralGroup","node","keys","Object","length","every","key","includes","selectPluralVariant","group","category","other"],"sourceRoot":"../../../src","sources":["translation/plurals.ts"],"mappings":";;AAEA,OAAO,MAAMA,iBAA4C,GAAG,CAC3D,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,EACN,OAAO,CACP;AAED,MAAMC,YAAwB,GAAGC,KAAK,IAAKA,KAAK,KAAK,CAAC,GAAG,KAAK,GAAG,OAAQ;AACzE,MAAMC,aAAyB,GAAGA,CAAA,KAAM,OAAO;AAC/C;AACA,MAAMC,WAAuB,GAAGF,KAAK,IAAKA,KAAK,KAAK,CAAC,IAAIA,KAAK,KAAK,CAAC,GAAG,KAAK,GAAG,OAAQ;;AAEvF;AACA,MAAMG,UAAsB,GAAGH,KAAK,IAAI;EACvC,IAAI,CAACI,MAAM,CAACC,SAAS,CAACL,KAAK,CAAC,EAAE;IAC7B,OAAO,MAAM;EACd;EACA,MAAMM,KAAK,GAAGC,IAAI,CAACC,GAAG,CAACR,KAAK,CAAC,GAAG,EAAE;EAClC,MAAMS,MAAM,GAAGF,IAAI,CAACC,GAAG,CAACR,KAAK,CAAC,GAAG,GAAG;EACpC,IAAIM,KAAK,KAAK,CAAC,IAAIG,MAAM,KAAK,EAAE,EAAE;IACjC,OAAO,KAAK;EACb;EACA,IAAIH,KAAK,IAAI,CAAC,IAAIA,KAAK,IAAI,CAAC,KAAKG,MAAM,GAAG,EAAE,IAAIA,MAAM,GAAG,EAAE,CAAC,EAAE;IAC7D,OAAO,KAAK;EACb;EACA,OAAO,MAAM;AACd,CAAC;;AAED;AACA,MAAMC,UAAsB,GAAGV,KAAK,IAAI;EACvC,I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CAAC,IAAID,KAAK,CAACE,KAAK;AACtC","ignoreList":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { interpolate } from "./interpolate.js";
|
|
4
|
+
import { isPluralGroup, resolvePluralRule, selectPluralVariant } from "./plurals.js";
|
|
5
|
+
/**
|
|
6
|
+
* How many lookup paths are remembered. An app that misses many distinct keys
|
|
7
|
+
* forgets the oldest first, so memory stays bounded (I18N-11).
|
|
8
|
+
*/
|
|
9
|
+
const WARNED_CAPACITY = 500;
|
|
10
|
+
export function warnOnce(context, dedupeKey, diagnostic) {
|
|
11
|
+
const {
|
|
12
|
+
warned
|
|
13
|
+
} = context;
|
|
14
|
+
if (warned.has(dedupeKey)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
warned.add(dedupeKey);
|
|
18
|
+
if (warned.size > WARNED_CAPACITY) {
|
|
19
|
+
const oldest = warned.values().next().value;
|
|
20
|
+
if (oldest !== undefined) warned.delete(oldest);
|
|
21
|
+
}
|
|
22
|
+
context.report(diagnostic);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Walks a dot-path key through a nested translation namespace. */
|
|
26
|
+
export function getTranslationNode(namespace, key) {
|
|
27
|
+
if (!namespace) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
let node = namespace;
|
|
31
|
+
for (const segment of key.split('.')) {
|
|
32
|
+
if (typeof node !== 'object' || node === null) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const next = node[segment];
|
|
36
|
+
if (next === undefined) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
node = next;
|
|
40
|
+
}
|
|
41
|
+
return node;
|
|
42
|
+
}
|
|
43
|
+
function pickValue(node, locale, options, warnings, key) {
|
|
44
|
+
if (typeof node === 'string') {
|
|
45
|
+
return node;
|
|
46
|
+
}
|
|
47
|
+
if (isPluralGroup(node)) {
|
|
48
|
+
const count = options?.count;
|
|
49
|
+
if (count === undefined) {
|
|
50
|
+
return node.other;
|
|
51
|
+
}
|
|
52
|
+
return selectPluralVariant(node, resolvePluralRule(locale)(count));
|
|
53
|
+
}
|
|
54
|
+
warnOnce(warnings, `invalid-value|${locale.code}|${key}`, {
|
|
55
|
+
code: 'invalid_value',
|
|
56
|
+
key,
|
|
57
|
+
locale: locale.code,
|
|
58
|
+
message: `Translation value for "${key}" in locale "${locale.code}" is not text or a plural group; treating it as missing.`
|
|
59
|
+
});
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Resolves a key through the active locale, its ordered fallback chain, and
|
|
65
|
+
* declared runtime-only default text, applying plural selection and named
|
|
66
|
+
* variable interpolation. Misses are reported with one console warning per
|
|
67
|
+
* lookup path; a full-chain miss applies the configured missing-translation
|
|
68
|
+
* policy (FR-008…FR-011, FR-033).
|
|
69
|
+
*/
|
|
70
|
+
export function translate(context, activeCode, key, vars, options) {
|
|
71
|
+
const active = context.localesByCode.get(activeCode);
|
|
72
|
+
const chain = [activeCode, ...(active?.fallbackChain ?? [])];
|
|
73
|
+
const mergedVars = options?.count === undefined ? vars : {
|
|
74
|
+
count: options.count,
|
|
75
|
+
...vars
|
|
76
|
+
};
|
|
77
|
+
const interpolateWith = (text, sourceLocale) => interpolate(text, mergedVars, name => warnOnce(context, `missing-var|${sourceLocale}|${key}|${name}`, {
|
|
78
|
+
code: 'missing_variable',
|
|
79
|
+
key,
|
|
80
|
+
locale: sourceLocale,
|
|
81
|
+
message: `Missing interpolation variable "${name}" for key "${key}" in locale "${sourceLocale}".`
|
|
82
|
+
}));
|
|
83
|
+
for (const code of chain) {
|
|
84
|
+
const locale = context.localesByCode.get(code);
|
|
85
|
+
if (!locale) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const node = getTranslationNode(context.resources[code], key);
|
|
89
|
+
if (node === undefined) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const value = pickValue(node, locale, options, context, key);
|
|
93
|
+
if (value === undefined) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (code !== activeCode) {
|
|
97
|
+
warnOnce(context, `fallback|${activeCode}|${key}`, {
|
|
98
|
+
code: 'fallback_used',
|
|
99
|
+
key,
|
|
100
|
+
locale: activeCode,
|
|
101
|
+
message: `Key "${key}" is missing in locale "${activeCode}"; served from fallback locale "${code}".`
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return interpolateWith(value, code);
|
|
105
|
+
}
|
|
106
|
+
const runtimeEntry = context.runtimeEntries.get(key);
|
|
107
|
+
if (runtimeEntry) {
|
|
108
|
+
return interpolateWith(runtimeEntry.defaultText, activeCode);
|
|
109
|
+
}
|
|
110
|
+
warnOnce(context, `missing|${activeCode}|${key}`, {
|
|
111
|
+
code: 'missing_translation',
|
|
112
|
+
key,
|
|
113
|
+
locale: activeCode,
|
|
114
|
+
message: `Missing translation for key "${key}" in locale "${activeCode}" and its entire fallback chain.`
|
|
115
|
+
});
|
|
116
|
+
return context.missingTranslation.mode === 'placeholder' ? context.missingTranslation.text : key;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["interpolate","isPluralGroup","resolvePluralRule","selectPluralVariant","WARNED_CAPACITY","warnOnce","context","dedupeKey","diagnostic","warned","has","add","size","oldest","values","next","value","undefined","delete","report","getTranslationNode","namespace","key","node","segment","split","pickValue","locale","options","warnings","count","other","code","message","translate","activeCode","vars","active","localesByCode","get","chain","fallbackChain","mergedVars","interpolateWith","text","sourceLocale","name","resources","runtimeEntry","runtimeEntries","defaultText","missingTranslation","mode"],"sourceRoot":"../../../src","sources":["translation/resolver.ts"],"mappings":";;AAUA,SAASA,WAAW,QAAQ,kBAAe;AAC3C,SAASC,aAAa,EAAEC,iBAAiB,EAAEC,mBAAmB,QAAQ,cAAW;AAaj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E,gCAAgCX,GAAG,gBAAgBa,UAAU;EACvE,CAAC,CAAC;EACF,OAAO7B,OAAO,CAAC6C,kBAAkB,CAACC,IAAI,KAAK,aAAa,GAAG9C,OAAO,CAAC6C,kBAAkB,CAACP,IAAI,GAAGtB,GAAG;AACjG","ignoreList":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { I18nConfigError } from "../config/types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Registry of declared runtime-only translation entries. Entries participate
|
|
7
|
+
* in the same lookup pipeline as scanned template keys and are protected from
|
|
8
|
+
* removal during locale JSON synchronization.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export function createRuntimeRegistry(entries) {
|
|
12
|
+
const registry = new Map();
|
|
13
|
+
if (entries) {
|
|
14
|
+
registerRuntimeEntries(registry, entries);
|
|
15
|
+
}
|
|
16
|
+
return registry;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The same checks the configured entries get (I18N-06): an entry registered at
|
|
21
|
+
* runtime by a lazily loaded feature used to be written in unvalidated, so a
|
|
22
|
+
* missing key or a non-string default surfaced only when a screen rendered it.
|
|
23
|
+
*/
|
|
24
|
+
export function validateRuntimeEntries(entries) {
|
|
25
|
+
const issues = [];
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
if (!entry?.key) {
|
|
29
|
+
issues.push('Runtime-only entries must declare a non-empty key.');
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (seen.has(entry.key)) {
|
|
33
|
+
issues.push(`Duplicate runtime-only entry "${entry.key}".`);
|
|
34
|
+
}
|
|
35
|
+
seen.add(entry.key);
|
|
36
|
+
if (typeof entry.defaultText !== 'string') {
|
|
37
|
+
issues.push(`Runtime-only entry "${entry.key}" must declare default text.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (issues.length > 0) {
|
|
41
|
+
throw new I18nConfigError(issues);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function registerRuntimeEntries(registry, entries) {
|
|
45
|
+
validateRuntimeEntries(entries);
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
registry.set(entry.key, entry);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=runtimeKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["I18nConfigError","createRuntimeRegistry","entries","registry","Map","registerRuntimeEntries","validateRuntimeEntries","issues","seen","Set","entry","key","push","has","add","defaultText","length","set"],"sourceRoot":"../../../src","sources":["translation/runtimeKeys.ts"],"mappings":";;AAAA,SAASA,eAAe,QAAsC,oBAAiB;;AAE/E;AACA;AACA;AACA;AACA;;AAGA,OAAO,SAASC,qBAAqBA,CACpCC,OAA4C,EACrB;EACvB,MAAMC,QAA8B,GAAG,IAAIC,GAAG,CAAC,CAAC;EAChD,IAAIF,OAAO,EAAE;IACZG,sBAAsB,CAACF,QAAQ,EAAED,OAAO,CAAC;EAC1C;EACA,OAAOC,QAAQ;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,sBAAsBA,CAACJ,OAA2C,EAAQ;EACzF,MAAMK,MAAgB,GAAG,EAAE;EAC3B,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAS,CAAC;EAC9B,KAAK,MAAMC,KAAK,IAAIR,OAAO,EAAE;IAC5B,IAAI,CAACQ,KAAK,EAAEC,GAAG,EAAE;MAChBJ,MAAM,CAACK,IAAI,CAAC,oDAAoD,CAAC;MACjE;IACD;IACA,IAAIJ,IAAI,CAACK,GAAG,CAACH,KAAK,CAACC,GAAG,CAAC,EAAE;MACxBJ,MAAM,CAACK,IAAI,CAAC,iCAAiCF,KAAK,CAACC,GAAG,IAAI,CAAC;IAC5D;IACAH,IAAI,CAACM,GAAG,CAACJ,KAAK,CAACC,GAAG,CAAC;IACnB,IAAI,OAAOD,KAAK,CAACK,WAAW,KAAK,QAAQ,EAAE;MAC1CR,MAAM,CAACK,IAAI,CAAC,uBAAuBF,KAAK,CAACC,GAAG,8BAA8B,CAAC;IAC5E;EACD;EACA,IAAIJ,MAAM,CAACS,MAAM,GAAG,CAAC,EAAE;IACtB,MAAM,IAAIhB,eAAe,CAACO,MAAM,CAAC;EAClC;AACD;AAEA,OAAO,SAASF,sBAAsBA,CACrCF,QAA8B,EAC9BD,OAA2C,EACpC;EACPI,sBAAsB,CAACJ,OAAO,CAAC;EAC/B,KAAK,MAAMQ,KAAK,IAAIR,OAAO,EAAE;IAC5BC,QAAQ,CAACc,GAAG,CAACP,KAAK,CAACC,GAAG,EAAED,KAAK,CAAC;EAC/B;AACD","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RuntimeTranslationEntry } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Runtime entries for a package's message catalog (I18N-13), so an app registers
|
|
4
|
+
* an SDK's copy in one line and translates it like its own:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* createI18n({ ...config, runtimeEntries: runtimeEntriesFromCatalog(paymentMessages.user) });
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Catalogs mark variables `{name}`; rn-i18n's are `{{name}}`, so they are
|
|
11
|
+
* converted. `policy: 'add'` lets the sync CLI write missing keys into each locale
|
|
12
|
+
* file with the default text.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runtimeEntriesFromCatalog(catalog: Readonly<Record<string, string>>, options?: {
|
|
15
|
+
readonly policy?: 'add' | 'report';
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
}): RuntimeTranslationEntry[];
|
|
18
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../../src/config/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACzC,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GACjF,uBAAuB,EAAE,CAO3B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What rn-i18n reports. Stable: an app may branch on these. */
|
|
2
|
+
export type I18nDiagnosticCode = 'missing_translation' | 'fallback_used' | 'missing_variable' | 'invalid_value' | 'invalid_format' | 'locale_unsupported' | 'plural_rule_default' | 'locale_read_failed' | 'locale_write_failed' | 'listener_threw';
|
|
3
|
+
export interface I18nDiagnostic {
|
|
4
|
+
readonly code: I18nDiagnosticCode;
|
|
5
|
+
/** For people: names the key, locale or variable involved. */
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly key?: string;
|
|
8
|
+
readonly locale?: string;
|
|
9
|
+
}
|
|
10
|
+
export type I18nDiagnosticHandler = (diagnostic: I18nDiagnostic) => void;
|
|
11
|
+
/**
|
|
12
|
+
* One place every diagnostic goes through (I18N-11): the app's SDK sinks always
|
|
13
|
+
* (`installSdkSink` from rn-core), then `onDiagnostic` when the app gave one,
|
|
14
|
+
* otherwise `console.warn` in development builds and tests only.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createReporter(onDiagnostic?: I18nDiagnosticHandler): I18nDiagnosticHandler;
|
|
17
|
+
/** For the few call sites that run before or outside an i18n instance. */
|
|
18
|
+
export declare const defaultReporter: I18nDiagnosticHandler;
|
|
19
|
+
/** Foreign error text, shaped before it reaches a message. */
|
|
20
|
+
export declare function describeError(error: unknown): string;
|
|
21
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../../../src/config/diagnostics.ts"],"names":[],"mappings":"AAMA,gEAAgE;AAChE,MAAM,MAAM,kBAAkB,GAC3B,qBAAqB,GACrB,eAAe,GACf,kBAAkB,GAClB,eAAe,GACf,gBAAgB,GAChB,oBAAoB,GACpB,qBAAqB,GACrB,oBAAoB,GACpB,qBAAqB,GACrB,gBAAgB,CAAC;AAEpB,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,UAAU,EAAE,cAAc,KAAK,IAAI,CAAC;AAiBzE;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,YAAY,CAAC,EAAE,qBAAqB,GAAG,qBAAqB,CAY1F;AAED,0EAA0E;AAC1E,eAAO,MAAM,eAAe,uBAAmB,CAAC;AAEhD,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEpD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SdkError } from '@chipmobilesdk/rn-core';
|
|
2
|
+
/** The package's error codes. */
|
|
3
|
+
export type I18nErrorCode = 'invalid_config' | 'unit_conversion';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration error listing every detected violation. An `SdkError`
|
|
6
|
+
* (`@chipmobilesdk/rn-core`) with `pkg: 'rn-i18n'`.
|
|
7
|
+
*/
|
|
8
|
+
export declare class I18nConfigError extends SdkError<I18nErrorCode> {
|
|
9
|
+
readonly issues: readonly string[];
|
|
10
|
+
constructor(issues: readonly string[]);
|
|
11
|
+
}
|
|
12
|
+
/** A unit conversion the package cannot perform, such as across dimensions. */
|
|
13
|
+
export declare class UnitConversionError extends SdkError<I18nErrorCode> {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/config/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,iCAAiC;AACjC,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AAEjE;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,QAAQ,CAAC,aAAa,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;gBAEvB,MAAM,EAAE,SAAS,MAAM,EAAE;CAOrC;AAED,+EAA+E;AAC/E,qBAAa,mBAAoB,SAAQ,QAAQ,CAAC,aAAa,CAAC;gBACnD,OAAO,EAAE,MAAM;CAI3B"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public configuration and contract types for @chipmobilesdk/rn-i18n.
|
|
3
|
+
*
|
|
4
|
+
* The package has one runtime dependency, rn-core; formatting uses the Intl APIs
|
|
5
|
+
* built into Hermes (Intl.NumberFormat, Intl.DateTimeFormat), while plural
|
|
6
|
+
* rules and unit conversion are package-owned because Intl.PluralRules and
|
|
7
|
+
* Intl unit-style formatting are not reliably available in Hermes.
|
|
8
|
+
*/
|
|
9
|
+
import type { I18nDiagnosticHandler } from './diagnostics';
|
|
10
|
+
export type LocaleDirection = 'ltr' | 'rtl';
|
|
11
|
+
export type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
|
|
12
|
+
export type PluralRule = (count: number) => PluralCategory;
|
|
13
|
+
export type UnitDimension = 'length' | 'mass' | 'volume' | 'temperature';
|
|
14
|
+
export type UnitId = 'millimeter' | 'centimeter' | 'meter' | 'kilometer' | 'inch' | 'foot' | 'mile' | 'gram' | 'kilogram' | 'ounce' | 'pound' | 'milliliter' | 'liter' | 'gallon' | 'celsius' | 'fahrenheit' | 'kelvin';
|
|
15
|
+
export interface LocaleConfig {
|
|
16
|
+
/** BCP-47 language-region code, e.g. `vi-VN`, `en-US`, `ja-JP`. */
|
|
17
|
+
code: string;
|
|
18
|
+
displayName: string;
|
|
19
|
+
direction: LocaleDirection;
|
|
20
|
+
/**
|
|
21
|
+
* Ordered locale codes consulted when a key is missing from this locale.
|
|
22
|
+
* Every entry must be another supported locale; cycles, duplicates, and
|
|
23
|
+
* self-references are rejected during setup validation.
|
|
24
|
+
*/
|
|
25
|
+
fallbackChain: string[];
|
|
26
|
+
/** ISO-4217 currency code used when no explicit currency is requested. */
|
|
27
|
+
defaultCurrency: string;
|
|
28
|
+
defaultUnit: UnitId;
|
|
29
|
+
/**
|
|
30
|
+
* Default Intl.DateTimeFormat options for this locale. Restricted to the
|
|
31
|
+
* component options supported by Hermes on both Android and iOS.
|
|
32
|
+
*/
|
|
33
|
+
defaultDateFormat: Intl.DateTimeFormatOptions;
|
|
34
|
+
/** Default Intl.NumberFormat options for this locale. */
|
|
35
|
+
defaultNumberFormat: Intl.NumberFormatOptions;
|
|
36
|
+
/** Optional plural rule override; defaults to the built-in language rule. */
|
|
37
|
+
pluralRule?: PluralRule;
|
|
38
|
+
}
|
|
39
|
+
export type TranslationNode = string | {
|
|
40
|
+
[key: string]: TranslationNode;
|
|
41
|
+
};
|
|
42
|
+
export type TranslationNamespace = {
|
|
43
|
+
[key: string]: TranslationNode;
|
|
44
|
+
};
|
|
45
|
+
/** App-owned translation resources keyed by locale code. */
|
|
46
|
+
export type TranslationResources = {
|
|
47
|
+
[localeCode: string]: TranslationNamespace;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A translation key intentionally resolved at runtime and therefore not
|
|
51
|
+
* discoverable by static source scanning. Declared entries are protected
|
|
52
|
+
* from removal during locale JSON synchronization.
|
|
53
|
+
*/
|
|
54
|
+
export interface RuntimeTranslationEntry {
|
|
55
|
+
key: string;
|
|
56
|
+
/** Template text used when no locale resource provides a value. */
|
|
57
|
+
defaultText: string;
|
|
58
|
+
/**
|
|
59
|
+
* Synchronization policy when the key is missing from a locale file:
|
|
60
|
+
* `add` writes the default text, `report` only lists it. Default: `report`.
|
|
61
|
+
*/
|
|
62
|
+
policy?: 'add' | 'report';
|
|
63
|
+
/** Owning feature note surfaced in the extraction report. */
|
|
64
|
+
description?: string;
|
|
65
|
+
}
|
|
66
|
+
export type MissingTranslationPolicy = {
|
|
67
|
+
mode: 'key';
|
|
68
|
+
} | {
|
|
69
|
+
mode: 'placeholder';
|
|
70
|
+
text: string;
|
|
71
|
+
};
|
|
72
|
+
export type InvalidFormatPolicy = {
|
|
73
|
+
mode: 'placeholder';
|
|
74
|
+
text: string;
|
|
75
|
+
} | {
|
|
76
|
+
mode: 'error';
|
|
77
|
+
};
|
|
78
|
+
/** App-injected persistence contract. The package never bundles a backend. */
|
|
79
|
+
export interface LocaleStorageAdapter {
|
|
80
|
+
getItem(key: string): Promise<string | null>;
|
|
81
|
+
setItem(key: string, value: string): Promise<void>;
|
|
82
|
+
removeItem(key: string): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* A synchronous read, for a store that has one (MMKV, rn-core's `KeyValuePort`).
|
|
85
|
+
* With it, `initSync()` resolves the locale before the first render, so the app
|
|
86
|
+
* never paints a frame in the wrong language (PERF-08).
|
|
87
|
+
*/
|
|
88
|
+
getItemSync?(key: string): string | null;
|
|
89
|
+
}
|
|
90
|
+
/** Returns the device locale, or undefined when detection is unavailable. */
|
|
91
|
+
export type DeviceLocaleProvider = () => string | undefined;
|
|
92
|
+
export interface I18nConfig {
|
|
93
|
+
locales: LocaleConfig[];
|
|
94
|
+
/** Recovery locale when persistence or device detection cannot decide. */
|
|
95
|
+
primaryLocale: string;
|
|
96
|
+
resources: TranslationResources;
|
|
97
|
+
runtimeEntries?: RuntimeTranslationEntry[];
|
|
98
|
+
/** Persist the selected locale across launches. Default: true. */
|
|
99
|
+
persistLocale?: boolean;
|
|
100
|
+
/** Required when `persistLocale` is not disabled. */
|
|
101
|
+
storage?: LocaleStorageAdapter;
|
|
102
|
+
/**
|
|
103
|
+
* Receives every diagnostic: missing translations and variables, fallbacks,
|
|
104
|
+
* invalid formats, persistence failures. Defaults to `console.warn` in
|
|
105
|
+
* development builds only. Diagnostics also reach rn-core's SDK sinks.
|
|
106
|
+
*/
|
|
107
|
+
onDiagnostic?: I18nDiagnosticHandler;
|
|
108
|
+
deviceLocale?: DeviceLocaleProvider;
|
|
109
|
+
/** Default: `{ mode: 'key' }`. */
|
|
110
|
+
missingTranslation?: MissingTranslationPolicy;
|
|
111
|
+
/** Default: `{ mode: 'placeholder', text: '—' }`. */
|
|
112
|
+
invalidFormat?: InvalidFormatPolicy;
|
|
113
|
+
}
|
|
114
|
+
export type LocaleSelectionSource = 'persisted' | 'device' | 'languageMatch' | 'primaryFallback' | 'runtimeSwitch';
|
|
115
|
+
export interface ActiveLocalePreference {
|
|
116
|
+
code: string;
|
|
117
|
+
source: LocaleSelectionSource;
|
|
118
|
+
/** True when an unsupported persisted locale was discarded. */
|
|
119
|
+
recovered: boolean;
|
|
120
|
+
}
|
|
121
|
+
export type TranslateVars = Record<string, string | number>;
|
|
122
|
+
export interface TranslateOptions {
|
|
123
|
+
/** Selects the plural variant and is exposed as the `count` variable. */
|
|
124
|
+
count?: number;
|
|
125
|
+
}
|
|
126
|
+
export { I18nConfigError } from './errors';
|
|
127
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/config/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,KAAK,CAAC;AAE5C,MAAM,MAAM,cAAc,G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AC,EAAE,oBAAoB,CAAC;IAC/B;;;;OAIG;IACH,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACrC,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,kCAAkC;IAClC,kBAAkB,CAAC,EAAE,wBAAwB,CAAC;IAC9C,qDAAqD;IACrD,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED,MAAM,MAAM,qBAAqB,GAChC,WAAW,GAAG,QAAQ,GAAG,eAAe,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAEhF,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,qBAAqB,CAAC;IAC9B,+DAA+D;IAC/D,SAAS,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAChC,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAGD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { I18nConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an I18nConfig before any localized content is served (FR-003,
|
|
4
|
+
* FR-046). Collects every violation and throws a single I18nConfigError so
|
|
5
|
+
* apps see the complete picture instead of fixing issues one at a time.
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateConfig(config: I18nConfig, knownUnits: ReadonlySet<string>): void;
|
|
8
|
+
//# sourceMappingURL=validateConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateConfig.d.ts","sourceRoot":"","sources":["../../../../src/config/validateConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,SAAS,CAAC;AAGxD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CA0DxF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InvalidFormatPolicy } from '../config/types';
|
|
2
|
+
/**
|
|
3
|
+
* Locale-aware currency formatting. The locale's configured default currency
|
|
4
|
+
* applies unless the caller passes an explicit currency override (FR-021).
|
|
5
|
+
*
|
|
6
|
+
* `locale.defaultNumberFormat` is deliberately **not** applied here: a currency
|
|
7
|
+
* carries its own minor units (yen has none, dinar has three), and the locale's
|
|
8
|
+
* generic number options would override them — ¥1,234.56 instead of ¥1,235.
|
|
9
|
+
* Pass the options you want for a currency explicitly (I18N-09).
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatCurrencyValue(value: number, localeCode: string, defaultCurrency: string, currencyOverride: string | undefined, options: Intl.NumberFormatOptions | undefined, invalidFormat: InvalidFormatPolicy): string;
|
|
12
|
+
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../../src/format/currency.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3D;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,OAAO,EAAE,IAAI,CAAC,mBAAmB,GAAG,SAAS,EAC7C,aAAa,EAAE,mBAAmB,GAChC,MAAM,CAkBR"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InvalidFormatPolicy } from '../config/types';
|
|
2
|
+
/**
|
|
3
|
+
* Locale-aware date formatting through the Hermes built-in
|
|
4
|
+
* Intl.DateTimeFormat.
|
|
5
|
+
*
|
|
6
|
+
* Options are **merged** over the locale's configured default, the way
|
|
7
|
+
* `formatNumber` has always worked: `{ month: 'long' }` changes the month and
|
|
8
|
+
* keeps the year and day. Replacing the default wholesale, which this used to
|
|
9
|
+
* do, meant one option silently dropped every other component — and the two
|
|
10
|
+
* formatters disagreed about what an option meant (I18N-09). Pass
|
|
11
|
+
* `{ replaceDefaults: true }` for the old behaviour.
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatDateValue(value: Date | number, localeCode: string, defaults: Intl.DateTimeFormatOptions, override: Intl.DateTimeFormatOptions | undefined, invalidFormat: InvalidFormatPolicy, replaceDefaults?: boolean): string;
|
|
14
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../../src/format/date.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3D;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,IAAI,GAAG,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,IAAI,CAAC,qBAAqB,EACpC,QAAQ,EAAE,IAAI,CAAC,qBAAqB,GAAG,SAAS,EAChD,aAAa,EAAE,mBAAmB,EAClC,eAAe,UAAQ,GACrB,MAAM,CAeR"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type I18nDiagnosticHandler } from '../config/diagnostics';
|
|
2
|
+
import type { InvalidFormatPolicy } from '../config/types';
|
|
3
|
+
/** The policy as an i18n instance resolves it: with the instance's reporter. */
|
|
4
|
+
export type ResolvedInvalidFormatPolicy = InvalidFormatPolicy & {
|
|
5
|
+
readonly report?: I18nDiagnosticHandler | undefined;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Applies the configured invalid-format behavior: return the placeholder, or
|
|
9
|
+
* throw a clear formatting error in `error` mode (FR-037, FR-045).
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyInvalidFormatPolicy(policy: ResolvedInvalidFormatPolicy, message: string): string;
|
|
12
|
+
//# sourceMappingURL=invalid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid.d.ts","sourceRoot":"","sources":["../../../../src/format/invalid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,gFAAgF;AAChF,MAAM,MAAM,2BAA2B,GAAG,mBAAmB,GAAG;IAC/D,QAAQ,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,wBAAwB,CACvC,MAAM,EAAE,2BAA2B,EACnC,OAAO,EAAE,MAAM,GACb,MAAM,CAMR"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { InvalidFormatPolicy } from '../config/types';
|
|
2
|
+
/**
|
|
3
|
+
* Locale-aware number formatting through the Hermes built-in
|
|
4
|
+
* Intl.NumberFormat. The locale default options apply unless the caller
|
|
5
|
+
* passes explicit overrides (FR-019).
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatNumberValue(value: number, localeCode: string, defaults: Intl.NumberFormatOptions, override: Intl.NumberFormatOptions | undefined, invalidFormat: InvalidFormatPolicy): string;
|
|
8
|
+
//# sourceMappingURL=number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../../src/format/number.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,IAAI,CAAC,mBAAmB,EAClC,QAAQ,EAAE,IAAI,CAAC,mBAAmB,GAAG,SAAS,EAC9C,aAAa,EAAE,mBAAmB,GAChC,MAAM,CAcR"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { InvalidFormatPolicy, UnitId } from '../config/types';
|
|
2
|
+
export declare const SUPPORTED_UNITS: readonly UnitId[];
|
|
3
|
+
export declare const KNOWN_UNIT_IDS: ReadonlySet<string>;
|
|
4
|
+
import { UnitConversionError } from '../config/errors';
|
|
5
|
+
export { UnitConversionError };
|
|
6
|
+
export declare function getUnitSymbol(unit: UnitId): string;
|
|
7
|
+
/**
|
|
8
|
+
* Converts between compatible supported units. Unknown units or conversions
|
|
9
|
+
* across dimensions throw a UnitConversionError (FR-044/FR-045).
|
|
10
|
+
*/
|
|
11
|
+
export declare function convertUnitValue(value: number, from: UnitId, to: UnitId): number;
|
|
12
|
+
export interface UnitFormatOptions extends Intl.NumberFormatOptions {
|
|
13
|
+
/** Unit the value is expressed in. Default: the locale's default unit. */
|
|
14
|
+
from?: UnitId;
|
|
15
|
+
/** Unit to display. Default: `from` (no conversion). */
|
|
16
|
+
to?: UnitId;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Converts (when requested) and formats a measurement value: locale-aware
|
|
20
|
+
* numeric part via Intl.NumberFormat plus the package-owned unit symbol.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatUnitValue(value: number, localeCode: string, localeDefaultUnit: UnitId, numberDefaults: Intl.NumberFormatOptions, options: UnitFormatOptions | undefined, invalidFormat: InvalidFormatPolicy): string;
|
|
23
|
+
//# sourceMappingURL=units.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../../src/format/units.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAiB,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqClF,eAAO,MAAM,eAAe,EAAiC,SAAS,MAAM,EAAE,CAAC;AAE/E,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,CAA4B,CAAC;AAG5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAE/B,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAwBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAuBhF;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,mBAAmB;IAClE,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,EAAE,CAAC,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,IAAI,CAAC,mBAAmB,EACxC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,aAAa,EAAE,mBAAmB,GAChC,MAAM,CAmBR"}
|