@flare-engine/localization 0.2.1 → 0.3.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/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +8 -3
- package/dist/index.d.mts +67 -61
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +67 -61
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +246 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +241 -218
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -8
package/dist/index.js
CHANGED
|
@@ -1,273 +1,270 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _flare_engine_events = require("@flare-engine/events");
|
|
3
|
+
//#region src/plurals.ts
|
|
4
|
+
const ENGLISH = (n) => n === 1 ? "one" : "other";
|
|
5
|
+
const POLISH = (n) => {
|
|
6
|
+
if (n === 1) return "one";
|
|
7
|
+
const mod10 = n % 10;
|
|
8
|
+
const mod100 = n % 100;
|
|
9
|
+
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return "few";
|
|
10
|
+
return "many";
|
|
9
11
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const RUSSIAN = (n) => {
|
|
13
|
+
const mod10 = n % 10;
|
|
14
|
+
const mod100 = n % 100;
|
|
15
|
+
if (mod10 === 1 && mod100 !== 11) return "one";
|
|
16
|
+
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return "few";
|
|
17
|
+
if (mod10 === 0 || mod10 >= 5 && mod10 <= 9 || mod100 >= 11 && mod100 <= 14) return "many";
|
|
18
|
+
return "other";
|
|
17
19
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
pluralCategory: () => pluralCategory,
|
|
27
|
-
resolveLocale: () => resolveLocale
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(index_exports);
|
|
30
|
-
|
|
31
|
-
// src/plurals.ts
|
|
32
|
-
var ENGLISH = (n) => n === 1 ? "one" : "other";
|
|
33
|
-
var POLISH = (n) => {
|
|
34
|
-
if (n === 1) return "one";
|
|
35
|
-
const mod10 = n % 10;
|
|
36
|
-
const mod100 = n % 100;
|
|
37
|
-
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return "few";
|
|
38
|
-
return "many";
|
|
39
|
-
};
|
|
40
|
-
var RUSSIAN = (n) => {
|
|
41
|
-
const mod10 = n % 10;
|
|
42
|
-
const mod100 = n % 100;
|
|
43
|
-
if (mod10 === 1 && mod100 !== 11) return "one";
|
|
44
|
-
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return "few";
|
|
45
|
-
if (mod10 === 0 || mod10 >= 5 && mod10 <= 9 || mod100 >= 11 && mod100 <= 14) return "many";
|
|
46
|
-
return "other";
|
|
20
|
+
const ARABIC = (n) => {
|
|
21
|
+
if (n === 0) return "zero";
|
|
22
|
+
if (n === 1) return "one";
|
|
23
|
+
if (n === 2) return "two";
|
|
24
|
+
const mod100 = n % 100;
|
|
25
|
+
if (mod100 >= 3 && mod100 <= 10) return "few";
|
|
26
|
+
if (mod100 >= 11 && mod100 <= 99) return "many";
|
|
27
|
+
return "other";
|
|
47
28
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
pt: ENGLISH,
|
|
65
|
-
nl: ENGLISH,
|
|
66
|
-
pl: POLISH,
|
|
67
|
-
ru: RUSSIAN,
|
|
68
|
-
uk: RUSSIAN,
|
|
69
|
-
ar: ARABIC,
|
|
70
|
-
ja: JAPANESE,
|
|
71
|
-
ko: JAPANESE,
|
|
72
|
-
zh: JAPANESE
|
|
29
|
+
const JAPANESE = () => "other";
|
|
30
|
+
const RULES = {
|
|
31
|
+
en: ENGLISH,
|
|
32
|
+
de: ENGLISH,
|
|
33
|
+
es: ENGLISH,
|
|
34
|
+
fr: (n) => n === 0 || n === 1 ? "one" : "other",
|
|
35
|
+
it: ENGLISH,
|
|
36
|
+
pt: ENGLISH,
|
|
37
|
+
nl: ENGLISH,
|
|
38
|
+
pl: POLISH,
|
|
39
|
+
ru: RUSSIAN,
|
|
40
|
+
uk: RUSSIAN,
|
|
41
|
+
ar: ARABIC,
|
|
42
|
+
ja: JAPANESE,
|
|
43
|
+
ko: JAPANESE,
|
|
44
|
+
zh: JAPANESE
|
|
73
45
|
};
|
|
74
46
|
function pluralCategory(locale, n) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return rule(n);
|
|
47
|
+
const lang = locale.toLowerCase().split(/[-_]/)[0] ?? "en";
|
|
48
|
+
return (RULES[lang] ?? ENGLISH)(n);
|
|
78
49
|
}
|
|
79
|
-
|
|
80
|
-
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/format.ts
|
|
52
|
+
/**
|
|
53
|
+
* Minimal ICU MessageFormat-ish parser.
|
|
54
|
+
*
|
|
55
|
+
* Grammar:
|
|
56
|
+
* text := (chunk)*
|
|
57
|
+
* chunk := literal | '{' var '}' | '{' var ',' 'plural' ',' branches '}'
|
|
58
|
+
* branches := (selector '{' text '}')+
|
|
59
|
+
* selector := '=' number | identifier // one | few | many | other | zero | two
|
|
60
|
+
* number/ident literals inside a branch may reference '#' → the variable's number value.
|
|
61
|
+
*
|
|
62
|
+
* Nested plural blocks are not supported (not needed for our tables).
|
|
63
|
+
*/
|
|
81
64
|
function formatMessage(template, values, locale) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
65
|
+
const vals = values ?? {};
|
|
66
|
+
let out = "";
|
|
67
|
+
let i = 0;
|
|
68
|
+
const len = template.length;
|
|
69
|
+
while (i < len) {
|
|
70
|
+
const ch = template[i];
|
|
71
|
+
if (ch !== "{") {
|
|
72
|
+
out += ch;
|
|
73
|
+
i++;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const endIdx = findMatchingClose(template, i);
|
|
77
|
+
if (endIdx === -1) {
|
|
78
|
+
out += template.slice(i);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
const inner = template.slice(i + 1, endIdx);
|
|
82
|
+
out += renderPlaceholder(inner, vals, locale);
|
|
83
|
+
i = endIdx + 1;
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
103
86
|
}
|
|
104
87
|
function findMatchingClose(src, startBrace) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
88
|
+
let depth = 0;
|
|
89
|
+
for (let i = startBrace; i < src.length; i++) {
|
|
90
|
+
const c = src[i];
|
|
91
|
+
if (c === "{") depth++;
|
|
92
|
+
else if (c === "}") {
|
|
93
|
+
depth--;
|
|
94
|
+
if (depth === 0) return i;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return -1;
|
|
115
98
|
}
|
|
116
99
|
function renderPlaceholder(inner, values, locale) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const branchText = branches[`=${Number.isFinite(n) ? n : ""}`] ?? branches[category] ?? branches.other ?? "";
|
|
135
|
-
const replaced = branchText.replace(/#/g, Number.isFinite(n) ? String(n) : "");
|
|
136
|
-
return formatMessage(replaced, values, locale);
|
|
100
|
+
const commaIdx = topLevelComma(inner);
|
|
101
|
+
if (commaIdx === -1) {
|
|
102
|
+
const k = inner.trim();
|
|
103
|
+
return stringifyValue(Object.hasOwn(values, k) ? values[k] : void 0);
|
|
104
|
+
}
|
|
105
|
+
const name = inner.slice(0, commaIdx).trim();
|
|
106
|
+
const rest = inner.slice(commaIdx + 1).trim();
|
|
107
|
+
const secondComma = topLevelComma(rest);
|
|
108
|
+
if (secondComma === -1) return stringifyValue(Object.hasOwn(values, name) ? values[name] : void 0);
|
|
109
|
+
const type = rest.slice(0, secondComma).trim();
|
|
110
|
+
const body = rest.slice(secondComma + 1).trim();
|
|
111
|
+
if (type !== "plural") return stringifyValue(Object.hasOwn(values, name) ? values[name] : void 0);
|
|
112
|
+
const raw = Object.hasOwn(values, name) ? values[name] : void 0;
|
|
113
|
+
const n = typeof raw === "number" ? raw : Number(raw);
|
|
114
|
+
const category = Number.isFinite(n) ? pluralCategory(locale, n) : "other";
|
|
115
|
+
const branches = parsePluralBranches(body);
|
|
116
|
+
return formatMessage((branches[`=${Number.isFinite(n) ? n : ""}`] ?? branches[category] ?? branches.other ?? "").replace(/#/g, Number.isFinite(n) ? String(n) : ""), values, locale);
|
|
137
117
|
}
|
|
138
118
|
function topLevelComma(src) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
119
|
+
let depth = 0;
|
|
120
|
+
for (let i = 0; i < src.length; i++) {
|
|
121
|
+
const c = src[i];
|
|
122
|
+
if (c === "{") depth++;
|
|
123
|
+
else if (c === "}") depth--;
|
|
124
|
+
else if (c === "," && depth === 0) return i;
|
|
125
|
+
}
|
|
126
|
+
return -1;
|
|
147
127
|
}
|
|
148
128
|
function parsePluralBranches(body) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
129
|
+
const out = {};
|
|
130
|
+
let i = 0;
|
|
131
|
+
while (i < body.length) {
|
|
132
|
+
while (i < body.length) {
|
|
133
|
+
const ch = body[i];
|
|
134
|
+
if (ch === " " || ch === " " || ch === "\n" || ch === "\r") i++;
|
|
135
|
+
else break;
|
|
136
|
+
}
|
|
137
|
+
if (i >= body.length) break;
|
|
138
|
+
const selStart = i;
|
|
139
|
+
while (i < body.length) {
|
|
140
|
+
const ch = body[i];
|
|
141
|
+
if (ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "{") break;
|
|
142
|
+
i++;
|
|
143
|
+
}
|
|
144
|
+
const selector = body.slice(selStart, i);
|
|
145
|
+
while (i < body.length) {
|
|
146
|
+
const ch = body[i];
|
|
147
|
+
if (ch === " " || ch === " " || ch === "\n" || ch === "\r") i++;
|
|
148
|
+
else break;
|
|
149
|
+
}
|
|
150
|
+
if (body[i] !== "{") break;
|
|
151
|
+
const end = findMatchingClose(body, i);
|
|
152
|
+
if (end === -1) break;
|
|
153
|
+
out[selector] = body.slice(i + 1, end);
|
|
154
|
+
i = end + 1;
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
177
157
|
}
|
|
178
158
|
function stringifyValue(v) {
|
|
179
|
-
|
|
180
|
-
|
|
159
|
+
if (v === void 0 || v === null) return "";
|
|
160
|
+
return String(v);
|
|
181
161
|
}
|
|
182
|
-
|
|
183
|
-
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/format-timestamp.ts
|
|
164
|
+
/**
|
|
165
|
+
* Format a Unix timestamp (milliseconds) as a human-readable date/time string
|
|
166
|
+
* using Intl.DateTimeFormat with the given locale.
|
|
167
|
+
*
|
|
168
|
+
* Returns `options.fallback` (default '') for ts <= 0 or on any Intl error
|
|
169
|
+
* (e.g. unsupported locale on a constrained runtime). The locale is used
|
|
170
|
+
* directly as the Intl BCP-47 tag.
|
|
171
|
+
*
|
|
172
|
+
* Safe on all target runtimes: Bun (V8), React Native Hermes (>= 0.70), web.
|
|
173
|
+
*/
|
|
174
|
+
function formatTimestamp(ts, locale, options) {
|
|
175
|
+
const fallback = options?.fallback ?? "";
|
|
176
|
+
if (ts <= 0) return fallback;
|
|
177
|
+
try {
|
|
178
|
+
const intlOpts = { dateStyle: options?.dateStyle ?? "short" };
|
|
179
|
+
if (options?.timeStyle !== void 0) intlOpts.timeStyle = options.timeStyle;
|
|
180
|
+
else if (options === void 0) intlOpts.timeStyle = "short";
|
|
181
|
+
return new Intl.DateTimeFormat(locale, intlOpts).format(new Date(ts));
|
|
182
|
+
} catch {
|
|
183
|
+
return fallback;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/resolve.ts
|
|
188
|
+
/**
|
|
189
|
+
* Negotiate the best locale match from a prioritized list against a set of
|
|
190
|
+
* available locales. Matching is case-insensitive and considers language +
|
|
191
|
+
* region. Returns the fallback when nothing matches.
|
|
192
|
+
*/
|
|
184
193
|
function resolveLocale(requested, available, fallback) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
if (available.length === 0) return fallback;
|
|
195
|
+
const norm = (s) => s.toLowerCase().replace(/_/g, "-");
|
|
196
|
+
const avail = available.map(norm);
|
|
197
|
+
for (const rawReq of requested) {
|
|
198
|
+
const req = norm(rawReq);
|
|
199
|
+
const exactIdx = avail.indexOf(req);
|
|
200
|
+
if (exactIdx !== -1) return available[exactIdx];
|
|
201
|
+
const lang = req.split("-")[0] ?? req;
|
|
202
|
+
const langIdx = avail.findIndex((a) => (a.split("-")[0] ?? a) === lang);
|
|
203
|
+
if (langIdx !== -1) return available[langIdx];
|
|
204
|
+
}
|
|
205
|
+
const fbIdx = avail.indexOf(norm(fallback));
|
|
206
|
+
if (fbIdx !== -1) return available[fbIdx];
|
|
207
|
+
return available[0];
|
|
199
208
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/manager.ts
|
|
211
|
+
/**
|
|
212
|
+
* Owns the active locale + string tables. `t(key, values?)` renders a message
|
|
213
|
+
* using the active locale, falling back to the fallback locale, then the raw
|
|
214
|
+
* key. `onChange` fires whenever the active locale is swapped. `setTable`
|
|
215
|
+
* replaces a locale's table in place — enables hot-reload in dev.
|
|
216
|
+
*/
|
|
203
217
|
var LocalizationManager = class {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
218
|
+
_tables;
|
|
219
|
+
_locale;
|
|
220
|
+
_fallback;
|
|
221
|
+
onChange = new _flare_engine_events.Signal();
|
|
222
|
+
constructor(options) {
|
|
223
|
+
this._tables = { ...options.tables };
|
|
224
|
+
this._fallback = options.fallbackLocale;
|
|
225
|
+
this._locale = options.initialLocale;
|
|
226
|
+
}
|
|
227
|
+
get locale() {
|
|
228
|
+
return this._locale;
|
|
229
|
+
}
|
|
230
|
+
get fallback() {
|
|
231
|
+
return this._fallback;
|
|
232
|
+
}
|
|
233
|
+
availableLocales() {
|
|
234
|
+
return Object.keys(this._tables);
|
|
235
|
+
}
|
|
236
|
+
setLocale(locale) {
|
|
237
|
+
if (this._locale === locale) return;
|
|
238
|
+
this._locale = locale;
|
|
239
|
+
this.onChange.emit(locale);
|
|
240
|
+
}
|
|
241
|
+
/** Pick the best-matching locale from the given requests and make it active. */
|
|
242
|
+
negotiateLocale(requested) {
|
|
243
|
+
const chosen = resolveLocale(requested, this.availableLocales(), this._fallback);
|
|
244
|
+
this.setLocale(chosen);
|
|
245
|
+
return chosen;
|
|
246
|
+
}
|
|
247
|
+
/** Replace (or install) a locale's table. Emits `onChange` if it targets the active locale. */
|
|
248
|
+
setTable(locale, table) {
|
|
249
|
+
this._tables[locale] = table;
|
|
250
|
+
if (locale === this._locale) this.onChange.emit(locale);
|
|
251
|
+
}
|
|
252
|
+
has(key) {
|
|
253
|
+
const active = this._tables[this._locale];
|
|
254
|
+
const fallback = this._tables[this._fallback];
|
|
255
|
+
return active !== void 0 && Object.hasOwn(active, key) || fallback !== void 0 && Object.hasOwn(fallback, key);
|
|
256
|
+
}
|
|
257
|
+
t(key, values) {
|
|
258
|
+
const active = this._tables[this._locale];
|
|
259
|
+
const fallback = this._tables[this._fallback];
|
|
260
|
+
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
|
+
}
|
|
245
262
|
};
|
|
263
|
+
//#endregion
|
|
264
|
+
exports.LocalizationManager = LocalizationManager;
|
|
265
|
+
exports.formatMessage = formatMessage;
|
|
266
|
+
exports.formatTimestamp = formatTimestamp;
|
|
267
|
+
exports.pluralCategory = pluralCategory;
|
|
268
|
+
exports.resolveLocale = resolveLocale;
|
|
246
269
|
|
|
247
|
-
// src/format-timestamp.ts
|
|
248
|
-
function formatTimestamp(ts, locale, options) {
|
|
249
|
-
const fallback = options?.fallback ?? "";
|
|
250
|
-
if (ts <= 0) return fallback;
|
|
251
|
-
try {
|
|
252
|
-
const intlOpts = {
|
|
253
|
-
dateStyle: options?.dateStyle ?? "short"
|
|
254
|
-
};
|
|
255
|
-
if (options?.timeStyle !== void 0) {
|
|
256
|
-
intlOpts.timeStyle = options.timeStyle;
|
|
257
|
-
} else if (options === void 0) {
|
|
258
|
-
intlOpts.timeStyle = "short";
|
|
259
|
-
}
|
|
260
|
-
return new Intl.DateTimeFormat(locale, intlOpts).format(new Date(ts));
|
|
261
|
-
} catch {
|
|
262
|
-
return fallback;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
266
|
-
0 && (module.exports = {
|
|
267
|
-
LocalizationManager,
|
|
268
|
-
formatMessage,
|
|
269
|
-
formatTimestamp,
|
|
270
|
-
pluralCategory,
|
|
271
|
-
resolveLocale
|
|
272
|
-
});
|
|
273
270
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/plurals.ts","../src/format.ts","../src/resolve.ts","../src/manager.ts","../src/format-timestamp.ts"],"sourcesContent":["export type { LocaleCode, MessageValue, MessageValues, StringTable } from './types.js';\nexport { type PluralCategory, pluralCategory } from './plurals.js';\nexport { formatMessage } from './format.js';\nexport { resolveLocale } from './resolve.js';\nexport { LocalizationManager, type LocalizationManagerOptions } from './manager.js';\nexport { formatTimestamp, type FormatTimestampOptions } from './format-timestamp.js';\n","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 return stringifyValue(values[inner.trim()]);\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) return stringifyValue(values[name]);\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(values[name]);\n }\n const raw = values[name];\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\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 return (\n this._tables[this._locale]?.[key] !== undefined ||\n this._tables[this._fallback]?.[key] !== undefined\n );\n }\n\n t(key: string, values?: MessageValues): string {\n const template =\n this._tables[this._locale]?.[key] ?? this._tables[this._fallback]?.[key] ?? key;\n return formatMessage(template, values, this._locale);\n }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYA,IAAM,UAAsB,CAAC,MAAO,MAAM,IAAI,QAAQ;AAEtD,IAAM,SAAqB,CAAC,MAAM;AAChC,MAAI,MAAM,EAAG,QAAO;AACpB,QAAM,QAAQ,IAAI;AAClB,QAAM,SAAS,IAAI;AACnB,MAAI,SAAS,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,IAAK,QAAO;AACrE,SAAO;AACT;AAEA,IAAM,UAAsB,CAAC,MAAM;AACjC,QAAM,QAAQ,IAAI;AAClB,QAAM,SAAS,IAAI;AACnB,MAAI,UAAU,KAAK,WAAW,GAAI,QAAO;AACzC,MAAI,SAAS,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,IAAK,QAAO;AACrE,MAAI,UAAU,KAAM,SAAS,KAAK,SAAS,KAAO,UAAU,MAAM,UAAU,GAAK,QAAO;AACxF,SAAO;AACT;AAEA,IAAM,SAAqB,CAAC,MAAM;AAChC,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,MAAM,EAAG,QAAO;AACpB,QAAM,SAAS,IAAI;AACnB,MAAI,UAAU,KAAK,UAAU,GAAI,QAAO;AACxC,MAAI,UAAU,MAAM,UAAU,GAAI,QAAO;AACzC,SAAO;AACT;AAEA,IAAM,WAAuB,MAAM;AAEnC,IAAM,QAAoC;AAAA,EACxC,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI,CAAC,MAAO,MAAM,KAAK,MAAM,IAAI,QAAQ;AAAA,EACzC,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,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,QAAQ,KAAK,OAAO;AAAA,EACrD;AACF;;;AC5CO,SAAS,gBACd,IACA,QACA,SACQ;AACR,QAAM,WAAW,SAAS,YAAY;AACtC,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI;AACF,UAAM,WAAuC;AAAA,MAC3C,WAAW,SAAS,aAAa;AAAA,IACnC;AACA,QAAI,SAAS,cAAc,QAAW;AACpC,eAAS,YAAY,QAAQ;AAAA,IAC/B,WAAW,YAAY,QAAW;AAChC,eAAS,YAAY;AAAA,IACvB;AACA,WAAO,IAAI,KAAK,eAAe,QAAQ,QAAQ,EAAE,OAAO,IAAI,KAAK,EAAE,CAAC;AAAA,EACtE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
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;A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