@chipmobilesdk/rn-i18n 0.3.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 +157 -0
- package/README.md +28 -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/src/index.ts +5 -3
- package/src/tooling/cli.ts +0 -76
- package/src/tooling/generateKeys.ts +0 -65
- 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
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* @chipmobilesdk/rn-i18n — reusable localization for ChipMobileSdk-family
|
|
3
3
|
* React Native apps.
|
|
4
4
|
*
|
|
5
|
-
* This is the single React Native
|
|
6
|
-
* synchronization tooling is
|
|
7
|
-
* `@chipmobilesdk/rn-i18n
|
|
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.
|
|
8
10
|
*/
|
|
9
11
|
|
|
10
12
|
export { createI18n } from './i18n';
|
package/src/tooling/cli.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extraction/synchronization CLI. Node-only; run through the root npm
|
|
3
|
-
* script under Node >= 22.11 with TypeScript type stripping:
|
|
4
|
-
*
|
|
5
|
-
* npm run i18n:sync
|
|
6
|
-
* node --experimental-strip-types packages/rn-i18n/src/tooling/cli.ts --config i18n-sync.config.json
|
|
7
|
-
*
|
|
8
|
-
* Exit codes: 0 success or warnings, 1 blocking findings (conflicts or
|
|
9
|
-
* malformed locale files), 2 invalid configuration or internal error.
|
|
10
|
-
*/
|
|
11
|
-
import fs from 'node:fs';
|
|
12
|
-
import path from 'node:path';
|
|
13
|
-
import process from 'node:process';
|
|
14
|
-
import { renderReport } from './report.ts';
|
|
15
|
-
import { SyncConfigError, runSync } from './runner.ts';
|
|
16
|
-
import type { SyncConfig } from './types.ts';
|
|
17
|
-
|
|
18
|
-
function parseArgs(argv: readonly string[]): { configPath: string } {
|
|
19
|
-
let configPath = 'i18n-sync.config.json';
|
|
20
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
21
|
-
if (argv[index] === '--config' && argv[index + 1]) {
|
|
22
|
-
configPath = argv[index + 1];
|
|
23
|
-
index += 1;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return { configPath };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function main(): Promise<number> {
|
|
30
|
-
const rootDir = process.cwd();
|
|
31
|
-
const { configPath } = parseArgs(process.argv.slice(2));
|
|
32
|
-
const absoluteConfigPath = path.resolve(rootDir, configPath);
|
|
33
|
-
|
|
34
|
-
if (!fs.existsSync(absoluteConfigPath)) {
|
|
35
|
-
console.error(`[rn-i18n] Sync configuration not found: ${configPath}`);
|
|
36
|
-
return 2;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let config: SyncConfig;
|
|
40
|
-
try {
|
|
41
|
-
config = JSON.parse(fs.readFileSync(absoluteConfigPath, 'utf8')) as SyncConfig;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error(`[rn-i18n] Sync configuration is not valid JSON: ${String(error)}`);
|
|
44
|
-
return 2;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
const { report, generatedKeysChanged } = await runSync(rootDir, config);
|
|
49
|
-
console.log(renderReport(report));
|
|
50
|
-
if (config.generateKeysFile) {
|
|
51
|
-
console.log(
|
|
52
|
-
generatedKeysChanged
|
|
53
|
-
? `Typed keys regenerated: ${config.generateKeysFile}`
|
|
54
|
-
: `Typed keys unchanged: ${config.generateKeysFile}`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
return report.outcome === 'failed' ? 1 : 0;
|
|
58
|
-
} catch (error) {
|
|
59
|
-
if (error instanceof SyncConfigError) {
|
|
60
|
-
console.error(`[rn-i18n] ${error.message}`);
|
|
61
|
-
} else {
|
|
62
|
-
console.error(`[rn-i18n] Sync failed: ${String(error)}`);
|
|
63
|
-
}
|
|
64
|
-
return 2;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
main().then(
|
|
69
|
-
code => {
|
|
70
|
-
process.exitCode = code;
|
|
71
|
-
},
|
|
72
|
-
error => {
|
|
73
|
-
console.error(`[rn-i18n] Unexpected failure: ${String(error)}`);
|
|
74
|
-
process.exitCode = 2;
|
|
75
|
-
},
|
|
76
|
-
);
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import type { RuntimeEntryConfig, TranslationTemplate } from './types.ts';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Renders the typed key contract: the union of scanned template keys and
|
|
7
|
-
* declared runtime-only keys (FR-041). Apps bind lookups to the generated
|
|
8
|
-
* type so `tsc --noEmit` reports invalid or stale key usage before release.
|
|
9
|
-
*/
|
|
10
|
-
export function renderKeysModule(
|
|
11
|
-
template: TranslationTemplate,
|
|
12
|
-
runtimeEntries: readonly RuntimeEntryConfig[],
|
|
13
|
-
typeName = 'AppI18nKey',
|
|
14
|
-
): string {
|
|
15
|
-
const templateKeys = template.keys.map(key => key.key).sort((a, b) => a.localeCompare(b, 'en'));
|
|
16
|
-
const runtimeKeys = runtimeEntries
|
|
17
|
-
.map(entry => entry.key)
|
|
18
|
-
.sort((a, b) => a.localeCompare(b, 'en'));
|
|
19
|
-
|
|
20
|
-
// Escaped, not interpolated: a key holding an apostrophe or a backslash wrote
|
|
21
|
-
// a file that did not parse, and `tsc` then failed for the whole app (I18N-20).
|
|
22
|
-
const literal = (key: string) => `'${key.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
|
|
23
|
-
const renderList = (keys: readonly string[]) =>
|
|
24
|
-
keys.length === 0 ? '[]' : `[\n${keys.map(key => `\t${literal(key)},`).join('\n')}\n]`;
|
|
25
|
-
|
|
26
|
-
return [
|
|
27
|
-
'// AUTO-GENERATED by @chipmobilesdk/rn-i18n tooling. Do not edit by hand.',
|
|
28
|
-
'// Regenerate with: npm run i18n:sync',
|
|
29
|
-
'',
|
|
30
|
-
`export const I18N_TEMPLATE_KEYS = ${renderList(templateKeys)} as const;`,
|
|
31
|
-
'',
|
|
32
|
-
`export const I18N_RUNTIME_ONLY_KEYS = ${renderList(runtimeKeys)} as const;`,
|
|
33
|
-
'',
|
|
34
|
-
'export const I18N_KEYS = [',
|
|
35
|
-
'\t...I18N_TEMPLATE_KEYS,',
|
|
36
|
-
'\t...I18N_RUNTIME_ONLY_KEYS,',
|
|
37
|
-
'] as const;',
|
|
38
|
-
'',
|
|
39
|
-
`export type ${typeName} = (typeof I18N_KEYS)[number];`,
|
|
40
|
-
'',
|
|
41
|
-
].join('\n');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface GenerateKeysResult {
|
|
45
|
-
filePath: string;
|
|
46
|
-
changed: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Writes the typed key artifact and reports whether it changed (staleness). */
|
|
50
|
-
export function generateKeysFile(
|
|
51
|
-
rootDir: string,
|
|
52
|
-
relativePath: string,
|
|
53
|
-
template: TranslationTemplate,
|
|
54
|
-
runtimeEntries: readonly RuntimeEntryConfig[],
|
|
55
|
-
typeName?: string,
|
|
56
|
-
): GenerateKeysResult {
|
|
57
|
-
const filePath = path.join(rootDir, relativePath);
|
|
58
|
-
const content = renderKeysModule(template, runtimeEntries, typeName);
|
|
59
|
-
const previous = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : undefined;
|
|
60
|
-
if (previous !== content) {
|
|
61
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
62
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
63
|
-
}
|
|
64
|
-
return { filePath, changed: previous !== content };
|
|
65
|
-
}
|
package/src/tooling/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Programmatic surface of the Node-only extraction and synchronization
|
|
3
|
-
* tooling, exposed as `@chipmobilesdk/rn-i18n/tooling`. This entrypoint must
|
|
4
|
-
* never be imported from React Native code; the runtime API lives at the
|
|
5
|
-
* package root (LIB-003).
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export { globToRegExp, listSourceFiles, scanSource } from './scan.ts';
|
|
9
|
-
export { flattenTranslations, nestTranslations, syncLocaleFiles } from './sync.ts';
|
|
10
|
-
export { buildReport, renderReport } from './report.ts';
|
|
11
|
-
export { generateKeysFile, renderKeysModule } from './generateKeys.ts';
|
|
12
|
-
export type { GenerateKeysResult } from './generateKeys.ts';
|
|
13
|
-
export { SyncConfigError, loadRuntimeEntries, runSync, validateSyncConfig } from './runner.ts';
|
|
14
|
-
export type { SyncRunResult } from './runner.ts';
|
|
15
|
-
export type {
|
|
16
|
-
AmbiguousUsage,
|
|
17
|
-
ExtractionReport,
|
|
18
|
-
KeyConflict,
|
|
19
|
-
LocaleSyncResult,
|
|
20
|
-
PatternConfig,
|
|
21
|
-
ReportOutcome,
|
|
22
|
-
RuntimeEntryConfig,
|
|
23
|
-
SourceLocation,
|
|
24
|
-
SyncConfig,
|
|
25
|
-
TemplateKey,
|
|
26
|
-
TranslationTemplate,
|
|
27
|
-
} from './types.ts';
|