@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,23 @@
|
|
|
1
|
+
import type { InvalidFormatPolicy, UnitId } from '../config/types.js';
|
|
2
|
+
export declare const SUPPORTED_UNITS: readonly UnitId[];
|
|
3
|
+
export declare const KNOWN_UNIT_IDS: ReadonlySet<string>;
|
|
4
|
+
import { UnitConversionError } from '../config/errors.js';
|
|
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,oBAAiB,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,qBAAkB,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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ActiveLocalePreference, I18nConfig, LocaleConfig, RuntimeTranslationEntry, TranslateOptions, TranslateVars, UnitId } from './config/types.js';
|
|
2
|
+
import type { UnitFormatOptions } from './format/units.js';
|
|
3
|
+
export interface I18n<TKey extends string = string> {
|
|
4
|
+
/** Resolves the initial locale: persisted → device → primary fallback. */
|
|
5
|
+
init(): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* `init()` without waiting, before the first render (PERF-08). Resolves the locale
|
|
8
|
+
* and returns true when it can do so synchronously: persistence is off, or the
|
|
9
|
+
* storage adapter has `getItemSync`. Returns false, changing nothing, when the
|
|
10
|
+
* adapter can only read asynchronously; call `init()` then.
|
|
11
|
+
*/
|
|
12
|
+
initSync(): boolean;
|
|
13
|
+
t(key: TKey, vars?: TranslateVars, options?: TranslateOptions): string;
|
|
14
|
+
getLocale(): ActiveLocalePreference;
|
|
15
|
+
/** Switches at runtime without restart and persists best-effort. */
|
|
16
|
+
setLocale(code: string): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Forgets the stored choice and follows the device again — the "System
|
|
19
|
+
* language" option a settings screen offers (I18N-17). Resolves to the
|
|
20
|
+
* locale now active.
|
|
21
|
+
*/
|
|
22
|
+
useDeviceLocale(): Promise<ActiveLocalePreference>;
|
|
23
|
+
getSupportedLocales(): readonly LocaleConfig[];
|
|
24
|
+
formatNumber(value: number, options?: Intl.NumberFormatOptions): string;
|
|
25
|
+
/**
|
|
26
|
+
* Options are merged over the locale's default (`{ month: 'long' }` keeps the
|
|
27
|
+
* year and day). `replaceDefaults` uses only what is passed.
|
|
28
|
+
*/
|
|
29
|
+
formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions, formatting?: {
|
|
30
|
+
replaceDefaults?: boolean;
|
|
31
|
+
}): string;
|
|
32
|
+
formatCurrency(value: number, currency?: string, options?: Intl.NumberFormatOptions): string;
|
|
33
|
+
formatUnit(value: number, options?: UnitFormatOptions): string;
|
|
34
|
+
convertUnit(value: number, from: UnitId, to: UnitId): number;
|
|
35
|
+
registerRuntimeEntries(entries: readonly RuntimeTranslationEntry[]): void;
|
|
36
|
+
subscribe(listener: () => void): () => void;
|
|
37
|
+
getVersion(): number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates an I18n instance from an app-owned configuration. Validation runs
|
|
41
|
+
* eagerly and throws an I18nConfigError before any localized content can be
|
|
42
|
+
* served (FR-003). Pass the app's generated key type for typed lookups:
|
|
43
|
+
* `createI18n<AppI18nKey>(config)`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createI18n<TKey extends string = string>(config: I18nConfig): I18n<TKey>;
|
|
46
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../src/i18n.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,sBAAsB,EACtB,UAAU,EAEV,YAAY,EAEZ,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,MAAM,EACN,MAAM,mBAAgB,CAAC;AAkBxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAgB,CAAC;AAExD,MAAM,WAAW,IAAI,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IACjD,0EAA0E;IAC1E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB;;;;;OAKG;IACH,QAAQ,IAAI,OAAO,CAAC;IACpB,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC;IACvE,SAAS,IAAI,sBAAsB,CAAC;IACpC,oEAAoE;IACpE,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC;;;;OAIG;IACH,eAAe,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnD,mBAAmB,IAAI,SAAS,YAAY,EAAE,CAAC;IAC/C,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;IACxE;;;OAGG;IACH,UAAU,CACT,KAAK,EAAE,IAAI,GAAG,MAAM,EACpB,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,EACpC,UAAU,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,OAAO,CAAA;KAAE,GACxC,MAAM,CAAC;IACV,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;IAC7F,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAC/D,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7D,sBAAsB,CAAC,OAAO,EAAE,SAAS,uBAAuB,EAAE,GAAG,IAAI,CAAC;IAC1E,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,UAAU,IAAI,MAAM,CAAC;CACrB;AAKD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,CA0OvF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @chipmobilesdk/rn-i18n — reusable localization for ChipMobileSdk-family
|
|
3
|
+
* React Native apps.
|
|
4
|
+
*
|
|
5
|
+
* This is the single entrypoint, and the package is React Native code only. The
|
|
6
|
+
* Node-only extraction and synchronization tooling is a package of its own,
|
|
7
|
+
* `@chipmobilesdk/rn-i18n-tooling` (the `chip-i18n` CLI): it used to ship inside
|
|
8
|
+
* this tarball as TypeScript source under `./tooling`, which no consumer could
|
|
9
|
+
* execute.
|
|
10
|
+
*/
|
|
11
|
+
export { createI18n } from './i18n.js';
|
|
12
|
+
export type { I18n } from './i18n.js';
|
|
13
|
+
export { I18nConfigError } from './config/types.js';
|
|
14
|
+
export { runtimeEntriesFromCatalog } from './config/catalog.js';
|
|
15
|
+
export { localeStorageFromKeyValue } from './locale/keyValueStorage.js';
|
|
16
|
+
export type { I18nErrorCode } from './config/errors.js';
|
|
17
|
+
export type { I18nDiagnostic, I18nDiagnosticCode, I18nDiagnosticHandler, } from './config/diagnostics.js';
|
|
18
|
+
export type { ActiveLocalePreference, DeviceLocaleProvider, I18nConfig, InvalidFormatPolicy, LocaleConfig, LocaleDirection, LocaleSelectionSource, LocaleStorageAdapter, MissingTranslationPolicy, PluralCategory, PluralRule, RuntimeTranslationEntry, TranslateOptions, TranslateVars, TranslationNamespace, TranslationNode, TranslationResources, UnitDimension, UnitId, } from './config/types.js';
|
|
19
|
+
export { LOCALE_STORAGE_KEY } from './locale/persistence.js';
|
|
20
|
+
export { defaultDeviceLocaleProvider } from './locale/deviceLocale.js';
|
|
21
|
+
export { SUPPORTED_UNITS, UnitConversionError, convertUnitValue as convertUnit, getUnitSymbol, } from './format/units.js';
|
|
22
|
+
export type { UnitFormatOptions } from './format/units.js';
|
|
23
|
+
export { I18nProvider } from './react/I18nProvider.js';
|
|
24
|
+
export type { I18nProviderProps } from './react/I18nProvider.js';
|
|
25
|
+
export { useLocale, useTranslation } from './react/hooks.js';
|
|
26
|
+
export type { UseLocaleResult, UseTranslationResult } from './react/hooks.js';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAQ,CAAC;AACpC,YAAY,EAAE,IAAI,EAAE,MAAM,WAAQ,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAgB,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAkB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA0B,CAAC;AACrE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAiB,CAAC;AACrD,YAAY,EACX,cAAc,EACd,kBAAkB,EAClB,qBAAqB,GACrB,MAAM,yBAAsB,CAAC;AAC9B,YAAY,EACX,sBAAsB,EACtB,oBAAoB,EACpB,UAAU,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,cAAc,EACd,UAAU,EACV,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,MAAM,GACN,MAAM,mBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAAuB,CAAC;AAEpE,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,gBAAgB,IAAI,WAAW,EAC/B,aAAa,GACb,MAAM,mBAAgB,CAAC;AACxB,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAgB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAsB,CAAC;AACpD,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAsB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,kBAAe,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,kBAAe,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type I18nDiagnosticHandler } from '../config/diagnostics.js';
|
|
2
|
+
import type { ActiveLocalePreference } from '../config/types.js';
|
|
3
|
+
export interface ActiveLocaleStore {
|
|
4
|
+
get(): ActiveLocalePreference;
|
|
5
|
+
set(preference: ActiveLocalePreference): void;
|
|
6
|
+
subscribe(listener: () => void): () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Notifies subscribers without changing the locale: what reaches the screen
|
|
9
|
+
* changed, not which language it is in (a runtime entry registered by a
|
|
10
|
+
* lazily loaded feature, say).
|
|
11
|
+
*/
|
|
12
|
+
bump(): void;
|
|
13
|
+
/** Monotonic change counter consumed by useSyncExternalStore. */
|
|
14
|
+
getVersion(): number;
|
|
15
|
+
}
|
|
16
|
+
export declare function createActiveLocaleStore(initial: ActiveLocalePreference, report?: I18nDiagnosticHandler): ActiveLocaleStore;
|
|
17
|
+
//# sourceMappingURL=activeLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activeLocale.d.ts","sourceRoot":"","sources":["../../../../src/locale/activeLocale.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkC,KAAK,qBAAqB,EAAE,MAAM,0BAAuB,CAAC;AACnG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAiB,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IACjC,GAAG,IAAI,sBAAsB,CAAC;IAC9B,GAAG,CAAC,UAAU,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC9C,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C;;;;OAIG;IACH,IAAI,IAAI,IAAI,CAAC;IACb,iEAAiE;IACjE,UAAU,IAAI,MAAM,CAAC;CACrB;AAED,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,sBAAsB,EAC/B,MAAM,GAAE,qBAAuC,GAC7C,iBAAiB,CA6BnB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DeviceLocaleProvider, LocaleConfig, LocaleSelectionSource } from '../config/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default device locale detection. Hermes resolves the Intl default locale
|
|
4
|
+
* from the device locale on both Android and iOS, so no native module is
|
|
5
|
+
* required. Apps may inject their own provider (e.g. react-native-localize)
|
|
6
|
+
* through `I18nConfig.deviceLocale`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const defaultDeviceLocaleProvider: DeviceLocaleProvider;
|
|
9
|
+
export interface DeviceLocaleMatch {
|
|
10
|
+
code: string;
|
|
11
|
+
source: Extract<LocaleSelectionSource, 'device' | 'languageMatch'>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Matches a detected device locale against the supported locales: an exact
|
|
15
|
+
* (case-insensitive) match wins; otherwise a device language that matches
|
|
16
|
+
* exactly one supported locale selects that locale (US4 scenario 3).
|
|
17
|
+
*/
|
|
18
|
+
export declare function matchSupportedLocale(deviceLocale: string | undefined, locales: readonly LocaleConfig[]): DeviceLocaleMatch | undefined;
|
|
19
|
+
//# sourceMappingURL=deviceLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceLocale.d.ts","sourceRoot":"","sources":["../../../../src/locale/deviceLocale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAiB,CAAC;AAEjG;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,oBAMzC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC,qBAAqB,EAAE,QAAQ,GAAG,eAAe,CAAC,CAAC;CACnE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,OAAO,EAAE,SAAS,YAAY,EAAE,GAC9B,iBAAiB,GAAG,SAAS,CAoB/B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `LocaleStorageAdapter` over rn-core's synchronous `KeyValuePort` (PERF-08).
|
|
3
|
+
*
|
|
4
|
+
* The adapter carries `getItemSync`, so `i18n.initSync()` resolves the persisted
|
|
5
|
+
* locale before the first render. Open the port the way the app opens its other
|
|
6
|
+
* durable state, for example `openDurable(() => createMMKV({ id: 'app' }))`.
|
|
7
|
+
*/
|
|
8
|
+
import type { KeyValuePort } from '@chipmobilesdk/rn-core';
|
|
9
|
+
import type { LocaleStorageAdapter } from '../config/types.js';
|
|
10
|
+
export declare function localeStorageFromKeyValue(port: KeyValuePort): LocaleStorageAdapter & {
|
|
11
|
+
getItemSync(key: string): string | null;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=keyValueStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyValueStorage.d.ts","sourceRoot":"","sources":["../../../../src/locale/keyValueStorage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAiB,CAAC;AAE5D,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,YAAY,GAChB,oBAAoB,GAAG;IAAE,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,CAapE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type I18nDiagnosticHandler } from '../config/diagnostics.js';
|
|
2
|
+
import type { LocaleStorageAdapter } from '../config/types.js';
|
|
3
|
+
export declare const LOCALE_STORAGE_KEY = "@chipmobilesdk/rn-i18n:locale";
|
|
4
|
+
/**
|
|
5
|
+
* Reads the persisted locale preference. Adapter failures are reported and
|
|
6
|
+
* treated as "no persisted value" so locale selection never crashes (FR-015).
|
|
7
|
+
*/
|
|
8
|
+
export declare function readPersistedLocale(storage: LocaleStorageAdapter, report?: I18nDiagnosticHandler): Promise<string | null>;
|
|
9
|
+
/** `readPersistedLocale` for a store with a synchronous read; same failure handling. */
|
|
10
|
+
export declare function readPersistedLocaleSync(storage: LocaleStorageAdapter & {
|
|
11
|
+
getItemSync(key: string): string | null;
|
|
12
|
+
}, report?: I18nDiagnosticHandler): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Persists the selected locale. Persistence is best-effort: a write failure
|
|
15
|
+
* is reported but the in-memory locale switch stays authoritative.
|
|
16
|
+
*/
|
|
17
|
+
export declare function writePersistedLocale(storage: LocaleStorageAdapter, code: string, report?: I18nDiagnosticHandler): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Forgets the stored choice, so the next launch follows the device again. The
|
|
20
|
+
* adapter's `removeItem` was required by the contract and called by nothing
|
|
21
|
+
* until `useDeviceLocale()` (I18N-17). Best-effort, like the write.
|
|
22
|
+
*/
|
|
23
|
+
export declare function clearPersistedLocale(storage: LocaleStorageAdapter, report?: I18nDiagnosticHandler): Promise<void>;
|
|
24
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../../src/locale/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,qBAAqB,EAAE,MAAM,0BAAuB,CAAC;AACnG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAiB,CAAC;AAE5D,eAAO,MAAM,kBAAkB,kCAAkC,CAAC;AAElE;;;GAGG;AACH,wBAAsB,mBAAmB,CACxC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,GAAE,qBAAuC,GAC7C,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAUxB;AAED,wFAAwF;AACxF,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,oBAAoB,GAAG;IAAE,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,EAC3E,MAAM,GAAE,qBAAuC,GAC7C,MAAM,GAAG,IAAI,CAUf;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,oBAAoB,EAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,qBAAuC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,GAAE,qBAAuC,GAC7C,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { I18n } from '../i18n.js';
|
|
4
|
+
export declare const I18nContext: React.Context<I18n<string> | null>;
|
|
5
|
+
export interface I18nProviderProps {
|
|
6
|
+
i18n: I18n<never>;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Provides the I18n instance to the React tree. Locale changes re-render
|
|
11
|
+
* consumers through the hooks' useSyncExternalStore subscription, so a
|
|
12
|
+
* runtime switch updates UI within one interaction cycle (PERF-002).
|
|
13
|
+
*/
|
|
14
|
+
export declare function I18nProvider({ i18n, children }: I18nProviderProps): React.JSX.Element;
|
|
15
|
+
export declare function useI18nContext(): I18n<string>;
|
|
16
|
+
//# sourceMappingURL=I18nProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18nProvider.d.ts","sourceRoot":"","sources":["../../../../src/react/I18nProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAS,CAAC;AAIpC,eAAO,MAAM,WAAW,oCAA2C,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,iBAAiB,qBAIjE;AAED,wBAAgB,cAAc,IAAI,IAAI,CAAC,MAAM,CAAC,CAM7C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ActiveLocalePreference, LocaleConfig, LocaleDirection, TranslateOptions, TranslateVars } from '../config/types.js';
|
|
2
|
+
export interface UseTranslationResult<TKey extends string> {
|
|
3
|
+
t: (key: TKey, vars?: TranslateVars, options?: TranslateOptions) => string;
|
|
4
|
+
locale: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Returns the translation function bound to the active locale. Pass the
|
|
8
|
+
* app's generated key type for compile-time key validation (FR-041):
|
|
9
|
+
* `const { t } = useTranslation<AppI18nKey>();`
|
|
10
|
+
*/
|
|
11
|
+
export declare function useTranslation<TKey extends string = string>(): UseTranslationResult<TKey>;
|
|
12
|
+
export interface UseLocaleResult {
|
|
13
|
+
locale: string;
|
|
14
|
+
direction: LocaleDirection;
|
|
15
|
+
preference: ActiveLocalePreference;
|
|
16
|
+
supportedLocales: readonly LocaleConfig[];
|
|
17
|
+
setLocale: (code: string) => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/** Returns active locale state, direction metadata, and the locale switcher. */
|
|
20
|
+
export declare function useLocale(): UseLocaleResult;
|
|
21
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,MAAM,oBAAiB,CAAC;AAQzB,MAAM,WAAW,oBAAoB,CAAC,IAAI,SAAS,MAAM;IACxD,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,MAAM,CAAC;IAC3E,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,KAAK,oBAAoB,CAAC,IAAI,CAAC,CAezF;AAED,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;IAC3B,UAAU,EAAE,sBAAsB,CAAC;IACnC,gBAAgB,EAAE,SAAS,YAAY,EAAE,CAAC;IAC1C,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED,gFAAgF;AAChF,wBAAgB,SAAS,IAAI,eAAe,CAc3C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TranslateVars } from '../config/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Replaces `{{name}}` placeholders with named values. Missing variables keep
|
|
4
|
+
* their placeholder text so the result stays deterministic, and each missing
|
|
5
|
+
* name is reported through `onMissingVariable`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function interpolate(text: string, vars?: TranslateVars, onMissingVariable?: (name: string) => void): string;
|
|
8
|
+
//# sourceMappingURL=interpolate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../../../src/translation/interpolate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAiB,CAAC;AAIrD;;;;GAIG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,aAAa,EACpB,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GACxC,MAAM,CASR"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LocaleConfig, PluralCategory, PluralRule, TranslationNode } from '../config/types.js';
|
|
2
|
+
export declare const PLURAL_CATEGORIES: readonly PluralCategory[];
|
|
3
|
+
export declare const DEFAULT_PLURAL_RULE: PluralRule;
|
|
4
|
+
/** True when this package has a rule for the language, or the locale brought one. */
|
|
5
|
+
export declare function hasPluralRule(locale: LocaleConfig): boolean;
|
|
6
|
+
export declare function resolvePluralRule(locale: LocaleConfig): PluralRule;
|
|
7
|
+
/**
|
|
8
|
+
* A plural group is an object whose keys are all plural categories, whose
|
|
9
|
+
* values are all strings, and which provides the required `other` variant.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isPluralGroup(node: TranslationNode): node is Record<string, string>;
|
|
12
|
+
export declare function selectPluralVariant(group: Record<string, string>, category: PluralCategory): string;
|
|
13
|
+
//# sourceMappingURL=plurals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plurals.d.ts","sourceRoot":"","sources":["../../../../src/translation/plurals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAiB,CAAC;AAEjG,eAAO,MAAM,iBAAiB,EAAE,SAAS,cAAc,EAOtD,CAAC;AA8EF,eAAO,MAAM,mBAAmB,EAAE,UAAyB,CAAC;AAE5D,qFAAqF;AACrF,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAM3D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAMlE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAanF;AAED,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,QAAQ,EAAE,cAAc,GACtB,MAAM,CAER"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { I18nDiagnostic, I18nDiagnosticHandler } from '../config/diagnostics.js';
|
|
2
|
+
import type { LocaleConfig, MissingTranslationPolicy, TranslateOptions, TranslateVars, TranslationNamespace, TranslationNode, TranslationResources } from '../config/types.js';
|
|
3
|
+
import type { RuntimeEntryRegistry } from './runtimeKeys.js';
|
|
4
|
+
export interface ResolverContext {
|
|
5
|
+
localesByCode: ReadonlyMap<string, LocaleConfig>;
|
|
6
|
+
resources: TranslationResources;
|
|
7
|
+
runtimeEntries: RuntimeEntryRegistry;
|
|
8
|
+
missingTranslation: MissingTranslationPolicy;
|
|
9
|
+
/** Dedupe set so each failed lookup path warns exactly once. */
|
|
10
|
+
warned: Set<string>;
|
|
11
|
+
report: I18nDiagnosticHandler;
|
|
12
|
+
}
|
|
13
|
+
export declare function warnOnce(context: Pick<ResolverContext, 'warned' | 'report'>, dedupeKey: string, diagnostic: I18nDiagnostic): void;
|
|
14
|
+
/** Walks a dot-path key through a nested translation namespace. */
|
|
15
|
+
export declare function getTranslationNode(namespace: TranslationNamespace | undefined, key: string): TranslationNode | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves a key through the active locale, its ordered fallback chain, and
|
|
18
|
+
* declared runtime-only default text, applying plural selection and named
|
|
19
|
+
* variable interpolation. Misses are reported with one console warning per
|
|
20
|
+
* lookup path; a full-chain miss applies the configured missing-translation
|
|
21
|
+
* policy (FR-008…FR-011, FR-033).
|
|
22
|
+
*/
|
|
23
|
+
export declare function translate(context: ResolverContext, activeCode: string, key: string, vars?: TranslateVars, options?: TranslateOptions): string;
|
|
24
|
+
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../../src/translation/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,0BAAuB,CAAC;AACnF,OAAO,KAAK,EACX,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,MAAM,oBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAe,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC/B,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,SAAS,EAAE,oBAAoB,CAAC;IAChC,cAAc,EAAE,oBAAoB,CAAC;IACrC,kBAAkB,EAAE,wBAAwB,CAAC;IAC7C,gEAAgE;IAChE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACpB,MAAM,EAAE,qBAAqB,CAAC;CAC9B;AAQD,wBAAgB,QAAQ,CACvB,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,QAAQ,CAAC,EACnD,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,cAAc,GACxB,IAAI,CAWN;AAED,mEAAmE;AACnE,wBAAgB,kBAAkB,CACjC,SAAS,EAAE,oBAAoB,GAAG,SAAS,EAC3C,GAAG,EAAE,MAAM,GACT,eAAe,GAAG,SAAS,CAgB7B;AA4BD;;;;;;GAMG;AACH,wBAAgB,SAAS,CACxB,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,aAAa,EACpB,OAAO,CAAC,EAAE,gBAAgB,GACxB,MAAM,CAoDR"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type RuntimeTranslationEntry } from '../config/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Registry of declared runtime-only translation entries. Entries participate
|
|
4
|
+
* in the same lookup pipeline as scanned template keys and are protected from
|
|
5
|
+
* removal during locale JSON synchronization.
|
|
6
|
+
*/
|
|
7
|
+
export type RuntimeEntryRegistry = Map<string, RuntimeTranslationEntry>;
|
|
8
|
+
export declare function createRuntimeRegistry(entries?: readonly RuntimeTranslationEntry[]): RuntimeEntryRegistry;
|
|
9
|
+
/**
|
|
10
|
+
* The same checks the configured entries get (I18N-06): an entry registered at
|
|
11
|
+
* runtime by a lazily loaded feature used to be written in unvalidated, so a
|
|
12
|
+
* missing key or a non-string default surfaced only when a screen rendered it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateRuntimeEntries(entries: readonly RuntimeTranslationEntry[]): void;
|
|
15
|
+
export declare function registerRuntimeEntries(registry: RuntimeEntryRegistry, entries: readonly RuntimeTranslationEntry[]): void;
|
|
16
|
+
//# sourceMappingURL=runtimeKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeKeys.d.ts","sourceRoot":"","sources":["../../../../src/translation/runtimeKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,uBAAuB,EAAE,MAAM,oBAAiB,CAAC;AAEhF;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;AAExE,wBAAgB,qBAAqB,CACpC,OAAO,CAAC,EAAE,SAAS,uBAAuB,EAAE,GAC1C,oBAAoB,CAMtB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,SAAS,uBAAuB,EAAE,GAAG,IAAI,CAmBxF;AAED,wBAAgB,sBAAsB,CACrC,QAAQ,EAAE,oBAAoB,EAC9B,OAAO,EAAE,SAAS,uBAAuB,EAAE,GACzC,IAAI,CAKN"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chipmobilesdk/rn-i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"source": "./src/index.ts",
|
|
7
|
+
"main": "./lib/commonjs/index.js",
|
|
8
|
+
"module": "./lib/module/index.js",
|
|
9
|
+
"types": "./lib/typescript/commonjs/index.d.ts",
|
|
8
10
|
"exports": {
|
|
9
11
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
"chipmobilesdk-source": "./src/index.ts",
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./lib/typescript/module/index.d.ts",
|
|
15
|
+
"default": "./lib/module/index.js"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./lib/typescript/commonjs/index.d.ts",
|
|
19
|
+
"default": "./lib/commonjs/index.js"
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
22
|
},
|
|
20
23
|
"files": [
|
|
@@ -25,25 +28,45 @@
|
|
|
25
28
|
"src/locale",
|
|
26
29
|
"src/format",
|
|
27
30
|
"src/react",
|
|
28
|
-
"src/tooling",
|
|
29
31
|
"skills",
|
|
30
32
|
"README.md",
|
|
31
|
-
"CHANGELOG.md"
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"lib"
|
|
32
35
|
],
|
|
33
36
|
"sideEffects": false,
|
|
34
37
|
"scripts": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
38
|
+
"build": "bob build",
|
|
39
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json",
|
|
40
|
+
"pack:check": "npm pack --dry-run",
|
|
41
|
+
"prepack": "npm run build"
|
|
37
42
|
},
|
|
38
43
|
"dependencies": {
|
|
39
|
-
"@chipmobilesdk/rn-core": "^0.
|
|
44
|
+
"@chipmobilesdk/rn-core": "^0.2.0"
|
|
40
45
|
},
|
|
41
46
|
"peerDependencies": {
|
|
42
|
-
"react": ">=19"
|
|
43
|
-
"react-native": ">=0.85"
|
|
47
|
+
"react": ">=19"
|
|
44
48
|
},
|
|
45
49
|
"publishConfig": {
|
|
46
50
|
"access": "public",
|
|
47
51
|
"registry": "https://registry.npmjs.org/"
|
|
52
|
+
},
|
|
53
|
+
"react-native-builder-bob": {
|
|
54
|
+
"source": "src",
|
|
55
|
+
"output": "lib",
|
|
56
|
+
"targets": [
|
|
57
|
+
[
|
|
58
|
+
"commonjs",
|
|
59
|
+
{
|
|
60
|
+
"esm": true
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
"module",
|
|
65
|
+
{
|
|
66
|
+
"esm": true
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"typescript"
|
|
70
|
+
]
|
|
48
71
|
}
|
|
49
72
|
}
|
|
@@ -46,9 +46,36 @@ Runtime:
|
|
|
46
46
|
- `I18nConfigError` — thrown on invalid configuration at startup; an rn-core SDK error with an
|
|
47
47
|
`I18nErrorCode`
|
|
48
48
|
|
|
49
|
+
Formatting, on the instance (all locale-aware, all through Hermes's Intl):
|
|
50
|
+
|
|
51
|
+
- `i18n.formatNumber(value, options?)`, `i18n.formatCurrency(value, currency?, options?)`,
|
|
52
|
+
`i18n.formatUnit(value, options?)` — options merge over the locale's defaults
|
|
53
|
+
- `i18n.formatDate(value, options?, { replaceDefaults? })` — options merge too;
|
|
54
|
+
`replaceDefaults: true` uses only what is passed
|
|
55
|
+
- `i18n.convertUnit(value, from, to)`, `SUPPORTED_UNITS`, `UnitConversionError`
|
|
56
|
+
|
|
57
|
+
Locale, on the instance: `init()` (idempotent), `initSync()`, `setLocale(code)`,
|
|
58
|
+
`useDeviceLocale()` (forget the stored choice and follow the device again),
|
|
59
|
+
`getLocale()`, `getSupportedLocales()`, `registerRuntimeEntries(entries)`,
|
|
60
|
+
`subscribe(listener)`, `getVersion()`
|
|
61
|
+
|
|
49
62
|
Types: `I18n`, `UnitFormatOptions`, `I18nProviderProps`, `UseLocaleResult`,
|
|
50
63
|
`UseTranslationResult`
|
|
51
64
|
|
|
65
|
+
## Plural rules are declared, not inferred
|
|
66
|
+
|
|
67
|
+
Hermes has no `Intl.PluralRules`, so this package carries a compact CLDR subset
|
|
68
|
+
(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). A
|
|
69
|
+
language outside it falls back to "1 is singular" **and reports a
|
|
70
|
+
`plural_rule_default` diagnostic** — declare `pluralRule` on the locale rather than
|
|
71
|
+
shipping wrong plurals.
|
|
72
|
+
|
|
73
|
+
## Entries registered at runtime re-render
|
|
74
|
+
|
|
75
|
+
`registerRuntimeEntries` notifies subscribers, so a lazily loaded feature's copy appears
|
|
76
|
+
without another render pass, and a malformed entry throws `I18nConfigError` there and then
|
|
77
|
+
instead of rendering the key.
|
|
78
|
+
|
|
52
79
|
`I18nConfigError` throws at startup by design — a misconfigured i18n setup should fail
|
|
53
80
|
loudly, not silently render keys.
|
|
54
81
|
|
|
@@ -12,6 +12,7 @@ export type I18nDiagnosticCode =
|
|
|
12
12
|
| 'invalid_value'
|
|
13
13
|
| 'invalid_format'
|
|
14
14
|
| 'locale_unsupported'
|
|
15
|
+
| 'plural_rule_default'
|
|
15
16
|
| 'locale_read_failed'
|
|
16
17
|
| 'locale_write_failed'
|
|
17
18
|
| 'listener_threw';
|
|
@@ -33,6 +34,7 @@ const SEVERITY: Record<I18nDiagnosticCode, DiagnosticSeverity> = {
|
|
|
33
34
|
invalid_value: 'warn',
|
|
34
35
|
invalid_format: 'warn',
|
|
35
36
|
locale_unsupported: 'warn',
|
|
37
|
+
plural_rule_default: 'warn',
|
|
36
38
|
locale_read_failed: 'warn',
|
|
37
39
|
locale_write_failed: 'warn',
|
|
38
40
|
listener_threw: 'error',
|
package/src/format/currency.ts
CHANGED
|
@@ -5,6 +5,11 @@ import { applyInvalidFormatPolicy } from './invalid';
|
|
|
5
5
|
/**
|
|
6
6
|
* Locale-aware currency formatting. The locale's configured default currency
|
|
7
7
|
* applies unless the caller passes an explicit currency override (FR-021).
|
|
8
|
+
*
|
|
9
|
+
* `locale.defaultNumberFormat` is deliberately **not** applied here: a currency
|
|
10
|
+
* carries its own minor units (yen has none, dinar has three), and the locale's
|
|
11
|
+
* generic number options would override them — ¥1,234.56 instead of ¥1,235.
|
|
12
|
+
* Pass the options you want for a currency explicitly (I18N-09).
|
|
8
13
|
*/
|
|
9
14
|
export function formatCurrencyValue(
|
|
10
15
|
value: number,
|
package/src/format/date.ts
CHANGED
|
@@ -4,9 +4,14 @@ import { applyInvalidFormatPolicy } from './invalid';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Locale-aware date formatting through the Hermes built-in
|
|
7
|
-
* Intl.DateTimeFormat.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Intl.DateTimeFormat.
|
|
8
|
+
*
|
|
9
|
+
* Options are **merged** over the locale's configured default, the way
|
|
10
|
+
* `formatNumber` has always worked: `{ month: 'long' }` changes the month and
|
|
11
|
+
* keeps the year and day. Replacing the default wholesale, which this used to
|
|
12
|
+
* do, meant one option silently dropped every other component — and the two
|
|
13
|
+
* formatters disagreed about what an option meant (I18N-09). Pass
|
|
14
|
+
* `{ replaceDefaults: true }` for the old behaviour.
|
|
10
15
|
*/
|
|
11
16
|
export function formatDateValue(
|
|
12
17
|
value: Date | number,
|
|
@@ -14,6 +19,7 @@ export function formatDateValue(
|
|
|
14
19
|
defaults: Intl.DateTimeFormatOptions,
|
|
15
20
|
override: Intl.DateTimeFormatOptions | undefined,
|
|
16
21
|
invalidFormat: InvalidFormatPolicy,
|
|
22
|
+
replaceDefaults = false,
|
|
17
23
|
): string {
|
|
18
24
|
const date = value instanceof Date ? value : new Date(value);
|
|
19
25
|
if (Number.isNaN(date.getTime())) {
|
|
@@ -22,7 +28,7 @@ export function formatDateValue(
|
|
|
22
28
|
`Cannot format invalid date value "${String(value)}" for locale "${localeCode}".`,
|
|
23
29
|
);
|
|
24
30
|
}
|
|
25
|
-
const options = override ?? defaults;
|
|
31
|
+
const options = replaceDefaults ? (override ?? defaults) : { ...defaults, ...override };
|
|
26
32
|
// rn-core's cached formatter (I18N-03); a bad option is a format problem (I18N-08).
|
|
27
33
|
try {
|
|
28
34
|
return getDateTimeFormat(localeCode, options).format(date);
|