@flare-engine/localization 0.4.6 → 0.4.7
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/dist/index.d.mts +6 -18
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +6 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Signal } from "@flare-engine/events";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* String table → `{ key: message }` per locale.
|
|
5
4
|
*
|
|
@@ -12,8 +11,6 @@ type LocaleCode = string;
|
|
|
12
11
|
type MessageValue = string | number;
|
|
13
12
|
type MessageValues = Record<string, MessageValue>;
|
|
14
13
|
type StringTable = Record<string, string>;
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/format.d.ts
|
|
17
14
|
/**
|
|
18
15
|
* Minimal ICU MessageFormat-ish parser.
|
|
19
16
|
*
|
|
@@ -26,9 +23,7 @@ type StringTable = Record<string, string>;
|
|
|
26
23
|
*
|
|
27
24
|
* Nested plural blocks are not supported (not needed for our tables).
|
|
28
25
|
*/
|
|
29
|
-
declare function formatMessage(template: string, values: MessageValues | undefined, locale: LocaleCode): string;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/format-timestamp.d.ts
|
|
26
|
+
export declare function formatMessage(template: string, values: MessageValues | undefined, locale: LocaleCode): string;
|
|
32
27
|
interface FormatTimestampOptions {
|
|
33
28
|
/** Intl.DateTimeFormat date style. Defaults to 'short'. */
|
|
34
29
|
dateStyle?: 'full' | 'long' | 'medium' | 'short';
|
|
@@ -54,9 +49,7 @@ interface FormatTimestampOptions {
|
|
|
54
49
|
*
|
|
55
50
|
* Safe on all target runtimes: Bun (V8), React Native Hermes (>= 0.70), web.
|
|
56
51
|
*/
|
|
57
|
-
declare function formatTimestamp(ts: number, locale: LocaleCode, options?: FormatTimestampOptions): string;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/manager.d.ts
|
|
52
|
+
export declare function formatTimestamp(ts: number, locale: LocaleCode, options?: FormatTimestampOptions): string;
|
|
60
53
|
interface LocalizationManagerOptions {
|
|
61
54
|
tables: Record<LocaleCode, StringTable>;
|
|
62
55
|
initialLocale: LocaleCode;
|
|
@@ -68,7 +61,7 @@ interface LocalizationManagerOptions {
|
|
|
68
61
|
* key. `onChange` fires whenever the active locale is swapped. `setTable`
|
|
69
62
|
* replaces a locale's table in place — enables hot-reload in dev.
|
|
70
63
|
*/
|
|
71
|
-
declare class LocalizationManager {
|
|
64
|
+
export declare class LocalizationManager {
|
|
72
65
|
private _tables;
|
|
73
66
|
private _locale;
|
|
74
67
|
private readonly _fallback;
|
|
@@ -85,23 +78,18 @@ declare class LocalizationManager {
|
|
|
85
78
|
has(key: string): boolean;
|
|
86
79
|
t(key: string, values?: MessageValues): string;
|
|
87
80
|
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/plurals.d.ts
|
|
90
81
|
/**
|
|
91
82
|
* Minimal CLDR-inspired plural classifier. Supports a handful of locales
|
|
92
83
|
* natively — fall back to English rules if unknown. This is not a full ICU
|
|
93
84
|
* implementation; it covers the categories used by our string tables.
|
|
94
85
|
*/
|
|
95
86
|
type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
|
|
96
|
-
declare function pluralCategory(locale: LocaleCode, n: number): PluralCategory;
|
|
97
|
-
//#endregion
|
|
98
|
-
//#region src/resolve.d.ts
|
|
87
|
+
export declare function pluralCategory(locale: LocaleCode, n: number): PluralCategory;
|
|
99
88
|
/**
|
|
100
89
|
* Negotiate the best locale match from a prioritized list against a set of
|
|
101
90
|
* available locales. Matching is case-insensitive and considers language +
|
|
102
91
|
* region. Returns the fallback when nothing matches.
|
|
103
92
|
*/
|
|
104
|
-
declare function resolveLocale(requested: readonly LocaleCode[], available: readonly LocaleCode[], fallback: LocaleCode): LocaleCode;
|
|
105
|
-
|
|
106
|
-
export { type FormatTimestampOptions, type LocaleCode, LocalizationManager, type LocalizationManagerOptions, type MessageValue, type MessageValues, type PluralCategory, type StringTable, formatMessage, formatTimestamp, pluralCategory, resolveLocale };
|
|
93
|
+
export declare function resolveLocale(requested: readonly LocaleCode[], available: readonly LocaleCode[], fallback: LocaleCode): LocaleCode;
|
|
94
|
+
export type { FormatTimestampOptions, LocaleCode, LocalizationManagerOptions, MessageValue, MessageValues, PluralCategory, StringTable };
|
|
107
95
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/format.ts","../src/format-timestamp.ts","../src/manager.ts","../src/plurals.ts","../src/resolve.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/format.ts","../src/format-timestamp.ts","../src/manager.ts","../src/plurals.ts","../src/resolve.ts"],"mappings":";;;;;;;;;KASY;KACA;KACA,gBAAgB,eAAe;KAC/B,cAAc;;;;;;;;;;;;;wBCIV,cACd,kBACA,QAAQ,2BACR,QAAQ;UCjBO;;EAEf;;;;;;;;;EASA;;EAEA;;;;;;;;;;;;wBAac,gBACd,YACA,QAAQ,YACR,UAAU;UC1BK;EACf,QAAQ,OAAO,YAAY;EAC3B,eAAe;EACf,gBAAgB;;;;;;;;qBASL;UACH;UACA;mBACS;WACR,UAAQ;EAEL,YAAA,SAAS;MAMjB,UAAU;MAIV,YAAY;EAIhB,oBAAoB;EAIpB,UAAU,QAAQ;;EAOlB,gBAAgB,oBAAoB,eAAe;;EAOnD,SAAS,QAAQ,YAAY,OAAO;EAKpC,IAAI;EASJ,EAAE,aAAa,SAAS;;;;;;;KC7Dd;wBAoDI,eAAe,QAAQ,YAAY,YAAY;;;;;;wBCrD/C,cACd,oBAAoB,cACpB,oBAAoB,cACpB,UAAU,aACT"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Signal } from "@flare-engine/events";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* String table → `{ key: message }` per locale.
|
|
5
4
|
*
|
|
@@ -12,8 +11,6 @@ type LocaleCode = string;
|
|
|
12
11
|
type MessageValue = string | number;
|
|
13
12
|
type MessageValues = Record<string, MessageValue>;
|
|
14
13
|
type StringTable = Record<string, string>;
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/format.d.ts
|
|
17
14
|
/**
|
|
18
15
|
* Minimal ICU MessageFormat-ish parser.
|
|
19
16
|
*
|
|
@@ -26,9 +23,7 @@ type StringTable = Record<string, string>;
|
|
|
26
23
|
*
|
|
27
24
|
* Nested plural blocks are not supported (not needed for our tables).
|
|
28
25
|
*/
|
|
29
|
-
declare function formatMessage(template: string, values: MessageValues | undefined, locale: LocaleCode): string;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/format-timestamp.d.ts
|
|
26
|
+
export declare function formatMessage(template: string, values: MessageValues | undefined, locale: LocaleCode): string;
|
|
32
27
|
interface FormatTimestampOptions {
|
|
33
28
|
/** Intl.DateTimeFormat date style. Defaults to 'short'. */
|
|
34
29
|
dateStyle?: 'full' | 'long' | 'medium' | 'short';
|
|
@@ -54,9 +49,7 @@ interface FormatTimestampOptions {
|
|
|
54
49
|
*
|
|
55
50
|
* Safe on all target runtimes: Bun (V8), React Native Hermes (>= 0.70), web.
|
|
56
51
|
*/
|
|
57
|
-
declare function formatTimestamp(ts: number, locale: LocaleCode, options?: FormatTimestampOptions): string;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/manager.d.ts
|
|
52
|
+
export declare function formatTimestamp(ts: number, locale: LocaleCode, options?: FormatTimestampOptions): string;
|
|
60
53
|
interface LocalizationManagerOptions {
|
|
61
54
|
tables: Record<LocaleCode, StringTable>;
|
|
62
55
|
initialLocale: LocaleCode;
|
|
@@ -68,7 +61,7 @@ interface LocalizationManagerOptions {
|
|
|
68
61
|
* key. `onChange` fires whenever the active locale is swapped. `setTable`
|
|
69
62
|
* replaces a locale's table in place — enables hot-reload in dev.
|
|
70
63
|
*/
|
|
71
|
-
declare class LocalizationManager {
|
|
64
|
+
export declare class LocalizationManager {
|
|
72
65
|
private _tables;
|
|
73
66
|
private _locale;
|
|
74
67
|
private readonly _fallback;
|
|
@@ -85,23 +78,18 @@ declare class LocalizationManager {
|
|
|
85
78
|
has(key: string): boolean;
|
|
86
79
|
t(key: string, values?: MessageValues): string;
|
|
87
80
|
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/plurals.d.ts
|
|
90
81
|
/**
|
|
91
82
|
* Minimal CLDR-inspired plural classifier. Supports a handful of locales
|
|
92
83
|
* natively — fall back to English rules if unknown. This is not a full ICU
|
|
93
84
|
* implementation; it covers the categories used by our string tables.
|
|
94
85
|
*/
|
|
95
86
|
type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
|
|
96
|
-
declare function pluralCategory(locale: LocaleCode, n: number): PluralCategory;
|
|
97
|
-
//#endregion
|
|
98
|
-
//#region src/resolve.d.ts
|
|
87
|
+
export declare function pluralCategory(locale: LocaleCode, n: number): PluralCategory;
|
|
99
88
|
/**
|
|
100
89
|
* Negotiate the best locale match from a prioritized list against a set of
|
|
101
90
|
* available locales. Matching is case-insensitive and considers language +
|
|
102
91
|
* region. Returns the fallback when nothing matches.
|
|
103
92
|
*/
|
|
104
|
-
declare function resolveLocale(requested: readonly LocaleCode[], available: readonly LocaleCode[], fallback: LocaleCode): LocaleCode;
|
|
105
|
-
|
|
106
|
-
export { type FormatTimestampOptions, type LocaleCode, LocalizationManager, type LocalizationManagerOptions, type MessageValue, type MessageValues, type PluralCategory, type StringTable, formatMessage, formatTimestamp, pluralCategory, resolveLocale };
|
|
93
|
+
export declare function resolveLocale(requested: readonly LocaleCode[], available: readonly LocaleCode[], fallback: LocaleCode): LocaleCode;
|
|
94
|
+
export type { FormatTimestampOptions, LocaleCode, LocalizationManagerOptions, MessageValue, MessageValues, PluralCategory, StringTable };
|
|
107
95
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/format.ts","../src/format-timestamp.ts","../src/manager.ts","../src/plurals.ts","../src/resolve.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/format.ts","../src/format-timestamp.ts","../src/manager.ts","../src/plurals.ts","../src/resolve.ts"],"mappings":";;;;;;;;;KASY;KACA;KACA,gBAAgB,eAAe;KAC/B,cAAc;;;;;;;;;;;;;wBCIV,cACd,kBACA,QAAQ,2BACR,QAAQ;UCjBO;;EAEf;;;;;;;;;EASA;;EAEA;;;;;;;;;;;;wBAac,gBACd,YACA,QAAQ,YACR,UAAU;UC1BK;EACf,QAAQ,OAAO,YAAY;EAC3B,eAAe;EACf,gBAAgB;;;;;;;;qBASL;UACH;UACA;mBACS;WACR,UAAQ;EAEL,YAAA,SAAS;MAMjB,UAAU;MAIV,YAAY;EAIhB,oBAAoB;EAIpB,UAAU,QAAQ;;EAOlB,gBAAgB,oBAAoB,eAAe;;EAOnD,SAAS,QAAQ,YAAY,OAAO;EAKpC,IAAI;EASJ,EAAE,aAAa,SAAS;;;;;;;KC7Dd;wBAoDI,eAAe,QAAQ,YAAY,YAAY;;;;;;wBCrD/C,cACd,oBAAoB,cACpB,oBAAoB,cACpB,UAAU,aACT"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _flare_engine_events = require("@flare-engine/events");
|
|
3
|
-
|
|
3
|
+
// src/plurals.ts
|
|
4
4
|
const ENGLISH = (n) => n === 1 ? "one" : "other";
|
|
5
5
|
const POLISH = (n) => {
|
|
6
6
|
if (n === 1) return "one";
|
|
@@ -47,8 +47,7 @@ function pluralCategory(locale, n) {
|
|
|
47
47
|
const lang = locale.toLowerCase().split(/[-_]/)[0] ?? "en";
|
|
48
48
|
return (RULES[lang] ?? ENGLISH)(n);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
//#region src/format.ts
|
|
50
|
+
// src/format.ts
|
|
52
51
|
/**
|
|
53
52
|
* Minimal ICU MessageFormat-ish parser.
|
|
54
53
|
*
|
|
@@ -159,8 +158,7 @@ function stringifyValue(v) {
|
|
|
159
158
|
if (v === void 0 || v === null) return "";
|
|
160
159
|
return String(v);
|
|
161
160
|
}
|
|
162
|
-
|
|
163
|
-
//#region src/format-timestamp.ts
|
|
161
|
+
// src/format-timestamp.ts
|
|
164
162
|
/**
|
|
165
163
|
* Format a Unix timestamp (milliseconds) as a human-readable date/time string
|
|
166
164
|
* using Intl.DateTimeFormat with the given locale.
|
|
@@ -183,8 +181,7 @@ function formatTimestamp(ts, locale, options) {
|
|
|
183
181
|
return fallback;
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
|
-
|
|
187
|
-
//#region src/resolve.ts
|
|
184
|
+
// src/resolve.ts
|
|
188
185
|
/**
|
|
189
186
|
* Negotiate the best locale match from a prioritized list against a set of
|
|
190
187
|
* available locales. Matching is case-insensitive and considers language +
|
|
@@ -206,8 +203,7 @@ function resolveLocale(requested, available, fallback) {
|
|
|
206
203
|
if (fbIdx !== -1) return available[fbIdx];
|
|
207
204
|
return available[0];
|
|
208
205
|
}
|
|
209
|
-
|
|
210
|
-
//#region src/manager.ts
|
|
206
|
+
// src/manager.ts
|
|
211
207
|
/**
|
|
212
208
|
* Owns the active locale + string tables. `t(key, values?)` renders a message
|
|
213
209
|
* using the active locale, falling back to the fallback locale, then the raw
|
|
@@ -260,7 +256,6 @@ var LocalizationManager = class {
|
|
|
260
256
|
return formatMessage((active !== void 0 && Object.hasOwn(active, key) ? active[key] : void 0) ?? (fallback !== void 0 && Object.hasOwn(fallback, key) ? fallback[key] : void 0) ?? key, values, this._locale);
|
|
261
257
|
}
|
|
262
258
|
};
|
|
263
|
-
//#endregion
|
|
264
259
|
exports.LocalizationManager = LocalizationManager;
|
|
265
260
|
exports.formatMessage = formatMessage;
|
|
266
261
|
exports.formatTimestamp = formatTimestamp;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Signal"],"sources":["../src/plurals.ts","../src/format.ts","../src/format-timestamp.ts","../src/resolve.ts","../src/manager.ts"],"sourcesContent":["import type { LocaleCode } from './types.js';\n\n/**\n * Minimal CLDR-inspired plural classifier. Supports a handful of locales\n * natively — fall back to English rules if unknown. This is not a full ICU\n * implementation; it covers the categories used by our string tables.\n */\n\nexport type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';\n\ntype PluralRule = (n: number) => PluralCategory;\n\nconst ENGLISH: PluralRule = (n) => (n === 1 ? 'one' : 'other');\n\nconst POLISH: PluralRule = (n) => {\n if (n === 1) return 'one';\n const mod10 = n % 10;\n const mod100 = n % 100;\n if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';\n return 'many';\n};\n\nconst RUSSIAN: PluralRule = (n) => {\n const mod10 = n % 10;\n const mod100 = n % 100;\n if (mod10 === 1 && mod100 !== 11) return 'one';\n if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';\n if (mod10 === 0 || (mod10 >= 5 && mod10 <= 9) || (mod100 >= 11 && mod100 <= 14)) return 'many';\n return 'other';\n};\n\nconst ARABIC: PluralRule = (n) => {\n if (n === 0) return 'zero';\n if (n === 1) return 'one';\n if (n === 2) return 'two';\n const mod100 = n % 100;\n if (mod100 >= 3 && mod100 <= 10) return 'few';\n if (mod100 >= 11 && mod100 <= 99) return 'many';\n return 'other';\n};\n\nconst JAPANESE: PluralRule = () => 'other';\n\nconst RULES: Record<string, PluralRule> = {\n en: ENGLISH,\n de: ENGLISH,\n es: ENGLISH,\n fr: (n) => (n === 0 || n === 1 ? 'one' : 'other'),\n it: ENGLISH,\n pt: ENGLISH,\n nl: ENGLISH,\n pl: POLISH,\n ru: RUSSIAN,\n uk: RUSSIAN,\n ar: ARABIC,\n ja: JAPANESE,\n ko: JAPANESE,\n zh: JAPANESE,\n};\n\nexport function pluralCategory(locale: LocaleCode, n: number): PluralCategory {\n const lang = locale.toLowerCase().split(/[-_]/)[0] ?? 'en';\n const rule = RULES[lang] ?? ENGLISH;\n return rule(n);\n}\n","import { pluralCategory } from './plurals.js';\nimport type { LocaleCode, MessageValues } from './types.js';\n\n/**\n * Minimal ICU MessageFormat-ish parser.\n *\n * Grammar:\n * text := (chunk)*\n * chunk := literal | '{' var '}' | '{' var ',' 'plural' ',' branches '}'\n * branches := (selector '{' text '}')+\n * selector := '=' number | identifier // one | few | many | other | zero | two\n * number/ident literals inside a branch may reference '#' → the variable's number value.\n *\n * Nested plural blocks are not supported (not needed for our tables).\n */\n\nexport function formatMessage(\n template: string,\n values: MessageValues | undefined,\n locale: LocaleCode,\n): string {\n const vals = values ?? {};\n let out = '';\n let i = 0;\n const len = template.length;\n while (i < len) {\n const ch = template[i];\n if (ch !== '{') {\n out += ch;\n i++;\n continue;\n }\n // Find the matching closing brace, respecting nested braces.\n const endIdx = findMatchingClose(template, i);\n if (endIdx === -1) {\n // Malformed — emit remainder literally.\n out += template.slice(i);\n break;\n }\n const inner = template.slice(i + 1, endIdx);\n out += renderPlaceholder(inner, vals, locale);\n i = endIdx + 1;\n }\n return out;\n}\n\nfunction findMatchingClose(src: string, startBrace: number): number {\n let depth = 0;\n for (let i = startBrace; i < src.length; i++) {\n const c = src[i];\n if (c === '{') depth++;\n else if (c === '}') {\n depth--;\n if (depth === 0) return i;\n }\n }\n return -1;\n}\n\nfunction renderPlaceholder(inner: string, values: MessageValues, locale: LocaleCode): string {\n // Split only on the top-level commas into at most 3 parts: name, type, body.\n const commaIdx = topLevelComma(inner);\n if (commaIdx === -1) {\n const k = inner.trim();\n return stringifyValue(Object.hasOwn(values, k) ? values[k] : undefined);\n }\n const name = inner.slice(0, commaIdx).trim();\n const rest = inner.slice(commaIdx + 1).trim();\n const secondComma = topLevelComma(rest);\n if (secondComma === -1)\n return stringifyValue(Object.hasOwn(values, name) ? values[name] : undefined);\n const type = rest.slice(0, secondComma).trim();\n const body = rest.slice(secondComma + 1).trim();\n if (type !== 'plural') {\n // Unknown formatter — fall back to raw substitution.\n return stringifyValue(Object.hasOwn(values, name) ? values[name] : undefined);\n }\n const raw = Object.hasOwn(values, name) ? values[name] : undefined;\n const n = typeof raw === 'number' ? raw : Number(raw);\n const category = Number.isFinite(n) ? pluralCategory(locale, n) : 'other';\n const branches = parsePluralBranches(body);\n const branchText =\n branches[`=${Number.isFinite(n) ? n : ''}`] ?? branches[category] ?? branches.other ?? '';\n // '#' inside the branch refers to the numeric value.\n const replaced = branchText.replace(/#/g, Number.isFinite(n) ? String(n) : '');\n // Recurse so nested `{var}` inside the branch is resolved.\n return formatMessage(replaced, values, locale);\n}\n\nfunction topLevelComma(src: string): number {\n let depth = 0;\n for (let i = 0; i < src.length; i++) {\n const c = src[i];\n if (c === '{') depth++;\n else if (c === '}') depth--;\n else if (c === ',' && depth === 0) return i;\n }\n return -1;\n}\n\nfunction parsePluralBranches(body: string): Record<string, string> {\n const out: Record<string, string> = {};\n let i = 0;\n while (i < body.length) {\n // Skip whitespace.\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') i++;\n else break;\n }\n if (i >= body.length) break;\n // Read selector until whitespace or '{'.\n const selStart = i;\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r' || ch === '{') break;\n i++;\n }\n const selector = body.slice(selStart, i);\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') i++;\n else break;\n }\n if (body[i] !== '{') break;\n const end = findMatchingClose(body, i);\n if (end === -1) break;\n out[selector] = body.slice(i + 1, end);\n i = end + 1;\n }\n return out;\n}\n\nfunction stringifyValue(v: unknown): string {\n if (v === undefined || v === null) return '';\n return String(v);\n}\n","import type { LocaleCode } from './types.js';\n\nexport interface FormatTimestampOptions {\n /** Intl.DateTimeFormat date style. Defaults to 'short'. */\n dateStyle?: 'full' | 'long' | 'medium' | 'short';\n /**\n * Intl.DateTimeFormat time style.\n *\n * Applied when explicitly provided here, or when the entire `options`\n * argument is omitted (defaults to 'short' in that case).\n * Passing an `options` object that does NOT include `timeStyle` yields a\n * date-only result — time is suppressed.\n */\n timeStyle?: 'full' | 'long' | 'medium' | 'short';\n /** Returned for ts <= 0 or on any Intl failure. Defaults to ''. */\n fallback?: string;\n}\n\n/**\n * Format a Unix timestamp (milliseconds) as a human-readable date/time string\n * using Intl.DateTimeFormat with the given locale.\n *\n * Returns `options.fallback` (default '') for ts <= 0 or on any Intl error\n * (e.g. unsupported locale on a constrained runtime). The locale is used\n * directly as the Intl BCP-47 tag.\n *\n * Safe on all target runtimes: Bun (V8), React Native Hermes (>= 0.70), web.\n */\nexport function formatTimestamp(\n ts: number,\n locale: LocaleCode,\n options?: FormatTimestampOptions,\n): string {\n const fallback = options?.fallback ?? '';\n if (ts <= 0) return fallback;\n try {\n const intlOpts: Intl.DateTimeFormatOptions = {\n dateStyle: options?.dateStyle ?? 'short',\n };\n if (options?.timeStyle !== undefined) {\n intlOpts.timeStyle = options.timeStyle;\n } else if (options === undefined) {\n intlOpts.timeStyle = 'short';\n }\n return new Intl.DateTimeFormat(locale, intlOpts).format(new Date(ts));\n } catch {\n return fallback;\n }\n}\n","import type { LocaleCode } from './types.js';\n\n/**\n * Negotiate the best locale match from a prioritized list against a set of\n * available locales. Matching is case-insensitive and considers language +\n * region. Returns the fallback when nothing matches.\n */\nexport function resolveLocale(\n requested: readonly LocaleCode[],\n available: readonly LocaleCode[],\n fallback: LocaleCode,\n): LocaleCode {\n if (available.length === 0) return fallback;\n const norm = (s: string): string => s.toLowerCase().replace(/_/g, '-');\n const avail = available.map(norm);\n\n for (const rawReq of requested) {\n const req = norm(rawReq);\n // Exact match.\n const exactIdx = avail.indexOf(req);\n if (exactIdx !== -1) return available[exactIdx] as LocaleCode;\n // Language-only match against any region variant.\n const lang = req.split('-')[0] ?? req;\n const langIdx = avail.findIndex((a) => (a.split('-')[0] ?? a) === lang);\n if (langIdx !== -1) return available[langIdx] as LocaleCode;\n }\n // Fallback — ensure it is actually present; otherwise first available.\n const fbIdx = avail.indexOf(norm(fallback));\n if (fbIdx !== -1) return available[fbIdx] as LocaleCode;\n return available[0] as LocaleCode;\n}\n","import { Signal } from '@flare-engine/events';\nimport { formatMessage } from './format.js';\nimport { resolveLocale } from './resolve.js';\nimport type { LocaleCode, MessageValues, StringTable } from './types.js';\n\nexport interface LocalizationManagerOptions {\n tables: Record<LocaleCode, StringTable>;\n initialLocale: LocaleCode;\n fallbackLocale: LocaleCode;\n}\n\n/**\n * Owns the active locale + string tables. `t(key, values?)` renders a message\n * using the active locale, falling back to the fallback locale, then the raw\n * key. `onChange` fires whenever the active locale is swapped. `setTable`\n * replaces a locale's table in place — enables hot-reload in dev.\n */\nexport class LocalizationManager {\n private _tables: Record<LocaleCode, StringTable>;\n private _locale: LocaleCode;\n private readonly _fallback: LocaleCode;\n readonly onChange = new Signal<LocaleCode>();\n\n constructor(options: LocalizationManagerOptions) {\n this._tables = { ...options.tables };\n this._fallback = options.fallbackLocale;\n this._locale = options.initialLocale;\n }\n\n get locale(): LocaleCode {\n return this._locale;\n }\n\n get fallback(): LocaleCode {\n return this._fallback;\n }\n\n availableLocales(): LocaleCode[] {\n return Object.keys(this._tables);\n }\n\n setLocale(locale: LocaleCode): void {\n if (this._locale === locale) return;\n this._locale = locale;\n this.onChange.emit(locale);\n }\n\n /** Pick the best-matching locale from the given requests and make it active. */\n negotiateLocale(requested: readonly LocaleCode[]): LocaleCode {\n const chosen = resolveLocale(requested, this.availableLocales(), this._fallback);\n this.setLocale(chosen);\n return chosen;\n }\n\n /** Replace (or install) a locale's table. Emits `onChange` if it targets the active locale. */\n setTable(locale: LocaleCode, table: StringTable): void {\n this._tables[locale] = table;\n if (locale === this._locale) this.onChange.emit(locale);\n }\n\n has(key: string): boolean {\n const active = this._tables[this._locale];\n const fallback = this._tables[this._fallback];\n return (\n (active !== undefined && Object.hasOwn(active, key)) ||\n (fallback !== undefined && Object.hasOwn(fallback, key))\n );\n }\n\n t(key: string, values?: MessageValues): string {\n const active = this._tables[this._locale];\n const fallback = this._tables[this._fallback];\n const template =\n (active !== undefined && Object.hasOwn(active, key) ? active[key] : undefined) ??\n (fallback !== undefined && Object.hasOwn(fallback, key) ? fallback[key] : undefined) ??\n key;\n return formatMessage(template, values, this._locale);\n }\n}\n"],"mappings":";;;AAYA,MAAM,WAAuB,MAAO,MAAM,IAAI,QAAQ;AAEtD,MAAM,UAAsB,MAAM;CAChC,IAAI,MAAM,GAAG,OAAO;CACpB,MAAM,QAAQ,IAAI;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,SAAS,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,KAAK,OAAO;CACrE,OAAO;AACT;AAEA,MAAM,WAAuB,MAAM;CACjC,MAAM,QAAQ,IAAI;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,UAAU,KAAK,WAAW,IAAI,OAAO;CACzC,IAAI,SAAS,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,KAAK,OAAO;CACrE,IAAI,UAAU,KAAM,SAAS,KAAK,SAAS,KAAO,UAAU,MAAM,UAAU,IAAK,OAAO;CACxF,OAAO;AACT;AAEA,MAAM,UAAsB,MAAM;CAChC,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,MAAM,GAAG,OAAO;CACpB,MAAM,SAAS,IAAI;CACnB,IAAI,UAAU,KAAK,UAAU,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AK,SAAS;EAC/E,KAAK,UAAU,MAAM;EACrB,OAAO;CACT;;CAGA,SAAS,QAAoB,OAA0B;EACrD,KAAK,QAAQ,UAAU;EACvB,IAAI,WAAW,KAAK,SAAS,KAAK,SAAS,KAAK,MAAM;CACxD;CAEA,IAAI,KAAsB;EACxB,MAAM,SAAS,KAAK,QAAQ,KAAK;EACjC,MAAM,WAAW,KAAK,QAAQ,KAAK;EACnC,OACG,WAAW,KAAA,KAAa,OAAO,OAAO,QAAQ,GAAG,KACjD,aAAa,KAAA,KAAa,OAAO,OAAO,UAAU,GAAG;CAE1D;CAEA,EAAE,KAAa,QAAgC;EAC7C,MAAM,SAAS,KAAK,QAAQ,KAAK;EACjC,MAAM,WAAW,KAAK,QAAQ,KAAK;EAKnC,OAAO,eAHJ,WAAW,KAAA,KAAa,OAAO,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,KAAA,OACnE,aAAa,KAAA,KAAa,OAAO,OAAO,UAAU,GAAG,IAAI,SAAS,OAAO,KAAA,MAC1E,KAC6B,QAAQ,KAAK,OAAO;CACrD;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Signal"],"sources":["../src/plurals.ts","../src/format.ts","../src/format-timestamp.ts","../src/resolve.ts","../src/manager.ts"],"sourcesContent":["import type { LocaleCode } from './types.js';\n\n/**\n * Minimal CLDR-inspired plural classifier. Supports a handful of locales\n * natively — fall back to English rules if unknown. This is not a full ICU\n * implementation; it covers the categories used by our string tables.\n */\n\nexport type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';\n\ntype PluralRule = (n: number) => PluralCategory;\n\nconst ENGLISH: PluralRule = (n) => (n === 1 ? 'one' : 'other');\n\nconst POLISH: PluralRule = (n) => {\n if (n === 1) return 'one';\n const mod10 = n % 10;\n const mod100 = n % 100;\n if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';\n return 'many';\n};\n\nconst RUSSIAN: PluralRule = (n) => {\n const mod10 = n % 10;\n const mod100 = n % 100;\n if (mod10 === 1 && mod100 !== 11) return 'one';\n if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';\n if (mod10 === 0 || (mod10 >= 5 && mod10 <= 9) || (mod100 >= 11 && mod100 <= 14)) return 'many';\n return 'other';\n};\n\nconst ARABIC: PluralRule = (n) => {\n if (n === 0) return 'zero';\n if (n === 1) return 'one';\n if (n === 2) return 'two';\n const mod100 = n % 100;\n if (mod100 >= 3 && mod100 <= 10) return 'few';\n if (mod100 >= 11 && mod100 <= 99) return 'many';\n return 'other';\n};\n\nconst JAPANESE: PluralRule = () => 'other';\n\nconst RULES: Record<string, PluralRule> = {\n en: ENGLISH,\n de: ENGLISH,\n es: ENGLISH,\n fr: (n) => (n === 0 || n === 1 ? 'one' : 'other'),\n it: ENGLISH,\n pt: ENGLISH,\n nl: ENGLISH,\n pl: POLISH,\n ru: RUSSIAN,\n uk: RUSSIAN,\n ar: ARABIC,\n ja: JAPANESE,\n ko: JAPANESE,\n zh: JAPANESE,\n};\n\nexport function pluralCategory(locale: LocaleCode, n: number): PluralCategory {\n const lang = locale.toLowerCase().split(/[-_]/)[0] ?? 'en';\n const rule = RULES[lang] ?? ENGLISH;\n return rule(n);\n}\n","import { pluralCategory } from './plurals.js';\nimport type { LocaleCode, MessageValues } from './types.js';\n\n/**\n * Minimal ICU MessageFormat-ish parser.\n *\n * Grammar:\n * text := (chunk)*\n * chunk := literal | '{' var '}' | '{' var ',' 'plural' ',' branches '}'\n * branches := (selector '{' text '}')+\n * selector := '=' number | identifier // one | few | many | other | zero | two\n * number/ident literals inside a branch may reference '#' → the variable's number value.\n *\n * Nested plural blocks are not supported (not needed for our tables).\n */\n\nexport function formatMessage(\n template: string,\n values: MessageValues | undefined,\n locale: LocaleCode,\n): string {\n const vals = values ?? {};\n let out = '';\n let i = 0;\n const len = template.length;\n while (i < len) {\n const ch = template[i];\n if (ch !== '{') {\n out += ch;\n i++;\n continue;\n }\n // Find the matching closing brace, respecting nested braces.\n const endIdx = findMatchingClose(template, i);\n if (endIdx === -1) {\n // Malformed — emit remainder literally.\n out += template.slice(i);\n break;\n }\n const inner = template.slice(i + 1, endIdx);\n out += renderPlaceholder(inner, vals, locale);\n i = endIdx + 1;\n }\n return out;\n}\n\nfunction findMatchingClose(src: string, startBrace: number): number {\n let depth = 0;\n for (let i = startBrace; i < src.length; i++) {\n const c = src[i];\n if (c === '{') depth++;\n else if (c === '}') {\n depth--;\n if (depth === 0) return i;\n }\n }\n return -1;\n}\n\nfunction renderPlaceholder(inner: string, values: MessageValues, locale: LocaleCode): string {\n // Split only on the top-level commas into at most 3 parts: name, type, body.\n const commaIdx = topLevelComma(inner);\n if (commaIdx === -1) {\n const k = inner.trim();\n return stringifyValue(Object.hasOwn(values, k) ? values[k] : undefined);\n }\n const name = inner.slice(0, commaIdx).trim();\n const rest = inner.slice(commaIdx + 1).trim();\n const secondComma = topLevelComma(rest);\n if (secondComma === -1)\n return stringifyValue(Object.hasOwn(values, name) ? values[name] : undefined);\n const type = rest.slice(0, secondComma).trim();\n const body = rest.slice(secondComma + 1).trim();\n if (type !== 'plural') {\n // Unknown formatter — fall back to raw substitution.\n return stringifyValue(Object.hasOwn(values, name) ? values[name] : undefined);\n }\n const raw = Object.hasOwn(values, name) ? values[name] : undefined;\n const n = typeof raw === 'number' ? raw : Number(raw);\n const category = Number.isFinite(n) ? pluralCategory(locale, n) : 'other';\n const branches = parsePluralBranches(body);\n const branchText =\n branches[`=${Number.isFinite(n) ? n : ''}`] ?? branches[category] ?? branches.other ?? '';\n // '#' inside the branch refers to the numeric value.\n const replaced = branchText.replace(/#/g, Number.isFinite(n) ? String(n) : '');\n // Recurse so nested `{var}` inside the branch is resolved.\n return formatMessage(replaced, values, locale);\n}\n\nfunction topLevelComma(src: string): number {\n let depth = 0;\n for (let i = 0; i < src.length; i++) {\n const c = src[i];\n if (c === '{') depth++;\n else if (c === '}') depth--;\n else if (c === ',' && depth === 0) return i;\n }\n return -1;\n}\n\nfunction parsePluralBranches(body: string): Record<string, string> {\n const out: Record<string, string> = {};\n let i = 0;\n while (i < body.length) {\n // Skip whitespace.\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') i++;\n else break;\n }\n if (i >= body.length) break;\n // Read selector until whitespace or '{'.\n const selStart = i;\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r' || ch === '{') break;\n i++;\n }\n const selector = body.slice(selStart, i);\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') i++;\n else break;\n }\n if (body[i] !== '{') break;\n const end = findMatchingClose(body, i);\n if (end === -1) break;\n out[selector] = body.slice(i + 1, end);\n i = end + 1;\n }\n return out;\n}\n\nfunction stringifyValue(v: unknown): string {\n if (v === undefined || v === null) return '';\n return String(v);\n}\n","import type { LocaleCode } from './types.js';\n\nexport interface FormatTimestampOptions {\n /** Intl.DateTimeFormat date style. Defaults to 'short'. */\n dateStyle?: 'full' | 'long' | 'medium' | 'short';\n /**\n * Intl.DateTimeFormat time style.\n *\n * Applied when explicitly provided here, or when the entire `options`\n * argument is omitted (defaults to 'short' in that case).\n * Passing an `options` object that does NOT include `timeStyle` yields a\n * date-only result — time is suppressed.\n */\n timeStyle?: 'full' | 'long' | 'medium' | 'short';\n /** Returned for ts <= 0 or on any Intl failure. Defaults to ''. */\n fallback?: string;\n}\n\n/**\n * Format a Unix timestamp (milliseconds) as a human-readable date/time string\n * using Intl.DateTimeFormat with the given locale.\n *\n * Returns `options.fallback` (default '') for ts <= 0 or on any Intl error\n * (e.g. unsupported locale on a constrained runtime). The locale is used\n * directly as the Intl BCP-47 tag.\n *\n * Safe on all target runtimes: Bun (V8), React Native Hermes (>= 0.70), web.\n */\nexport function formatTimestamp(\n ts: number,\n locale: LocaleCode,\n options?: FormatTimestampOptions,\n): string {\n const fallback = options?.fallback ?? '';\n if (ts <= 0) return fallback;\n try {\n const intlOpts: Intl.DateTimeFormatOptions = {\n dateStyle: options?.dateStyle ?? 'short',\n };\n if (options?.timeStyle !== undefined) {\n intlOpts.timeStyle = options.timeStyle;\n } else if (options === undefined) {\n intlOpts.timeStyle = 'short';\n }\n return new Intl.DateTimeFormat(locale, intlOpts).format(new Date(ts));\n } catch {\n return fallback;\n }\n}\n","import type { LocaleCode } from './types.js';\n\n/**\n * Negotiate the best locale match from a prioritized list against a set of\n * available locales. Matching is case-insensitive and considers language +\n * region. Returns the fallback when nothing matches.\n */\nexport function resolveLocale(\n requested: readonly LocaleCode[],\n available: readonly LocaleCode[],\n fallback: LocaleCode,\n): LocaleCode {\n if (available.length === 0) return fallback;\n const norm = (s: string): string => s.toLowerCase().replace(/_/g, '-');\n const avail = available.map(norm);\n\n for (const rawReq of requested) {\n const req = norm(rawReq);\n // Exact match.\n const exactIdx = avail.indexOf(req);\n if (exactIdx !== -1) return available[exactIdx] as LocaleCode;\n // Language-only match against any region variant.\n const lang = req.split('-')[0] ?? req;\n const langIdx = avail.findIndex((a) => (a.split('-')[0] ?? a) === lang);\n if (langIdx !== -1) return available[langIdx] as LocaleCode;\n }\n // Fallback — ensure it is actually present; otherwise first available.\n const fbIdx = avail.indexOf(norm(fallback));\n if (fbIdx !== -1) return available[fbIdx] as LocaleCode;\n return available[0] as LocaleCode;\n}\n","import { Signal } from '@flare-engine/events';\nimport { formatMessage } from './format.js';\nimport { resolveLocale } from './resolve.js';\nimport type { LocaleCode, MessageValues, StringTable } from './types.js';\n\nexport interface LocalizationManagerOptions {\n tables: Record<LocaleCode, StringTable>;\n initialLocale: LocaleCode;\n fallbackLocale: LocaleCode;\n}\n\n/**\n * Owns the active locale + string tables. `t(key, values?)` renders a message\n * using the active locale, falling back to the fallback locale, then the raw\n * key. `onChange` fires whenever the active locale is swapped. `setTable`\n * replaces a locale's table in place — enables hot-reload in dev.\n */\nexport class LocalizationManager {\n private _tables: Record<LocaleCode, StringTable>;\n private _locale: LocaleCode;\n private readonly _fallback: LocaleCode;\n readonly onChange = new Signal<LocaleCode>();\n\n constructor(options: LocalizationManagerOptions) {\n this._tables = { ...options.tables };\n this._fallback = options.fallbackLocale;\n this._locale = options.initialLocale;\n }\n\n get locale(): LocaleCode {\n return this._locale;\n }\n\n get fallback(): LocaleCode {\n return this._fallback;\n }\n\n availableLocales(): LocaleCode[] {\n return Object.keys(this._tables);\n }\n\n setLocale(locale: LocaleCode): void {\n if (this._locale === locale) return;\n this._locale = locale;\n this.onChange.emit(locale);\n }\n\n /** Pick the best-matching locale from the given requests and make it active. */\n negotiateLocale(requested: readonly LocaleCode[]): LocaleCode {\n const chosen = resolveLocale(requested, this.availableLocales(), this._fallback);\n this.setLocale(chosen);\n return chosen;\n }\n\n /** Replace (or install) a locale's table. Emits `onChange` if it targets the active locale. */\n setTable(locale: LocaleCode, table: StringTable): void {\n this._tables[locale] = table;\n if (locale === this._locale) this.onChange.emit(locale);\n }\n\n has(key: string): boolean {\n const active = this._tables[this._locale];\n const fallback = this._tables[this._fallback];\n return (\n (active !== undefined && Object.hasOwn(active, key)) ||\n (fallback !== undefined && Object.hasOwn(fallback, key))\n );\n }\n\n t(key: string, values?: MessageValues): string {\n const active = this._tables[this._locale];\n const fallback = this._tables[this._fallback];\n const template =\n (active !== undefined && Object.hasOwn(active, key) ? active[key] : undefined) ??\n (fallback !== undefined && Object.hasOwn(fallback, key) ? fallback[key] : undefined) ??\n key;\n return formatMessage(template, values, this._locale);\n }\n}\n"],"mappings":";;;AAYA,MAAM,WAAuB,MAAO,MAAM,IAAI,QAAQ;AAEtD,MAAM,UAAsB,MAAM;CAChC,IAAI,MAAM,GAAG,OAAO;CACpB,MAAM,QAAQ,IAAI;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,SAAS,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,KAAK,OAAO;CACrE,OAAO;AACT;AAEA,MAAM,WAAuB,MAAM;CACjC,MAAM,QAAQ,IAAI;CACl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
4
|
const POLISH = (n) => {
|
|
5
5
|
if (n === 1) return "one";
|
|
@@ -46,8 +46,7 @@ function pluralCategory(locale, n) {
|
|
|
46
46
|
const lang = locale.toLowerCase().split(/[-_]/)[0] ?? "en";
|
|
47
47
|
return (RULES[lang] ?? ENGLISH)(n);
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
//#region src/format.ts
|
|
49
|
+
// src/format.ts
|
|
51
50
|
/**
|
|
52
51
|
* Minimal ICU MessageFormat-ish parser.
|
|
53
52
|
*
|
|
@@ -158,8 +157,7 @@ function stringifyValue(v) {
|
|
|
158
157
|
if (v === void 0 || v === null) return "";
|
|
159
158
|
return String(v);
|
|
160
159
|
}
|
|
161
|
-
|
|
162
|
-
//#region src/format-timestamp.ts
|
|
160
|
+
// src/format-timestamp.ts
|
|
163
161
|
/**
|
|
164
162
|
* Format a Unix timestamp (milliseconds) as a human-readable date/time string
|
|
165
163
|
* using Intl.DateTimeFormat with the given locale.
|
|
@@ -182,8 +180,7 @@ function formatTimestamp(ts, locale, options) {
|
|
|
182
180
|
return fallback;
|
|
183
181
|
}
|
|
184
182
|
}
|
|
185
|
-
|
|
186
|
-
//#region src/resolve.ts
|
|
183
|
+
// src/resolve.ts
|
|
187
184
|
/**
|
|
188
185
|
* Negotiate the best locale match from a prioritized list against a set of
|
|
189
186
|
* available locales. Matching is case-insensitive and considers language +
|
|
@@ -205,8 +202,7 @@ function resolveLocale(requested, available, fallback) {
|
|
|
205
202
|
if (fbIdx !== -1) return available[fbIdx];
|
|
206
203
|
return available[0];
|
|
207
204
|
}
|
|
208
|
-
|
|
209
|
-
//#region src/manager.ts
|
|
205
|
+
// src/manager.ts
|
|
210
206
|
/**
|
|
211
207
|
* Owns the active locale + string tables. `t(key, values?)` renders a message
|
|
212
208
|
* using the active locale, falling back to the fallback locale, then the raw
|
|
@@ -259,7 +255,6 @@ var LocalizationManager = class {
|
|
|
259
255
|
return formatMessage((active !== void 0 && Object.hasOwn(active, key) ? active[key] : void 0) ?? (fallback !== void 0 && Object.hasOwn(fallback, key) ? fallback[key] : void 0) ?? key, values, this._locale);
|
|
260
256
|
}
|
|
261
257
|
};
|
|
262
|
-
//#endregion
|
|
263
258
|
export { LocalizationManager, formatMessage, formatTimestamp, pluralCategory, resolveLocale };
|
|
264
259
|
|
|
265
260
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/plurals.ts","../src/format.ts","../src/format-timestamp.ts","../src/resolve.ts","../src/manager.ts"],"sourcesContent":["import type { LocaleCode } from './types.js';\n\n/**\n * Minimal CLDR-inspired plural classifier. Supports a handful of locales\n * natively — fall back to English rules if unknown. This is not a full ICU\n * implementation; it covers the categories used by our string tables.\n */\n\nexport type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';\n\ntype PluralRule = (n: number) => PluralCategory;\n\nconst ENGLISH: PluralRule = (n) => (n === 1 ? 'one' : 'other');\n\nconst POLISH: PluralRule = (n) => {\n if (n === 1) return 'one';\n const mod10 = n % 10;\n const mod100 = n % 100;\n if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';\n return 'many';\n};\n\nconst RUSSIAN: PluralRule = (n) => {\n const mod10 = n % 10;\n const mod100 = n % 100;\n if (mod10 === 1 && mod100 !== 11) return 'one';\n if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';\n if (mod10 === 0 || (mod10 >= 5 && mod10 <= 9) || (mod100 >= 11 && mod100 <= 14)) return 'many';\n return 'other';\n};\n\nconst ARABIC: PluralRule = (n) => {\n if (n === 0) return 'zero';\n if (n === 1) return 'one';\n if (n === 2) return 'two';\n const mod100 = n % 100;\n if (mod100 >= 3 && mod100 <= 10) return 'few';\n if (mod100 >= 11 && mod100 <= 99) return 'many';\n return 'other';\n};\n\nconst JAPANESE: PluralRule = () => 'other';\n\nconst RULES: Record<string, PluralRule> = {\n en: ENGLISH,\n de: ENGLISH,\n es: ENGLISH,\n fr: (n) => (n === 0 || n === 1 ? 'one' : 'other'),\n it: ENGLISH,\n pt: ENGLISH,\n nl: ENGLISH,\n pl: POLISH,\n ru: RUSSIAN,\n uk: RUSSIAN,\n ar: ARABIC,\n ja: JAPANESE,\n ko: JAPANESE,\n zh: JAPANESE,\n};\n\nexport function pluralCategory(locale: LocaleCode, n: number): PluralCategory {\n const lang = locale.toLowerCase().split(/[-_]/)[0] ?? 'en';\n const rule = RULES[lang] ?? ENGLISH;\n return rule(n);\n}\n","import { pluralCategory } from './plurals.js';\nimport type { LocaleCode, MessageValues } from './types.js';\n\n/**\n * Minimal ICU MessageFormat-ish parser.\n *\n * Grammar:\n * text := (chunk)*\n * chunk := literal | '{' var '}' | '{' var ',' 'plural' ',' branches '}'\n * branches := (selector '{' text '}')+\n * selector := '=' number | identifier // one | few | many | other | zero | two\n * number/ident literals inside a branch may reference '#' → the variable's number value.\n *\n * Nested plural blocks are not supported (not needed for our tables).\n */\n\nexport function formatMessage(\n template: string,\n values: MessageValues | undefined,\n locale: LocaleCode,\n): string {\n const vals = values ?? {};\n let out = '';\n let i = 0;\n const len = template.length;\n while (i < len) {\n const ch = template[i];\n if (ch !== '{') {\n out += ch;\n i++;\n continue;\n }\n // Find the matching closing brace, respecting nested braces.\n const endIdx = findMatchingClose(template, i);\n if (endIdx === -1) {\n // Malformed — emit remainder literally.\n out += template.slice(i);\n break;\n }\n const inner = template.slice(i + 1, endIdx);\n out += renderPlaceholder(inner, vals, locale);\n i = endIdx + 1;\n }\n return out;\n}\n\nfunction findMatchingClose(src: string, startBrace: number): number {\n let depth = 0;\n for (let i = startBrace; i < src.length; i++) {\n const c = src[i];\n if (c === '{') depth++;\n else if (c === '}') {\n depth--;\n if (depth === 0) return i;\n }\n }\n return -1;\n}\n\nfunction renderPlaceholder(inner: string, values: MessageValues, locale: LocaleCode): string {\n // Split only on the top-level commas into at most 3 parts: name, type, body.\n const commaIdx = topLevelComma(inner);\n if (commaIdx === -1) {\n const k = inner.trim();\n return stringifyValue(Object.hasOwn(values, k) ? values[k] : undefined);\n }\n const name = inner.slice(0, commaIdx).trim();\n const rest = inner.slice(commaIdx + 1).trim();\n const secondComma = topLevelComma(rest);\n if (secondComma === -1)\n return stringifyValue(Object.hasOwn(values, name) ? values[name] : undefined);\n const type = rest.slice(0, secondComma).trim();\n const body = rest.slice(secondComma + 1).trim();\n if (type !== 'plural') {\n // Unknown formatter — fall back to raw substitution.\n return stringifyValue(Object.hasOwn(values, name) ? values[name] : undefined);\n }\n const raw = Object.hasOwn(values, name) ? values[name] : undefined;\n const n = typeof raw === 'number' ? raw : Number(raw);\n const category = Number.isFinite(n) ? pluralCategory(locale, n) : 'other';\n const branches = parsePluralBranches(body);\n const branchText =\n branches[`=${Number.isFinite(n) ? n : ''}`] ?? branches[category] ?? branches.other ?? '';\n // '#' inside the branch refers to the numeric value.\n const replaced = branchText.replace(/#/g, Number.isFinite(n) ? String(n) : '');\n // Recurse so nested `{var}` inside the branch is resolved.\n return formatMessage(replaced, values, locale);\n}\n\nfunction topLevelComma(src: string): number {\n let depth = 0;\n for (let i = 0; i < src.length; i++) {\n const c = src[i];\n if (c === '{') depth++;\n else if (c === '}') depth--;\n else if (c === ',' && depth === 0) return i;\n }\n return -1;\n}\n\nfunction parsePluralBranches(body: string): Record<string, string> {\n const out: Record<string, string> = {};\n let i = 0;\n while (i < body.length) {\n // Skip whitespace.\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') i++;\n else break;\n }\n if (i >= body.length) break;\n // Read selector until whitespace or '{'.\n const selStart = i;\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r' || ch === '{') break;\n i++;\n }\n const selector = body.slice(selStart, i);\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') i++;\n else break;\n }\n if (body[i] !== '{') break;\n const end = findMatchingClose(body, i);\n if (end === -1) break;\n out[selector] = body.slice(i + 1, end);\n i = end + 1;\n }\n return out;\n}\n\nfunction stringifyValue(v: unknown): string {\n if (v === undefined || v === null) return '';\n return String(v);\n}\n","import type { LocaleCode } from './types.js';\n\nexport interface FormatTimestampOptions {\n /** Intl.DateTimeFormat date style. Defaults to 'short'. */\n dateStyle?: 'full' | 'long' | 'medium' | 'short';\n /**\n * Intl.DateTimeFormat time style.\n *\n * Applied when explicitly provided here, or when the entire `options`\n * argument is omitted (defaults to 'short' in that case).\n * Passing an `options` object that does NOT include `timeStyle` yields a\n * date-only result — time is suppressed.\n */\n timeStyle?: 'full' | 'long' | 'medium' | 'short';\n /** Returned for ts <= 0 or on any Intl failure. Defaults to ''. */\n fallback?: string;\n}\n\n/**\n * Format a Unix timestamp (milliseconds) as a human-readable date/time string\n * using Intl.DateTimeFormat with the given locale.\n *\n * Returns `options.fallback` (default '') for ts <= 0 or on any Intl error\n * (e.g. unsupported locale on a constrained runtime). The locale is used\n * directly as the Intl BCP-47 tag.\n *\n * Safe on all target runtimes: Bun (V8), React Native Hermes (>= 0.70), web.\n */\nexport function formatTimestamp(\n ts: number,\n locale: LocaleCode,\n options?: FormatTimestampOptions,\n): string {\n const fallback = options?.fallback ?? '';\n if (ts <= 0) return fallback;\n try {\n const intlOpts: Intl.DateTimeFormatOptions = {\n dateStyle: options?.dateStyle ?? 'short',\n };\n if (options?.timeStyle !== undefined) {\n intlOpts.timeStyle = options.timeStyle;\n } else if (options === undefined) {\n intlOpts.timeStyle = 'short';\n }\n return new Intl.DateTimeFormat(locale, intlOpts).format(new Date(ts));\n } catch {\n return fallback;\n }\n}\n","import type { LocaleCode } from './types.js';\n\n/**\n * Negotiate the best locale match from a prioritized list against a set of\n * available locales. Matching is case-insensitive and considers language +\n * region. Returns the fallback when nothing matches.\n */\nexport function resolveLocale(\n requested: readonly LocaleCode[],\n available: readonly LocaleCode[],\n fallback: LocaleCode,\n): LocaleCode {\n if (available.length === 0) return fallback;\n const norm = (s: string): string => s.toLowerCase().replace(/_/g, '-');\n const avail = available.map(norm);\n\n for (const rawReq of requested) {\n const req = norm(rawReq);\n // Exact match.\n const exactIdx = avail.indexOf(req);\n if (exactIdx !== -1) return available[exactIdx] as LocaleCode;\n // Language-only match against any region variant.\n const lang = req.split('-')[0] ?? req;\n const langIdx = avail.findIndex((a) => (a.split('-')[0] ?? a) === lang);\n if (langIdx !== -1) return available[langIdx] as LocaleCode;\n }\n // Fallback — ensure it is actually present; otherwise first available.\n const fbIdx = avail.indexOf(norm(fallback));\n if (fbIdx !== -1) return available[fbIdx] as LocaleCode;\n return available[0] as LocaleCode;\n}\n","import { Signal } from '@flare-engine/events';\nimport { formatMessage } from './format.js';\nimport { resolveLocale } from './resolve.js';\nimport type { LocaleCode, MessageValues, StringTable } from './types.js';\n\nexport interface LocalizationManagerOptions {\n tables: Record<LocaleCode, StringTable>;\n initialLocale: LocaleCode;\n fallbackLocale: LocaleCode;\n}\n\n/**\n * Owns the active locale + string tables. `t(key, values?)` renders a message\n * using the active locale, falling back to the fallback locale, then the raw\n * key. `onChange` fires whenever the active locale is swapped. `setTable`\n * replaces a locale's table in place — enables hot-reload in dev.\n */\nexport class LocalizationManager {\n private _tables: Record<LocaleCode, StringTable>;\n private _locale: LocaleCode;\n private readonly _fallback: LocaleCode;\n readonly onChange = new Signal<LocaleCode>();\n\n constructor(options: LocalizationManagerOptions) {\n this._tables = { ...options.tables };\n this._fallback = options.fallbackLocale;\n this._locale = options.initialLocale;\n }\n\n get locale(): LocaleCode {\n return this._locale;\n }\n\n get fallback(): LocaleCode {\n return this._fallback;\n }\n\n availableLocales(): LocaleCode[] {\n return Object.keys(this._tables);\n }\n\n setLocale(locale: LocaleCode): void {\n if (this._locale === locale) return;\n this._locale = locale;\n this.onChange.emit(locale);\n }\n\n /** Pick the best-matching locale from the given requests and make it active. */\n negotiateLocale(requested: readonly LocaleCode[]): LocaleCode {\n const chosen = resolveLocale(requested, this.availableLocales(), this._fallback);\n this.setLocale(chosen);\n return chosen;\n }\n\n /** Replace (or install) a locale's table. Emits `onChange` if it targets the active locale. */\n setTable(locale: LocaleCode, table: StringTable): void {\n this._tables[locale] = table;\n if (locale === this._locale) this.onChange.emit(locale);\n }\n\n has(key: string): boolean {\n const active = this._tables[this._locale];\n const fallback = this._tables[this._fallback];\n return (\n (active !== undefined && Object.hasOwn(active, key)) ||\n (fallback !== undefined && Object.hasOwn(fallback, key))\n );\n }\n\n t(key: string, values?: MessageValues): string {\n const active = this._tables[this._locale];\n const fallback = this._tables[this._fallback];\n const template =\n (active !== undefined && Object.hasOwn(active, key) ? active[key] : undefined) ??\n (fallback !== undefined && Object.hasOwn(fallback, key) ? fallback[key] : undefined) ??\n key;\n return formatMessage(template, values, this._locale);\n }\n}\n"],"mappings":";;AAYA,MAAM,WAAuB,MAAO,MAAM,IAAI,QAAQ;AAEtD,MAAM,UAAsB,MAAM;CAChC,IAAI,MAAM,GAAG,OAAO;CACpB,MAAM,QAAQ,IAAI;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,SAAS,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,KAAK,OAAO;CACrE,OAAO;AACT;AAEA,MAAM,WAAuB,MAAM;CACjC,MAAM,QAAQ,IAAI;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,UAAU,KAAK,WAAW,IAAI,OAAO;CACzC,IAAI,SAAS,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,KAAK,OAAO;CACrE,IAAI,UAAU,KAAM,SAAS,KAAK,SAAS,KAAO,UAAU,MAAM,UAAU,IAAK,OAAO;CACxF,OAAO;AACT;AAEA,MAAM,UAAsB,MAAM;CAChC,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,MAAM,GAAG,OAAO;CACpB,MAAM,SAAS,IAAI;CACnB,IAAI,UAAU,KAAK,UAAU,IAAI,OAAO;CACxC,IA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AAM;EACrB,OAAO;CACT;;CAGA,SAAS,QAAoB,OAA0B;EACrD,KAAK,QAAQ,UAAU;EACvB,IAAI,WAAW,KAAK,SAAS,KAAK,SAAS,KAAK,MAAM;CACxD;CAEA,IAAI,KAAsB;EACxB,MAAM,SAAS,KAAK,QAAQ,KAAK;EACjC,MAAM,WAAW,KAAK,QAAQ,KAAK;EACnC,OACG,WAAW,KAAA,KAAa,OAAO,OAAO,QAAQ,GAAG,KACjD,aAAa,KAAA,KAAa,OAAO,OAAO,UAAU,GAAG;CAE1D;CAEA,EAAE,KAAa,QAAgC;EAC7C,MAAM,SAAS,KAAK,QAAQ,KAAK;EACjC,MAAM,WAAW,KAAK,QAAQ,KAAK;EAKnC,OAAO,eAHJ,WAAW,KAAA,KAAa,OAAO,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,KAAA,OACnE,aAAa,KAAA,KAAa,OAAO,OAAO,UAAU,GAAG,IAAI,SAAS,OAAO,KAAA,MAC1E,KAC6B,QAAQ,KAAK,OAAO;CACrD;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/plurals.ts","../src/format.ts","../src/format-timestamp.ts","../src/resolve.ts","../src/manager.ts"],"sourcesContent":["import type { LocaleCode } from './types.js';\n\n/**\n * Minimal CLDR-inspired plural classifier. Supports a handful of locales\n * natively — fall back to English rules if unknown. This is not a full ICU\n * implementation; it covers the categories used by our string tables.\n */\n\nexport type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';\n\ntype PluralRule = (n: number) => PluralCategory;\n\nconst ENGLISH: PluralRule = (n) => (n === 1 ? 'one' : 'other');\n\nconst POLISH: PluralRule = (n) => {\n if (n === 1) return 'one';\n const mod10 = n % 10;\n const mod100 = n % 100;\n if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';\n return 'many';\n};\n\nconst RUSSIAN: PluralRule = (n) => {\n const mod10 = n % 10;\n const mod100 = n % 100;\n if (mod10 === 1 && mod100 !== 11) return 'one';\n if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';\n if (mod10 === 0 || (mod10 >= 5 && mod10 <= 9) || (mod100 >= 11 && mod100 <= 14)) return 'many';\n return 'other';\n};\n\nconst ARABIC: PluralRule = (n) => {\n if (n === 0) return 'zero';\n if (n === 1) return 'one';\n if (n === 2) return 'two';\n const mod100 = n % 100;\n if (mod100 >= 3 && mod100 <= 10) return 'few';\n if (mod100 >= 11 && mod100 <= 99) return 'many';\n return 'other';\n};\n\nconst JAPANESE: PluralRule = () => 'other';\n\nconst RULES: Record<string, PluralRule> = {\n en: ENGLISH,\n de: ENGLISH,\n es: ENGLISH,\n fr: (n) => (n === 0 || n === 1 ? 'one' : 'other'),\n it: ENGLISH,\n pt: ENGLISH,\n nl: ENGLISH,\n pl: POLISH,\n ru: RUSSIAN,\n uk: RUSSIAN,\n ar: ARABIC,\n ja: JAPANESE,\n ko: JAPANESE,\n zh: JAPANESE,\n};\n\nexport function pluralCategory(locale: LocaleCode, n: number): PluralCategory {\n const lang = locale.toLowerCase().split(/[-_]/)[0] ?? 'en';\n const rule = RULES[lang] ?? ENGLISH;\n return rule(n);\n}\n","import { pluralCategory } from './plurals.js';\nimport type { LocaleCode, MessageValues } from './types.js';\n\n/**\n * Minimal ICU MessageFormat-ish parser.\n *\n * Grammar:\n * text := (chunk)*\n * chunk := literal | '{' var '}' | '{' var ',' 'plural' ',' branches '}'\n * branches := (selector '{' text '}')+\n * selector := '=' number | identifier // one | few | many | other | zero | two\n * number/ident literals inside a branch may reference '#' → the variable's number value.\n *\n * Nested plural blocks are not supported (not needed for our tables).\n */\n\nexport function formatMessage(\n template: string,\n values: MessageValues | undefined,\n locale: LocaleCode,\n): string {\n const vals = values ?? {};\n let out = '';\n let i = 0;\n const len = template.length;\n while (i < len) {\n const ch = template[i];\n if (ch !== '{') {\n out += ch;\n i++;\n continue;\n }\n // Find the matching closing brace, respecting nested braces.\n const endIdx = findMatchingClose(template, i);\n if (endIdx === -1) {\n // Malformed — emit remainder literally.\n out += template.slice(i);\n break;\n }\n const inner = template.slice(i + 1, endIdx);\n out += renderPlaceholder(inner, vals, locale);\n i = endIdx + 1;\n }\n return out;\n}\n\nfunction findMatchingClose(src: string, startBrace: number): number {\n let depth = 0;\n for (let i = startBrace; i < src.length; i++) {\n const c = src[i];\n if (c === '{') depth++;\n else if (c === '}') {\n depth--;\n if (depth === 0) return i;\n }\n }\n return -1;\n}\n\nfunction renderPlaceholder(inner: string, values: MessageValues, locale: LocaleCode): string {\n // Split only on the top-level commas into at most 3 parts: name, type, body.\n const commaIdx = topLevelComma(inner);\n if (commaIdx === -1) {\n const k = inner.trim();\n return stringifyValue(Object.hasOwn(values, k) ? values[k] : undefined);\n }\n const name = inner.slice(0, commaIdx).trim();\n const rest = inner.slice(commaIdx + 1).trim();\n const secondComma = topLevelComma(rest);\n if (secondComma === -1)\n return stringifyValue(Object.hasOwn(values, name) ? values[name] : undefined);\n const type = rest.slice(0, secondComma).trim();\n const body = rest.slice(secondComma + 1).trim();\n if (type !== 'plural') {\n // Unknown formatter — fall back to raw substitution.\n return stringifyValue(Object.hasOwn(values, name) ? values[name] : undefined);\n }\n const raw = Object.hasOwn(values, name) ? values[name] : undefined;\n const n = typeof raw === 'number' ? raw : Number(raw);\n const category = Number.isFinite(n) ? pluralCategory(locale, n) : 'other';\n const branches = parsePluralBranches(body);\n const branchText =\n branches[`=${Number.isFinite(n) ? n : ''}`] ?? branches[category] ?? branches.other ?? '';\n // '#' inside the branch refers to the numeric value.\n const replaced = branchText.replace(/#/g, Number.isFinite(n) ? String(n) : '');\n // Recurse so nested `{var}` inside the branch is resolved.\n return formatMessage(replaced, values, locale);\n}\n\nfunction topLevelComma(src: string): number {\n let depth = 0;\n for (let i = 0; i < src.length; i++) {\n const c = src[i];\n if (c === '{') depth++;\n else if (c === '}') depth--;\n else if (c === ',' && depth === 0) return i;\n }\n return -1;\n}\n\nfunction parsePluralBranches(body: string): Record<string, string> {\n const out: Record<string, string> = {};\n let i = 0;\n while (i < body.length) {\n // Skip whitespace.\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') i++;\n else break;\n }\n if (i >= body.length) break;\n // Read selector until whitespace or '{'.\n const selStart = i;\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r' || ch === '{') break;\n i++;\n }\n const selector = body.slice(selStart, i);\n while (i < body.length) {\n const ch = body[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') i++;\n else break;\n }\n if (body[i] !== '{') break;\n const end = findMatchingClose(body, i);\n if (end === -1) break;\n out[selector] = body.slice(i + 1, end);\n i = end + 1;\n }\n return out;\n}\n\nfunction stringifyValue(v: unknown): string {\n if (v === undefined || v === null) return '';\n return String(v);\n}\n","import type { LocaleCode } from './types.js';\n\nexport interface FormatTimestampOptions {\n /** Intl.DateTimeFormat date style. Defaults to 'short'. */\n dateStyle?: 'full' | 'long' | 'medium' | 'short';\n /**\n * Intl.DateTimeFormat time style.\n *\n * Applied when explicitly provided here, or when the entire `options`\n * argument is omitted (defaults to 'short' in that case).\n * Passing an `options` object that does NOT include `timeStyle` yields a\n * date-only result — time is suppressed.\n */\n timeStyle?: 'full' | 'long' | 'medium' | 'short';\n /** Returned for ts <= 0 or on any Intl failure. Defaults to ''. */\n fallback?: string;\n}\n\n/**\n * Format a Unix timestamp (milliseconds) as a human-readable date/time string\n * using Intl.DateTimeFormat with the given locale.\n *\n * Returns `options.fallback` (default '') for ts <= 0 or on any Intl error\n * (e.g. unsupported locale on a constrained runtime). The locale is used\n * directly as the Intl BCP-47 tag.\n *\n * Safe on all target runtimes: Bun (V8), React Native Hermes (>= 0.70), web.\n */\nexport function formatTimestamp(\n ts: number,\n locale: LocaleCode,\n options?: FormatTimestampOptions,\n): string {\n const fallback = options?.fallback ?? '';\n if (ts <= 0) return fallback;\n try {\n const intlOpts: Intl.DateTimeFormatOptions = {\n dateStyle: options?.dateStyle ?? 'short',\n };\n if (options?.timeStyle !== undefined) {\n intlOpts.timeStyle = options.timeStyle;\n } else if (options === undefined) {\n intlOpts.timeStyle = 'short';\n }\n return new Intl.DateTimeFormat(locale, intlOpts).format(new Date(ts));\n } catch {\n return fallback;\n }\n}\n","import type { LocaleCode } from './types.js';\n\n/**\n * Negotiate the best locale match from a prioritized list against a set of\n * available locales. Matching is case-insensitive and considers language +\n * region. Returns the fallback when nothing matches.\n */\nexport function resolveLocale(\n requested: readonly LocaleCode[],\n available: readonly LocaleCode[],\n fallback: LocaleCode,\n): LocaleCode {\n if (available.length === 0) return fallback;\n const norm = (s: string): string => s.toLowerCase().replace(/_/g, '-');\n const avail = available.map(norm);\n\n for (const rawReq of requested) {\n const req = norm(rawReq);\n // Exact match.\n const exactIdx = avail.indexOf(req);\n if (exactIdx !== -1) return available[exactIdx] as LocaleCode;\n // Language-only match against any region variant.\n const lang = req.split('-')[0] ?? req;\n const langIdx = avail.findIndex((a) => (a.split('-')[0] ?? a) === lang);\n if (langIdx !== -1) return available[langIdx] as LocaleCode;\n }\n // Fallback — ensure it is actually present; otherwise first available.\n const fbIdx = avail.indexOf(norm(fallback));\n if (fbIdx !== -1) return available[fbIdx] as LocaleCode;\n return available[0] as LocaleCode;\n}\n","import { Signal } from '@flare-engine/events';\nimport { formatMessage } from './format.js';\nimport { resolveLocale } from './resolve.js';\nimport type { LocaleCode, MessageValues, StringTable } from './types.js';\n\nexport interface LocalizationManagerOptions {\n tables: Record<LocaleCode, StringTable>;\n initialLocale: LocaleCode;\n fallbackLocale: LocaleCode;\n}\n\n/**\n * Owns the active locale + string tables. `t(key, values?)` renders a message\n * using the active locale, falling back to the fallback locale, then the raw\n * key. `onChange` fires whenever the active locale is swapped. `setTable`\n * replaces a locale's table in place — enables hot-reload in dev.\n */\nexport class LocalizationManager {\n private _tables: Record<LocaleCode, StringTable>;\n private _locale: LocaleCode;\n private readonly _fallback: LocaleCode;\n readonly onChange = new Signal<LocaleCode>();\n\n constructor(options: LocalizationManagerOptions) {\n this._tables = { ...options.tables };\n this._fallback = options.fallbackLocale;\n this._locale = options.initialLocale;\n }\n\n get locale(): LocaleCode {\n return this._locale;\n }\n\n get fallback(): LocaleCode {\n return this._fallback;\n }\n\n availableLocales(): LocaleCode[] {\n return Object.keys(this._tables);\n }\n\n setLocale(locale: LocaleCode): void {\n if (this._locale === locale) return;\n this._locale = locale;\n this.onChange.emit(locale);\n }\n\n /** Pick the best-matching locale from the given requests and make it active. */\n negotiateLocale(requested: readonly LocaleCode[]): LocaleCode {\n const chosen = resolveLocale(requested, this.availableLocales(), this._fallback);\n this.setLocale(chosen);\n return chosen;\n }\n\n /** Replace (or install) a locale's table. Emits `onChange` if it targets the active locale. */\n setTable(locale: LocaleCode, table: StringTable): void {\n this._tables[locale] = table;\n if (locale === this._locale) this.onChange.emit(locale);\n }\n\n has(key: string): boolean {\n const active = this._tables[this._locale];\n const fallback = this._tables[this._fallback];\n return (\n (active !== undefined && Object.hasOwn(active, key)) ||\n (fallback !== undefined && Object.hasOwn(fallback, key))\n );\n }\n\n t(key: string, values?: MessageValues): string {\n const active = this._tables[this._locale];\n const fallback = this._tables[this._fallback];\n const template =\n (active !== undefined && Object.hasOwn(active, key) ? active[key] : undefined) ??\n (fallback !== undefined && Object.hasOwn(fallback, key) ? fallback[key] : undefined) ??\n key;\n return formatMessage(template, values, this._locale);\n }\n}\n"],"mappings":";;AAYA,MAAM,WAAuB,MAAO,MAAM,IAAI,QAAQ;AAEtD,MAAM,UAAsB,MAAM;CAChC,IAAI,MAAM,GAAG,OAAO;CACpB,MAAM,QAAQ,IAAI;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,SAAS,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,KAAK,OAAO;CACrE,OAAO;AACT;AAEA,MAAM,WAAuB,MAAM;CACjC,MAAM,QAAQ,IAAI;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,U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,UAAU,QAAQ;CACzB;CAEA,IAAI,SAAqB;EACvB,OAAO,KAAK;CACd;CAEA,IAAI,WAAuB;EACzB,OAAO,KAAK;CACd;CAEA,mBAAiC;EAC/B,OAAO,OAAO,KAAK,KAAK,OAAO;CACjC;CAEA,UAAU,QAA0B;EAClC,IAAI,KAAK,YAAY,QAAQ;EAC7B,KAAK,UAAU;EACf,KAAK,SAAS,KAAK,MAAM;CAC3B;;CAGA,gBAAgB,WAA8C;EAC5D,MAAM,SAAS,cAAc,WAAW,KAAK,iBAAiB,GAAG,KAAK,SAAS;EAC/E,KAAK,UAAU,MAAM;EACrB,OAAO;CACT;;CAGA,SAAS,QAAoB,OAA0B;EACrD,KAAK,QAAQ,UAAU;EACvB,IAAI,WAAW,KAAK,SAAS,KAAK,SAAS,KAAK,MAAM;CACxD;CAEA,IAAI,KAAsB;EACxB,MAAM,SAAS,KAAK,QAAQ,KAAK;EACjC,MAAM,WAAW,KAAK,QAAQ,KAAK;EACnC,OACG,WAAW,KAAA,KAAa,OAAO,OAAO,QAAQ,GAAG,KACjD,aAAa,KAAA,KAAa,OAAO,OAAO,UAAU,GAAG;CAE1D;CAEA,EAAE,KAAa,QAAgC;EAC7C,MAAM,SAAS,KAAK,QAAQ,KAAK;EACjC,MAAM,WAAW,KAAK,QAAQ,KAAK;EAKnC,OAAO,eAHJ,WAAW,KAAA,KAAa,OAAO,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,KAAA,OACnE,aAAa,KAAA,KAAa,OAAO,OAAO,UAAU,GAAG,IAAI,SAAS,OAAO,KAAA,MAC1E,KAC6B,QAAQ,KAAK,OAAO;CACrD;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/localization",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "String tables, locale resolution, ICU-style plurals + interpolation",
|
|
5
5
|
"keywords": ["flare-engine", "localization", "i18n", "icu", "plurals"],
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@flare-engine/events": "^0.4.
|
|
40
|
+
"@flare-engine/events": "^0.4.7"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=20"
|