@zerolith/i18n 0.1.0-alpha.1 → 0.1.0-alpha.10
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/README.md +8 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +66 -8
- package/dist/cli.js.map +1 -1
- package/dist/compile.d.ts +6 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +179 -85
- package/dist/compile.js.map +1 -1
- package/dist/index.d.ts +14 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -14
- package/dist/index.js.map +1 -1
- package/dist/production/compile.js +167 -0
- package/dist/production/compile.js.map +1 -0
- package/dist/production/index.js +2 -0
- package/dist/production/index.js.map +1 -0
- package/package.json +9 -7
- package/src/cli.ts +87 -8
- package/src/compile.ts +203 -86
- package/src/index.ts +43 -16
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
import { type ReadableSignal } from "zerolith";
|
|
11
11
|
/** One entry of an `Accept-Language` header or of `navigator.languages`. */
|
|
12
12
|
export interface LanguageRange {
|
|
13
|
+
/** The language tag, or `*` for any language, as written before any `;` parameters. */
|
|
13
14
|
readonly range: string;
|
|
15
|
+
/** The entry's `q` weight between 0 and 1, rounded to three decimals; 1 when the entry gives none. */
|
|
14
16
|
readonly quality: number;
|
|
15
17
|
}
|
|
16
18
|
/** Parses an `Accept-Language` header into ranges ordered by quality, dropping those with quality zero. */
|
|
@@ -20,16 +22,18 @@ export declare function parseAcceptLanguage(header: string | null | undefined):
|
|
|
20
22
|
* `Accept-Language` header, `navigator.languages`, or one tag. Each range
|
|
21
23
|
* is tried in order of quality, first as an exact match, then by dropping
|
|
22
24
|
* subtags from the end as RFC 4647 lookup does, then as the language of a
|
|
23
|
-
* more specific supported locale
|
|
25
|
+
* more specific supported locale, preferring one written in the same
|
|
26
|
+
* script, so `zh-HK` finds `zh-TW` before `zh-CN`. `*` and no match at all
|
|
27
|
+
* give `fallback`.
|
|
24
28
|
*/
|
|
25
29
|
export declare function negotiateLocale(requested: string | readonly string[] | null | undefined, supported: readonly string[], fallback: string): string;
|
|
26
|
-
/** The writing direction of a locale, from `Intl.Locale` where the engine provides it and from
|
|
30
|
+
/** The writing direction of a locale, from `Intl.Locale` where the engine provides it and otherwise from its script, the likely one when the tag names none, as engines decide. */
|
|
27
31
|
export declare function localeDirection(locale: string): "ltr" | "rtl";
|
|
28
32
|
/** Options for `createLocale`. */
|
|
29
33
|
export interface LocaleOptions {
|
|
30
34
|
/** The locales the application ships, most preferred first. */
|
|
31
35
|
supported: readonly string[];
|
|
32
|
-
/** The locale used when nothing matches
|
|
36
|
+
/** The locale used when nothing matches, one of `supported`. Defaults to the first supported one. */
|
|
33
37
|
fallback?: string;
|
|
34
38
|
/** What to negotiate from at first: an `Accept-Language` header, `navigator.languages`, or a tag. Defaults to the fallback. */
|
|
35
39
|
initial?: string | readonly string[] | null;
|
|
@@ -40,20 +44,26 @@ export interface LocaleState {
|
|
|
40
44
|
readonly locale: ReadableSignal<string>;
|
|
41
45
|
/** The writing direction of the current locale. */
|
|
42
46
|
readonly direction: ReadableSignal<"ltr" | "rtl">;
|
|
47
|
+
/** A copy of the `supported` option, in the same order; `set` negotiates against it. */
|
|
43
48
|
readonly supported: readonly string[];
|
|
44
49
|
/** Switches locales after negotiating the request against `supported`. */
|
|
45
50
|
set(requested: string | readonly string[]): void;
|
|
46
51
|
}
|
|
47
|
-
/** Creates the locale state for an application. */
|
|
52
|
+
/** Creates the locale state for an application. Throws a `TypeError` when `supported` is empty or `fallback` is not one of its locales, since the locale must always be one of them. */
|
|
48
53
|
export declare function createLocale(options: LocaleOptions): LocaleState;
|
|
49
54
|
/** Keeps the document's `lang` and `dir` attributes in step with the locale; returns the effect's disposer. */
|
|
50
55
|
export declare function applyLocale(state: LocaleState, doc?: Document): () => void;
|
|
51
56
|
/** Formatters for the current locale; each reads the locale signal when called, so a computed value or template re-renders on a locale change. */
|
|
52
57
|
export interface Formatters {
|
|
58
|
+
/** Formats a number with `Intl.NumberFormat`. */
|
|
53
59
|
number(value: number, options?: Intl.NumberFormatOptions): string;
|
|
60
|
+
/** Formats a `Date`, or a timestamp in milliseconds since the epoch, with `Intl.DateTimeFormat`. */
|
|
54
61
|
date(value: Date | number, options?: Intl.DateTimeFormatOptions): string;
|
|
62
|
+
/** Formats a time `value` units of `unit` away from now with `Intl.RelativeTimeFormat`, such as `in 2 hours`; a negative value lies in the past. */
|
|
55
63
|
relative(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string;
|
|
64
|
+
/** Joins strings into a list with `Intl.ListFormat`, such as `a, b, and c` in English. */
|
|
56
65
|
list(values: Iterable<string>, options?: Intl.ListFormatOptions): string;
|
|
66
|
+
/** Selects the plural category of a number with `Intl.PluralRules`, such as `one` or `other`, for choosing a message variant. */
|
|
57
67
|
plural(value: number, options?: Intl.PluralRulesOptions): Intl.LDMLPluralRule;
|
|
58
68
|
}
|
|
59
69
|
/** Creates formatters over a locale, given as a signal or as a fixed tag. Instances are cached per locale and options. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,cAAc,EAAyC,MAAM,UAAU,CAAC;AAEtF,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAE1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,2GAA2G;AAC3G,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,aAAa,EAAE,CA+BtF;AAcD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,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wL;AACxL,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAsBhE;AAED,+GAA+G;AAC/G,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,GAAE,QAAmB,GAAG,MAAM,IAAI,CAOpF;AAED,kJAAkJ;AAClJ,MAAM,WAAW,UAAU;IAEvB,iDAAiD;IACjD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;IAClE,oGAAoG;IACpG,IAAI,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;IACzE,oJAAoJ;IACpJ,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,yBAAyB,GAAG,MAAM,CAAC;IAC7G,0FAA0F;IAC1F,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC;IACzE,iIAAiI;IACjI,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC;CACjF;AAgBD,0HAA0H;AAC1H,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,UAAU,CAU9E"}
|
package/dist/index.js
CHANGED
|
@@ -47,7 +47,9 @@ function canonical(tag) {
|
|
|
47
47
|
* `Accept-Language` header, `navigator.languages`, or one tag. Each range
|
|
48
48
|
* is tried in order of quality, first as an exact match, then by dropping
|
|
49
49
|
* subtags from the end as RFC 4647 lookup does, then as the language of a
|
|
50
|
-
* more specific supported locale
|
|
50
|
+
* more specific supported locale, preferring one written in the same
|
|
51
|
+
* script, so `zh-HK` finds `zh-TW` before `zh-CN`. `*` and no match at all
|
|
52
|
+
* give `fallback`.
|
|
51
53
|
*/
|
|
52
54
|
export function negotiateLocale(requested, supported, fallback) {
|
|
53
55
|
const ranges = typeof requested === "string" ? parseAcceptLanguage(requested).map((entry) => entry.range) : [...(requested ?? [])];
|
|
@@ -64,15 +66,26 @@ export function negotiateLocale(requested, supported, fallback) {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
const language = wanted.split("-")[0] ?? wanted;
|
|
67
|
-
const related = candidates.
|
|
68
|
-
if (related
|
|
69
|
-
|
|
69
|
+
const related = candidates.filter((candidate) => candidate.lower.startsWith(`${language}-`));
|
|
70
|
+
if (related.length > 0) {
|
|
71
|
+
const script = scriptOf(range);
|
|
72
|
+
return (related.find((candidate) => scriptOf(candidate.tag) === script) ?? related[0])?.tag ?? fallback;
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
return fallback;
|
|
73
76
|
}
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
/** The script a locale is written in, with the likely script filled in, as `Hant` for `zh-TW`; undefined for a tag that does not parse. */
|
|
78
|
+
function scriptOf(tag) {
|
|
79
|
+
try {
|
|
80
|
+
return new Intl.Locale(tag).maximize().script;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** The scripts written right to left, by their ISO 15924 codes in lowercase. */
|
|
87
|
+
const RTL_SCRIPTS = new Set(["adlm", "arab", "hebr", "mand", "mend", "nkoo", "rohg", "samr", "syrc", "thaa", "yezi"]);
|
|
88
|
+
/** The writing direction of a locale, from `Intl.Locale` where the engine provides it and otherwise from its script, the likely one when the tag names none, as engines decide. */
|
|
76
89
|
export function localeDirection(locale) {
|
|
77
90
|
try {
|
|
78
91
|
const parsed = new Intl.Locale(locale);
|
|
@@ -81,21 +94,22 @@ export function localeDirection(locale) {
|
|
|
81
94
|
if (info !== undefined) {
|
|
82
95
|
return info.direction === "rtl" ? "rtl" : "ltr";
|
|
83
96
|
}
|
|
84
|
-
|
|
85
|
-
const script = parsed.script?.toLowerCase();
|
|
86
|
-
if (script === "arab" || script === "hebr" || script === "thaa" || script === "syrc" || script === "nkoo") {
|
|
87
|
-
return "rtl";
|
|
88
|
-
}
|
|
89
|
-
return RTL_LANGUAGES.has(language) || RTL_LANGUAGES.has(`${language}-${script ?? ""}`) ? "rtl" : "ltr";
|
|
97
|
+
return RTL_SCRIPTS.has((parsed.maximize().script ?? "").toLowerCase()) ? "rtl" : "ltr";
|
|
90
98
|
}
|
|
91
99
|
catch {
|
|
92
100
|
return "ltr";
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
|
-
/** Creates the locale state for an application. */
|
|
103
|
+
/** Creates the locale state for an application. Throws a `TypeError` when `supported` is empty or `fallback` is not one of its locales, since the locale must always be one of them. */
|
|
96
104
|
export function createLocale(options) {
|
|
97
105
|
const supported = [...options.supported];
|
|
98
|
-
|
|
106
|
+
if (supported.length === 0) {
|
|
107
|
+
throw new TypeError("zerolith/i18n: createLocale needs at least one supported locale");
|
|
108
|
+
}
|
|
109
|
+
const fallback = options.fallback === undefined ? (supported[0] ?? "") : supported.find((tag) => canonical(tag).toLowerCase() === canonical(options.fallback ?? "").toLowerCase());
|
|
110
|
+
if (fallback === undefined) {
|
|
111
|
+
throw new TypeError(`zerolith/i18n: the fallback ${options.fallback ?? ""} is not one of the supported locales, ${supported.join(", ")}`);
|
|
112
|
+
}
|
|
99
113
|
const locale = signal(negotiateLocale(options.initial ?? fallback, supported, fallback), { name: "locale" });
|
|
100
114
|
return {
|
|
101
115
|
locale,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAoC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MA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,MAAM,CAAC,KAAK,CAAC;QAC/H,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAC7H,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC;QACrJ,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;QAC3H,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;KACjI,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
class e{index=0;text;key;constructor(e,t){this.text=e,this.key=t}fail(e){throw Error(`zerolith/i18n: message "${this.key}": ${e} at offset ${this.index}`)}peek(e=0){return this.text.charAt(this.index+e)}skipSpace(){for(;/[ \t\r\n ]/.test(this.peek());)this.index++}expect(e){this.text.startsWith(e,this.index)||this.fail(`expected ${JSON.stringify(e)}`),this.index+=e.length}name(){let e=/^[A-Za-z_][A-Za-z0-9_.-]*/.exec(this.text.slice(this.index));return e===null&&this.fail(`expected a name`),this.index+=e[0].length,e[0]}literal(){if(this.peek()===`|`){this.index++;let e=``;for(;this.index<this.text.length&&this.peek()!==`|`;)this.peek()===`\\`?(e+=this.peek(1),this.index+=2):(e+=this.peek(),this.index++);return this.expect(`|`),{kind:`literal`,value:e}}let e=/^[A-Za-z0-9_.+:@%-]+/.exec(this.text.slice(this.index));return e===null&&this.fail(`expected a literal`),this.index+=e[0].length,{kind:`literal`,value:e[0]}}variable(){return this.expect(`$`),{kind:`variable`,name:this.name()}}expression(){if(this.skipSpace(),this.peek()===`#`||this.peek()===`/`){for(;this.index<this.text.length&&this.peek()!==`}`;)this.index++;this.expect(`}`);return}let e;this.peek()===`$`?e=this.variable():this.peek()!==`:`&&(e=this.literal()),this.skipSpace();let t,n={};if(this.peek()===`:`)for(this.index++,t=this.name(),this.skipSpace();this.peek()!==`}`&&this.peek()!==`@`&&this.index<this.text.length;){let e=this.name();this.skipSpace(),this.expect(`=`),this.skipSpace(),n[e]=this.peek()===`$`?this.variable():this.literal(),this.skipSpace()}for(;this.peek()===`@`;)this.index++,this.name(),this.skipSpace(),this.peek()===`=`&&(this.index++,this.skipSpace(),this.peek()===`$`?this.variable():this.literal(),this.skipSpace());return this.expect(`}`),e===void 0&&t===void 0&&this.fail(`an expression needs an operand or a function`),{operand:e,fn:t,options:n}}pattern(e){let t=[],n=``;for(;this.index<this.text.length;){let r=this.peek();if(e&&r===`}`&&this.peek(1)===`}`)break;if(r===`\\`){let e=this.peek(1);e!==`{`&&e!==`}`&&e!==`\\`&&e!==`|`&&this.fail(`only \\{ \\} \\\\ and \\| can be escaped`),n+=e,this.index+=2}else if(r===`{`){n!==``&&(t.push(n),n=``),this.index++;let e=this.expression();e!==void 0&&t.push(e)}else r===`}`?this.fail(`a lone } must be escaped as \\}`):(n+=r,this.index++)}return n!==``&&t.push(n),t}quotedPattern(){this.expect(`{{`);let e=this.pattern(!0);return this.expect(`}}`),e}parse(){let e={declarations:new Map,pattern:void 0,selectors:[],variants:[]},t=this.text.trimStart();if(!t.startsWith(`.`)&&!t.startsWith(`{{`))return e.pattern=this.pattern(!1),e;for(this.skipSpace();this.text.startsWith(`.input`,this.index)||this.text.startsWith(`.local`,this.index);){let t=this.text.startsWith(`.local`,this.index);this.index+=6,this.skipSpace();let n;t?(n=this.variable().name,this.skipSpace(),this.expect(`=`),this.skipSpace()):n=``,this.expect(`{`);let r=this.expression();r===void 0&&this.fail(`a declaration cannot be markup`),t||(r.operand?.kind!==`variable`&&this.fail(`.input needs a variable operand`),n=r.operand.name),e.declarations.has(n)&&this.fail(`$${n} is declared twice`),e.declarations.set(n,{expression:r,local:t}),this.skipSpace()}if(this.text.startsWith(`.match`,this.index)){for(this.index+=6,this.skipSpace();this.peek()===`$`||this.peek()===`{`;){if(this.peek()===`{`){this.index++;let t=this.expression();t===void 0&&this.fail(`a selector cannot be markup`),e.selectors.push(t)}else e.selectors.push({operand:this.variable(),fn:void 0,options:{}});this.skipSpace()}for(e.selectors.length===0&&this.fail(`.match needs at least one selector`);this.index<this.text.length;){let t=[];for(;this.peek()!==`{`;)this.peek()===`*`?(this.index++,t.push(`*`)):t.push(this.literal().value),this.skipSpace();t.length!==e.selectors.length&&this.fail(`a variant needs ${e.selectors.length} key(s), found ${t.length}`),e.variants.push({keys:t,pattern:this.quotedPattern()}),this.skipSpace()}return e.variants.some(e=>e.keys.every(e=>e===`*`))||this.fail(`a matcher needs a variant whose keys are all *`),e}return e.pattern=this.quotedPattern(),this.skipSpace(),this.index<this.text.length&&this.fail(`unexpected text after the pattern`),e}}const t=new Set([`number`,`integer`,`percent`,`currency`,`offset`]),n=new Set([`date`,`time`,`datetime`]),r={minimumFractionDigits:`minimumFractionDigits`,maximumFractionDigits:`maximumFractionDigits`,minimumIntegerDigits:`minimumIntegerDigits`,minimumSignificantDigits:`minimumSignificantDigits`,maximumSignificantDigits:`maximumSignificantDigits`,signDisplay:`signDisplay`,trailingZeroDisplay:`trailingZeroDisplay`,roundingMode:`roundingMode`,roundingIncrement:`roundingIncrement`,roundingPriority:`roundingPriority`,currencyDisplay:`currencyDisplay`,currencySign:`currencySign`,numberingSystem:`numberingSystem`},i=new Set(`arguments.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.eval.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.static.super.switch.this.throw.true.try.typeof.var.void.while.with.yield`.split(`.`)),a=RegExp(`[<>${String.fromCodePoint(8232,8233)}]`,`g`),o=/\r\n|[\n\r\u2028\u2029]/;function s(e){return JSON.stringify(e).replace(a,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}function c(e){return e.split(o).join(` `).replaceAll(`<`,`<`)}const l=/^[A-Za-z_][A-Za-z0-9_]*$/;function u(e){return l.test(e)?e:s(e)}function d(e){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).split(/[^A-Za-z0-9]+/).filter(e=>e!==``).map((e,t)=>t===0?e.charAt(0).toLowerCase()+e.slice(1):e.charAt(0).toUpperCase()+e.slice(1)).join(``);return/^[0-9]/.test(t)?`_${t}`:t===``?`_`:t}class f{arguments=new Map;locals=new Map;prelude=[];key;message;formatters;used;reads=0;constructor(e,t,n,r){this.key=e,this.message=t,this.formatters=n,this.used=r}shared(e){this.used.add(`once`);let t=this.formatters.get(e);return t===void 0&&(t=`$f${this.formatters.size}`,this.formatters.set(e,t)),t}fail(e){throw Error(`zerolith/i18n: message "${this.key}": ${e}`)}argument(e,t){this.reads++;let n=this.locals.get(e);if(n!==void 0)return n;let r=this.arguments.get(e);return r===void 0||r===`string`?this.arguments.set(e,t):r!==t&&t!==`string`&&this.fail(`$${e} is used both as ${r} and as ${t}`),l.test(e)?`args.${e}`:`args[${s(e)}]`}optionValue(e){if(e!==void 0)return e.kind===`literal`?s(e.value):`String(${this.argument(e.name,`string`)})`}numberOptions(e){let t=[],n=e.fn??`number`;if(n===`integer`)t.push(`maximumFractionDigits: 0`);else if(n===`percent`)t.push(`style: "percent"`);else if(n===`currency`){let n=this.optionValue(e.options.currency);n===void 0&&this.fail(`:currency needs a currency option`),t.push(`style: "currency"`,`currency: ${n}`)}for(let[n,i]of Object.entries(e.options)){let e=r[n];if(e!==void 0){let n=i.kind===`literal`?i.value:void 0,r=n!==void 0&&/^[0-9]+$/.test(n)?n:void 0;t.push(`${e}: ${r??this.optionValue(i)??`undefined`}`)}else n===`useGrouping`&&i.kind===`literal`?t.push(`useGrouping: ${i.value===`never`?`false`:i.value===`always`?`true`:s(i.value)}`):n===`fractionDigits`&&i.kind===`literal`&&/^[0-9]+$/.test(i.value)&&t.push(`minimumFractionDigits: ${i.value}`,`maximumFractionDigits: ${i.value}`)}return t.length===0?`{}`:`{ ${t.join(`, `)} }`}dateOptions(e){let t=[],n=e.fn??`date`,r=t=>{let n=e.options[t];return n?.kind===`literal`?n.value:void 0},i=r(n===`datetime`?`dateLength`:`length`)??(n===`time`?void 0:`medium`);i!==void 0&&n!==`time`&&t.push(`dateStyle: ${s(i)}`);let a=r(n===`datetime`?`timePrecision`:`precision`)??(n===`date`?void 0:`minute`);a!==void 0&&n!==`date`&&t.push(`timeStyle: ${s(a===`second`?`medium`:`short`)}`);let o=r(`timeZone`);o!==void 0&&o!==`input`&&t.push(`timeZone: ${s(o)}`);let c=r(`hour12`);c!==void 0&&t.push(`hour12: ${c===`true`}`);let l=r(`timeZoneStyle`);return l!==void 0&&t.push(`timeZoneName: ${s(l)}`),t.length===0?`{}`:`{ ${t.join(`, `)} }`}numeric(e){let t=e.operand,n;if(t===void 0?this.fail(`:${e.fn??``} needs an operand`):n=t.kind===`literal`?Number.isFinite(Number(t.value))?String(Number(t.value)):this.fail(`${JSON.stringify(t.value)} is not a number`):this.argument(t.name,`number`),e.fn===`offset`){let t=this.optionValue(e.options.add),r=this.optionValue(e.options.subtract);t===void 0==(r===void 0)&&this.fail(`:offset needs exactly one of add or subtract`),n=`(${n} ${t===void 0?`-`:`+`} Number(${t??r??`0`}))`}return n}resolve(e,t=!1){if(e.fn===void 0&&e.operand?.kind===`variable`){let n=this.message.declarations.get(e.operand.name);if(n!==void 0&&(t||!n.local))return n.expression}return e}format(e){let r=this.resolve(e),i=r.fn;if(i===void 0||i===`string`){let e=r.operand;return e===void 0&&this.fail(`:string needs an operand`),e.kind===`literal`?s(e.value):`String(${this.argument(e.name,`string`)})`}if(t.has(i)){let e=this.numeric(r),t=this.reads,n=this.numberOptions(r);return this.reads===t?`${this.shared(`new Intl.NumberFormat(locale, ${n})`)}().format(${e})`:(this.used.add(`number`),`$number(${e}, ${n})`)}if(n.has(i)){let e=r.operand;e===void 0&&this.fail(`:${i} needs an operand`);let t=e.kind===`literal`?`new Date(${s(e.value)})`:this.argument(e.name,`date`);return`${this.shared(`new Intl.DateTimeFormat(locale, ${this.dateOptions(r)})`)}().format(${t})`}this.fail(`unknown function :${i}`)}selector(e){let n=this.resolve(e,!0),r=n.fn??`string`;if(t.has(r)){let e=n.options.select,t=e?.kind===`literal`?e.value:`plural`,i=r===`percent`?`(${this.numeric(n)}) * 100`:this.numeric(n);if(t===`exact`)return`{ value: String(${i}), categories: [] }`;let a=s(t===`ordinal`?`ordinal`:`cardinal`),o=this.reads,c=this.numberOptions(n);return this.reads===o?`{ value: String(${i}), categories: [${this.shared(`new Intl.PluralRules(locale, { ...new Intl.NumberFormat(locale, ${c}).resolvedOptions(), type: ${a} })`)}().select(${i})] }`:(this.used.add(`plural`),`{ value: String(${i}), categories: [$plural(${i}, ${a}, ${c})] }`)}if(r===`string`){let e=n.operand;return e===void 0&&this.fail(`a selector needs an operand`),`{ value: ${e.kind===`literal`?s(e.value):`String(${this.argument(e.name,`string`)})`}, categories: [] }`}this.fail(`:${r} cannot select`)}pattern(e){return e.length===0?`""`:e.map(e=>typeof e==`string`?s(e):this.format(e)).join(` + `)}body(){for(let[e,t]of this.message.declarations)if(t.local){let n=this.format(t.expression),r=l.test(e)?`local_${e}`:`local_${this.locals.size}`;this.locals.set(e,r),this.prelude.push(`const ${r} = ${n};`)}if(this.message.pattern!==void 0)return this.pattern(this.message.pattern);let e=this.message.selectors.map(e=>this.selector(e)),t=this.message.variants.map(e=>`{ keys: ${s(e.keys)}, pattern: () => ${this.pattern(e.pattern)} }`);return this.used.add(`select`),`$select([${e.join(`, `)}], [${t.join(`, `)}])`}}const p={cache:{js:`const $formats = new Map();
|
|
2
|
+
function $cached(kind, options, create)
|
|
3
|
+
{
|
|
4
|
+
const key = kind + JSON.stringify(options);
|
|
5
|
+
let instance = $formats.get(key);
|
|
6
|
+
if (instance === undefined)
|
|
7
|
+
{
|
|
8
|
+
instance = create();
|
|
9
|
+
$formats.set(key, instance);
|
|
10
|
+
}
|
|
11
|
+
return instance;
|
|
12
|
+
}`,ts:`const $formats: Map<string, unknown> = new Map();
|
|
13
|
+
function $cached<T>(kind: string, options: object, create: () => T): T
|
|
14
|
+
{
|
|
15
|
+
const key = kind + JSON.stringify(options);
|
|
16
|
+
let instance = $formats.get(key) as T | undefined;
|
|
17
|
+
if (instance === undefined)
|
|
18
|
+
{
|
|
19
|
+
instance = create();
|
|
20
|
+
$formats.set(key, instance);
|
|
21
|
+
}
|
|
22
|
+
return instance;
|
|
23
|
+
}`},once:{js:`function $once(create)
|
|
24
|
+
{
|
|
25
|
+
let instance;
|
|
26
|
+
return () => (instance ??= create());
|
|
27
|
+
}`,ts:`function $once<T>(create: () => T): () => T
|
|
28
|
+
{
|
|
29
|
+
let instance: T | undefined;
|
|
30
|
+
return () => (instance ??= create());
|
|
31
|
+
}`},number:{js:`function $number(value, options)
|
|
32
|
+
{
|
|
33
|
+
return $cached("n", options, () => new Intl.NumberFormat(locale, options)).format(value);
|
|
34
|
+
}`,ts:`function $number(value: number, options: Intl.NumberFormatOptions): string
|
|
35
|
+
{
|
|
36
|
+
return $cached("n", options, () => new Intl.NumberFormat(locale, options)).format(value);
|
|
37
|
+
}`},plural:{js:`function $plural(value, type, options)
|
|
38
|
+
{
|
|
39
|
+
return $cached("p" + type, options, () => new Intl.PluralRules(locale, { ...$cached("n", options, () => new Intl.NumberFormat(locale, options)).resolvedOptions(), type })).select(value);
|
|
40
|
+
}`,ts:`function $plural(value: number, type: "cardinal" | "ordinal", options: Intl.NumberFormatOptions): string
|
|
41
|
+
{
|
|
42
|
+
return $cached("p" + type, options, () => new Intl.PluralRules(locale, { ...$cached("n", options, () => new Intl.NumberFormat(locale, options)).resolvedOptions(), type })).select(value);
|
|
43
|
+
}`},select:{js:`function $select(selectors, variants)
|
|
44
|
+
{
|
|
45
|
+
let best;
|
|
46
|
+
let bestRank;
|
|
47
|
+
for (const variant of variants)
|
|
48
|
+
{
|
|
49
|
+
const rank = [];
|
|
50
|
+
let matches = true;
|
|
51
|
+
for (const [index, key] of variant.keys.entries())
|
|
52
|
+
{
|
|
53
|
+
const selector = selectors[index];
|
|
54
|
+
if (key === "*")
|
|
55
|
+
{
|
|
56
|
+
rank.push(0);
|
|
57
|
+
}
|
|
58
|
+
else if (key === selector.value)
|
|
59
|
+
{
|
|
60
|
+
rank.push(2);
|
|
61
|
+
}
|
|
62
|
+
else if (selector.categories.includes(key))
|
|
63
|
+
{
|
|
64
|
+
rank.push(1);
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
{
|
|
68
|
+
matches = false;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!matches)
|
|
73
|
+
{
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (matches && $better(rank, bestRank))
|
|
77
|
+
{
|
|
78
|
+
best = variant;
|
|
79
|
+
bestRank = rank;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return best === undefined ? "" : best.pattern();
|
|
83
|
+
}
|
|
84
|
+
function $better(rank, current)
|
|
85
|
+
{
|
|
86
|
+
if (current === undefined)
|
|
87
|
+
{
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
for (const [index, score] of rank.entries())
|
|
91
|
+
{
|
|
92
|
+
const other = current[index] ?? 0;
|
|
93
|
+
if (score !== other)
|
|
94
|
+
{
|
|
95
|
+
return score > other;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}`,ts:`interface Selector
|
|
100
|
+
{
|
|
101
|
+
value: string;
|
|
102
|
+
categories: string[];
|
|
103
|
+
}
|
|
104
|
+
interface Variant
|
|
105
|
+
{
|
|
106
|
+
keys: string[];
|
|
107
|
+
pattern: () => string;
|
|
108
|
+
}
|
|
109
|
+
function $better(rank: number[], current: number[] | undefined): boolean
|
|
110
|
+
{
|
|
111
|
+
if (current === undefined)
|
|
112
|
+
{
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
for (const [index, score] of rank.entries())
|
|
116
|
+
{
|
|
117
|
+
const other = current[index] ?? 0;
|
|
118
|
+
if (score !== other)
|
|
119
|
+
{
|
|
120
|
+
return score > other;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
function $select(selectors: Selector[], variants: Variant[]): string
|
|
126
|
+
{
|
|
127
|
+
let best: Variant | undefined;
|
|
128
|
+
let bestRank: number[] | undefined;
|
|
129
|
+
for (const variant of variants)
|
|
130
|
+
{
|
|
131
|
+
const rank: number[] = [];
|
|
132
|
+
let matches = true;
|
|
133
|
+
for (const [index, key] of variant.keys.entries())
|
|
134
|
+
{
|
|
135
|
+
const selector = selectors[index];
|
|
136
|
+
if (key === "*")
|
|
137
|
+
{
|
|
138
|
+
rank.push(0);
|
|
139
|
+
}
|
|
140
|
+
else if (selector !== undefined && key === selector.value)
|
|
141
|
+
{
|
|
142
|
+
rank.push(2);
|
|
143
|
+
}
|
|
144
|
+
else if (selector !== undefined && selector.categories.includes(key))
|
|
145
|
+
{
|
|
146
|
+
rank.push(1);
|
|
147
|
+
}
|
|
148
|
+
else
|
|
149
|
+
{
|
|
150
|
+
matches = false;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (matches && $better(rank, bestRank))
|
|
155
|
+
{
|
|
156
|
+
best = variant;
|
|
157
|
+
bestRank = rank;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return best === undefined ? "" : best.pattern();
|
|
161
|
+
}`}};function m(e,t){let n=new Set(e);return(n.has(`number`)||n.has(`plural`))&&n.add(`cache`),Object.keys(p).filter(e=>n.has(e)).map(e=>p[e][t?`js`:`ts`]).join(`
|
|
162
|
+
`)}function h(e){return e===`number`?`number`:e===`date`?`Date | number`:`string | number`}export function compileMessages(t,n,r={}){let a=r.language===`js`,l=[];l.push(`// Generated by @zerolith/i18n from ${c(r.source??`the ${t} catalog`)}. Do not edit; regenerate instead.`),a&&l.push(`// @ts-check`),l.push(`export const locale${a?``:`: string`} = ${s(t)};`),l.push(``);let p=l.length,g=new Map,_=new Set,v=[],y=new Set;for(let[t,r]of Object.entries(n)){let n=d(t);if(y.has(n))throw Error(`zerolith/i18n: keys "${t}" and another one both become ${n}`);if(n===`locale`)throw Error(`zerolith/i18n: key "${t}" becomes locale, which every compiled module exports; rename the key`);let s=i.has(n)?`message_${n}`:n;y.add(n),v.push(n);let c=new e(r,t).parse(),p=new f(t,c,g,_),m=p.body(),b=[...p.arguments.entries()].toSorted(([e],[t])=>e.localeCompare(t)),x=r.replace(/\*\//g,`* /`).replaceAll(`<`,`<`).split(o).map(e=>` * ${e}`.trimEnd()).join(`
|
|
163
|
+
`),S=`{ ${b.map(([e,t])=>`${u(e)}: ${h(t)}`).join(`; `)} }`;a?(l.push(`/**\n${x}${b.length>0?`\n * @param {${S}} args`:``}\n * @returns {string}\n */`),l.push(`${s===n?`export `:``}function ${s}(${b.length>0?`args`:``})`)):(l.push(`/**\n${x}\n */`),l.push(`${s===n?`export `:``}function ${s}(${b.length>0?`args: ${S}`:``}): string`)),l.push(`{`);for(let e of p.prelude)l.push(` ${e}`);l.push(` return ${m};`),l.push(`}`),s!==n&&l.push(`export { ${s} as ${n} };`),l.push(``)}let b=m(_,a),x=Array.from(g,([e,t])=>`const ${t} = $once(() => ${e});`);return l.splice(p,0,...b===``?[]:[b,``],...x.length===0?[]:[...x,``]),{code:l.join(`
|
|
164
|
+
`),names:v}}export function messageNames(e){return Object.keys(e).map(d)}export function compileIndex(e,t={}){let n=t.language===`js`,r=n?`js`:`ts`,i=[`// Generated by @zerolith/i18n. Do not edit; regenerate instead.`];return n&&i.push(`// @ts-check`),n||(i.push(`import type * as first from ${s(`./${e[0]??`en`}.${r}`)};`),i.push(``)),i.push(`export const locales${n?``:`: readonly string[]`} = ${s(e)};`),i.push(``),i.push(`/** Loads one locale's messages; each locale is its own module. */`),i.push(n?`export const loaders = {`:`export const loaders: Readonly<Record<string, () => Promise<typeof first>>> = {`),i.push(e.map(e=>` ${s(e)}: () => import(${s(`./${e}.${r}`)})`).join(`,
|
|
165
|
+
`)),i.push(`};`),i.push(``),i.join(`
|
|
166
|
+
`)}
|
|
167
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sources":["../../src/compile.ts"],"sourcesContent":["/**\n * The message compiler: MessageFormat 2 catalogs in, one module per locale\n * out, with a plain function per message whose arguments are typed from\n * the placeholders. Formatting and plural selection call `Intl` in the\n * generated module, so no message runtime is shipped. The subset\n * implemented is the one catalogs use: text and placeholders, quoted and\n * unquoted literals, `.input` and `.local` declarations, `.match` with\n * numeric and string selectors, and the default functions `:string`,\n * `:number`, `:integer`, `:percent`, `:currency`, `:offset`, `:date`,\n * `:time`, and `:datetime`. Markup is accepted and formats to nothing.\n */\n\n/** A catalog: message key to MessageFormat 2 source. */\nexport type Catalog = Readonly<Record<string, string>>;\n\n/** Options for `compileMessages`. */\nexport interface CompileOptions\n{\n /** `ts` emits TypeScript (the default); `js` emits JavaScript with JSDoc types for buildless projects. */\n language?: \"ts\" | \"js\";\n /** Named in the generated header. */\n source?: string;\n}\n\n/** The result of compiling one catalog. */\nexport interface CompiledCatalog\n{\n /** The generated module's source, TypeScript or JavaScript as the `language` option chose; the `zerolith-i18n` CLI writes it to `<locale>.ts` or `<locale>.js`. */\n code: string;\n /** The message keys as function names, in source order. */\n names: string[];\n}\n\ntype ArgumentType = \"number\" | \"date\" | \"string\";\n\ninterface Literal\n{\n kind: \"literal\";\n value: string;\n}\n\ninterface Variable\n{\n kind: \"variable\";\n name: string;\n}\n\ninterface Expression\n{\n operand: Literal | Variable | undefined;\n fn: string | undefined;\n options: Record<string, Literal | Variable>;\n}\n\ntype Part = string | Expression;\n\ninterface Variant\n{\n keys: string[];\n pattern: Part[];\n}\n\ninterface Message\n{\n declarations: Map<string, { expression: Expression; local: boolean }>;\n pattern: Part[] | undefined;\n selectors: Expression[];\n variants: Variant[];\n}\n\nclass Parser\n{\n private index = 0;\n private readonly text: string;\n private readonly key: string;\n\n constructor(text: string, key: string)\n {\n this.text = text;\n this.key = key;\n }\n\n private fail(message: string): never\n {\n throw new Error(`zerolith/i18n: message \"${this.key}\": ${message} at offset ${this.index}`);\n }\n\n private peek(offset = 0): string\n {\n return this.text.charAt(this.index + offset);\n }\n\n private skipSpace(): void\n {\n while (/[ \\t\\r\\n ]/.test(this.peek()))\n {\n this.index++;\n }\n }\n\n private expect(token: string): void\n {\n if (!this.text.startsWith(token, this.index))\n {\n this.fail(`expected ${JSON.stringify(token)}`);\n }\n this.index += token.length;\n }\n\n private name(): string\n {\n const match = /^[A-Za-z_][A-Za-z0-9_.-]*/.exec(this.text.slice(this.index));\n if (match === null)\n {\n this.fail(\"expected a name\");\n }\n this.index += match[0].length;\n return match[0];\n }\n\n private literal(): Literal\n {\n if (this.peek() === \"|\")\n {\n this.index++;\n let value = \"\";\n while (this.index < this.text.length && this.peek() !== \"|\")\n {\n if (this.peek() === \"\\\\\")\n {\n value += this.peek(1);\n this.index += 2;\n }\n else\n {\n value += this.peek();\n this.index++;\n }\n }\n this.expect(\"|\");\n return { kind: \"literal\", value };\n }\n const match = /^[A-Za-z0-9_.+:@%-]+/.exec(this.text.slice(this.index));\n if (match === null)\n {\n this.fail(\"expected a literal\");\n }\n this.index += match[0].length;\n return { kind: \"literal\", value: match[0] };\n }\n\n private variable(): Variable\n {\n this.expect(\"$\");\n return { kind: \"variable\", name: this.name() };\n }\n\n /** Parses the inside of `{ ... }` after the opening brace. */\n private expression(): Expression | undefined\n {\n this.skipSpace();\n if (this.peek() === \"#\" || this.peek() === \"/\")\n {\n while (this.index < this.text.length && this.peek() !== \"}\")\n {\n this.index++;\n }\n this.expect(\"}\");\n return undefined;\n }\n let operand: Literal | Variable | undefined;\n if (this.peek() === \"$\")\n {\n operand = this.variable();\n }\n else if (this.peek() !== \":\")\n {\n operand = this.literal();\n }\n this.skipSpace();\n let fn: string | undefined;\n const options: Record<string, Literal | Variable> = {};\n if (this.peek() === \":\")\n {\n this.index++;\n fn = this.name();\n this.skipSpace();\n while (this.peek() !== \"}\" && this.peek() !== \"@\" && this.index < this.text.length)\n {\n const option = this.name();\n this.skipSpace();\n this.expect(\"=\");\n this.skipSpace();\n options[option] = this.peek() === \"$\" ? this.variable() : this.literal();\n this.skipSpace();\n }\n }\n while (this.peek() === \"@\")\n {\n this.index++;\n this.name();\n this.skipSpace();\n if (this.peek() === \"=\")\n {\n this.index++;\n this.skipSpace();\n if (this.peek() === \"$\")\n {\n this.variable();\n }\n else\n {\n this.literal();\n }\n this.skipSpace();\n }\n }\n this.expect(\"}\");\n if (operand === undefined && fn === undefined)\n {\n this.fail(\"an expression needs an operand or a function\");\n }\n return { operand, fn, options };\n }\n\n /** Parses pattern text up to `end` (`}}` for quoted patterns, the end of input for simple ones). */\n private pattern(quoted: boolean): Part[]\n {\n const parts: Part[] = [];\n let text = \"\";\n while (this.index < this.text.length)\n {\n const char = this.peek();\n if (quoted && char === \"}\" && this.peek(1) === \"}\")\n {\n break;\n }\n if (char === \"\\\\\")\n {\n const next = this.peek(1);\n if (next !== \"{\" && next !== \"}\" && next !== \"\\\\\" && next !== \"|\")\n {\n this.fail(\"only \\\\{ \\\\} \\\\\\\\ and \\\\| can be escaped\");\n }\n text += next;\n this.index += 2;\n }\n else if (char === \"{\")\n {\n if (text !== \"\")\n {\n parts.push(text);\n text = \"\";\n }\n this.index++;\n const expression = this.expression();\n if (expression !== undefined)\n {\n parts.push(expression);\n }\n }\n else if (char === \"}\")\n {\n this.fail(\"a lone } must be escaped as \\\\}\");\n }\n else\n {\n text += char;\n this.index++;\n }\n }\n if (text !== \"\")\n {\n parts.push(text);\n }\n return parts;\n }\n\n private quotedPattern(): Part[]\n {\n this.expect(\"{{\");\n const parts = this.pattern(true);\n this.expect(\"}}\");\n return parts;\n }\n\n parse(): Message\n {\n const message: Message = { declarations: new Map(), pattern: undefined, selectors: [], variants: [] };\n const trimmed = this.text.trimStart();\n if (!trimmed.startsWith(\".\") && !trimmed.startsWith(\"{{\"))\n {\n message.pattern = this.pattern(false);\n return message;\n }\n this.skipSpace();\n while (this.text.startsWith(\".input\", this.index) || this.text.startsWith(\".local\", this.index))\n {\n const local = this.text.startsWith(\".local\", this.index);\n this.index += 6;\n this.skipSpace();\n let name: string;\n if (local)\n {\n name = this.variable().name;\n this.skipSpace();\n this.expect(\"=\");\n this.skipSpace();\n }\n else\n {\n name = \"\";\n }\n this.expect(\"{\");\n const expression = this.expression();\n if (expression === undefined)\n {\n this.fail(\"a declaration cannot be markup\");\n }\n if (!local)\n {\n if (expression.operand?.kind !== \"variable\")\n {\n this.fail(\".input needs a variable operand\");\n }\n name = expression.operand.name;\n }\n if (message.declarations.has(name))\n {\n this.fail(`$${name} is declared twice`);\n }\n message.declarations.set(name, { expression, local });\n this.skipSpace();\n }\n if (this.text.startsWith(\".match\", this.index))\n {\n this.index += 6;\n this.skipSpace();\n while (this.peek() === \"$\" || this.peek() === \"{\")\n {\n if (this.peek() === \"{\")\n {\n this.index++;\n const expression = this.expression();\n if (expression === undefined)\n {\n this.fail(\"a selector cannot be markup\");\n }\n message.selectors.push(expression);\n }\n else\n {\n message.selectors.push({ operand: this.variable(), fn: undefined, options: {} });\n }\n this.skipSpace();\n }\n if (message.selectors.length === 0)\n {\n this.fail(\".match needs at least one selector\");\n }\n while (this.index < this.text.length)\n {\n const keys: string[] = [];\n while (this.peek() !== \"{\")\n {\n if (this.peek() === \"*\")\n {\n this.index++;\n keys.push(\"*\");\n }\n else\n {\n keys.push(this.literal().value);\n }\n this.skipSpace();\n }\n if (keys.length !== message.selectors.length)\n {\n this.fail(`a variant needs ${message.selectors.length} key(s), found ${keys.length}`);\n }\n message.variants.push({ keys, pattern: this.quotedPattern() });\n this.skipSpace();\n }\n if (!message.variants.some((variant) => variant.keys.every((key) => key === \"*\")))\n {\n this.fail(\"a matcher needs a variant whose keys are all *\");\n }\n return message;\n }\n message.pattern = this.quotedPattern();\n this.skipSpace();\n if (this.index < this.text.length)\n {\n this.fail(\"unexpected text after the pattern\");\n }\n return message;\n }\n}\n\nconst NUMBER_FUNCTIONS = new Set([\"number\", \"integer\", \"percent\", \"currency\", \"offset\"]);\nconst DATE_FUNCTIONS = new Set([\"date\", \"time\", \"datetime\"]);\nconst NUMBER_OPTIONS: Record<string, string> = {\n minimumFractionDigits: \"minimumFractionDigits\",\n maximumFractionDigits: \"maximumFractionDigits\",\n minimumIntegerDigits: \"minimumIntegerDigits\",\n minimumSignificantDigits: \"minimumSignificantDigits\",\n maximumSignificantDigits: \"maximumSignificantDigits\",\n signDisplay: \"signDisplay\",\n trailingZeroDisplay: \"trailingZeroDisplay\",\n roundingMode: \"roundingMode\",\n roundingIncrement: \"roundingIncrement\",\n roundingPriority: \"roundingPriority\",\n currencyDisplay: \"currencyDisplay\",\n currencySign: \"currencySign\",\n numberingSystem: \"numberingSystem\"\n};\n\n/** Names a module cannot bind; a message named so is exported under its name from a binding of its own. */\nconst RESERVED: ReadonlySet<string> = new Set([\"arguments\", \"await\", \"break\", \"case\", \"catch\", \"class\", \"const\", \"continue\", \"debugger\", \"default\", \"delete\", \"do\", \"else\", \"enum\", \"eval\", \"export\", \"extends\", \"false\", \"finally\", \"for\", \"function\", \"if\", \"implements\", \"import\", \"in\", \"instanceof\", \"interface\", \"let\", \"new\", \"null\", \"package\", \"private\", \"protected\", \"public\", \"return\", \"static\", \"super\", \"switch\", \"this\", \"throw\", \"true\", \"try\", \"typeof\", \"var\", \"void\", \"while\", \"with\", \"yield\"]);\n\n/** Characters an HTML parser reads inside an inline script, and the line separators older engines refused in string literals. */\nconst SCRIPT_UNSAFE = new RegExp(`[<>${String.fromCodePoint(0x2028, 0x2029)}]`, \"g\");\n\n/** The line breaks of a message's source, each starting a new line of its doc comment. */\nconst SOURCE_LINES = /\\r\\n|[\\n\\r\\u2028\\u2029]/;\n\n/**\n * A value written as JavaScript source: its JSON, with `<`, `>`, U+2028, and\n * U+2029 escaped, so generated code stays inert even when a page inlines\n * it in a script element.\n */\nfunction jsLiteral(value: unknown): string\n{\n return JSON.stringify(value).replace(SCRIPT_UNSAFE, (character) => `\\\\u${character.charCodeAt(0).toString(16).padStart(4, \"0\")}`);\n}\n\n/** Text for a `//` comment, kept on one line and with `<` written as `<`, so it can end neither the comment nor an inline script. */\nfunction commentText(text: string): string\n{\n return text.split(SOURCE_LINES).join(\" \").replaceAll(\"<\", \"<\");\n}\n\n/** An argument or local name JavaScript can write as it is; MessageFormat also allows `-` and `.`, as in `$first-name`. */\nconst PLAIN_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** A property name as code: as it is when plain, quoted otherwise. */\nfunction property(name: string): string\n{\n return PLAIN_NAME.test(name) ? name : jsLiteral(name);\n}\n\nfunction identifier(key: string): string\n{\n const words = key.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\").split(/[^A-Za-z0-9]+/).filter((word) => word !== \"\");\n const name = words.map((word, index) => (index === 0 ? word.charAt(0).toLowerCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1))).join(\"\");\n return /^[0-9]/.test(name) ? `_${name}` : name === \"\" ? \"_\" : name;\n}\n\nclass Emitter\n{\n readonly arguments: Map<string, ArgumentType> = new Map();\n readonly locals: Map<string, string> = new Map();\n readonly prelude: string[] = [];\n private readonly key: string;\n private readonly message: Message;\n private readonly formatters: Map<string, string>;\n private readonly used: Set<Helper>;\n private reads = 0;\n\n constructor(key: string, message: Message, formatters: Map<string, string>, used: Set<Helper>)\n {\n this.key = key;\n this.message = message;\n this.formatters = formatters;\n this.used = used;\n }\n\n /** The module-level binding of a formatter whose options are known at compile time, created on first use and shared by every message that creates it the same way. */\n private shared(create: string): string\n {\n this.used.add(\"once\");\n let binding = this.formatters.get(create);\n if (binding === undefined)\n {\n binding = `$f${this.formatters.size}`;\n this.formatters.set(create, binding);\n }\n return binding;\n }\n\n private fail(text: string): never\n {\n throw new Error(`zerolith/i18n: message \"${this.key}\": ${text}`);\n }\n\n private argument(name: string, type: ArgumentType): string\n {\n this.reads++;\n const local = this.locals.get(name);\n if (local !== undefined)\n {\n return local;\n }\n const existing = this.arguments.get(name);\n if (existing === undefined || existing === \"string\")\n {\n this.arguments.set(name, type);\n }\n else if (existing !== type && type !== \"string\")\n {\n this.fail(`$${name} is used both as ${existing} and as ${type}`);\n }\n return PLAIN_NAME.test(name) ? `args.${name}` : `args[${jsLiteral(name)}]`;\n }\n\n private optionValue(value: Literal | Variable | undefined): string | undefined\n {\n if (value === undefined)\n {\n return undefined;\n }\n return value.kind === \"literal\" ? jsLiteral(value.value) : `String(${this.argument(value.name, \"string\")})`;\n }\n\n private numberOptions(expression: Expression): string\n {\n const entries: string[] = [];\n const fn = expression.fn ?? \"number\";\n if (fn === \"integer\")\n {\n entries.push(\"maximumFractionDigits: 0\");\n }\n else if (fn === \"percent\")\n {\n entries.push(\"style: \\\"percent\\\"\");\n }\n else if (fn === \"currency\")\n {\n const currency = this.optionValue(expression.options[\"currency\"]);\n if (currency === undefined)\n {\n this.fail(\":currency needs a currency option\");\n }\n entries.push(\"style: \\\"currency\\\"\", `currency: ${currency}`);\n }\n for (const [option, value] of Object.entries(expression.options))\n {\n const mapped = NUMBER_OPTIONS[option];\n if (mapped !== undefined)\n {\n const literal = value.kind === \"literal\" ? value.value : undefined;\n const numeric = literal !== undefined && /^[0-9]+$/.test(literal) ? literal : undefined;\n entries.push(`${mapped}: ${numeric ?? this.optionValue(value) ?? \"undefined\"}`);\n }\n else if (option === \"useGrouping\" && value.kind === \"literal\")\n {\n entries.push(`useGrouping: ${value.value === \"never\" ? \"false\" : value.value === \"always\" ? \"true\" : jsLiteral(value.value)}`);\n }\n else if (option === \"fractionDigits\" && value.kind === \"literal\" && /^[0-9]+$/.test(value.value))\n {\n entries.push(`minimumFractionDigits: ${value.value}`, `maximumFractionDigits: ${value.value}`);\n }\n }\n return entries.length === 0 ? \"{}\" : `{ ${entries.join(\", \")} }`;\n }\n\n private dateOptions(expression: Expression): string\n {\n const entries: string[] = [];\n const fn = expression.fn ?? \"date\";\n const literal = (name: string): string | undefined =>\n {\n const value = expression.options[name];\n return value?.kind === \"literal\" ? value.value : undefined;\n };\n const length = literal(fn === \"datetime\" ? \"dateLength\" : \"length\") ?? (fn === \"time\" ? undefined : \"medium\");\n if (length !== undefined && fn !== \"time\")\n {\n entries.push(`dateStyle: ${jsLiteral(length)}`);\n }\n const precision = literal(fn === \"datetime\" ? \"timePrecision\" : \"precision\") ?? (fn === \"date\" ? undefined : \"minute\");\n if (precision !== undefined && fn !== \"date\")\n {\n entries.push(`timeStyle: ${jsLiteral(precision === \"second\" ? \"medium\" : \"short\")}`);\n }\n const zone = literal(\"timeZone\");\n if (zone !== undefined && zone !== \"input\")\n {\n entries.push(`timeZone: ${jsLiteral(zone)}`);\n }\n const hour12 = literal(\"hour12\");\n if (hour12 !== undefined)\n {\n entries.push(`hour12: ${hour12 === \"true\"}`);\n }\n const style = literal(\"timeZoneStyle\");\n if (style !== undefined)\n {\n entries.push(`timeZoneName: ${jsLiteral(style)}`);\n }\n return entries.length === 0 ? \"{}\" : `{ ${entries.join(\", \")} }`;\n }\n\n /** The JavaScript for an expression's numeric value, before formatting. */\n private numeric(expression: Expression): string\n {\n const operand = expression.operand;\n let value: string;\n if (operand === undefined)\n {\n this.fail(`:${expression.fn ?? \"\"} needs an operand`);\n }\n else if (operand.kind === \"literal\")\n {\n value = Number.isFinite(Number(operand.value)) ? String(Number(operand.value)) : this.fail(`${JSON.stringify(operand.value)} is not a number`);\n }\n else\n {\n value = this.argument(operand.name, \"number\");\n }\n if (expression.fn === \"offset\")\n {\n const add = this.optionValue(expression.options[\"add\"]);\n const subtract = this.optionValue(expression.options[\"subtract\"]);\n if ((add === undefined) === (subtract === undefined))\n {\n this.fail(\":offset needs exactly one of add or subtract\");\n }\n value = `(${value} ${add === undefined ? \"-\" : \"+\"} Number(${add ?? subtract ?? \"0\"}))`;\n }\n return value;\n }\n\n /** Resolves a plain `{$x}` to its `.input` declaration when one exists, or with `locals` to its `.local` one too, so a selector on a local selects as its expression does. */\n private resolve(expression: Expression, locals = false): Expression\n {\n if (expression.fn === undefined && expression.operand?.kind === \"variable\")\n {\n const declared = this.message.declarations.get(expression.operand.name);\n if (declared !== undefined && (locals || !declared.local))\n {\n return declared.expression;\n }\n }\n return expression;\n }\n\n /** The JavaScript producing the formatted string of an expression. */\n format(raw: Expression): string\n {\n const expression = this.resolve(raw);\n const fn = expression.fn;\n if (fn === undefined || fn === \"string\")\n {\n const operand = expression.operand;\n if (operand === undefined)\n {\n this.fail(\":string needs an operand\");\n }\n return operand.kind === \"literal\" ? jsLiteral(operand.value) : `String(${this.argument(operand.name, \"string\")})`;\n }\n if (NUMBER_FUNCTIONS.has(fn))\n {\n const value = this.numeric(expression);\n const reads = this.reads;\n const options = this.numberOptions(expression);\n if (this.reads === reads)\n {\n return `${this.shared(`new Intl.NumberFormat(locale, ${options})`)}().format(${value})`;\n }\n this.used.add(\"number\");\n return `$number(${value}, ${options})`;\n }\n if (DATE_FUNCTIONS.has(fn))\n {\n const operand = expression.operand;\n if (operand === undefined)\n {\n this.fail(`:${fn} needs an operand`);\n }\n const value = operand.kind === \"literal\" ? `new Date(${jsLiteral(operand.value)})` : this.argument(operand.name, \"date\");\n return `${this.shared(`new Intl.DateTimeFormat(locale, ${this.dateOptions(expression)})`)}().format(${value})`;\n }\n this.fail(`unknown function :${fn}`);\n }\n\n /** The JavaScript for a selector: its comparable value and the categories it matches. */\n selector(raw: Expression): string\n {\n const expression = this.resolve(raw, true);\n const fn = expression.fn ?? \"string\";\n if (NUMBER_FUNCTIONS.has(fn))\n {\n const select = expression.options[\"select\"];\n const mode = select?.kind === \"literal\" ? select.value : \"plural\";\n const value = fn === \"percent\" ? `(${this.numeric(expression)}) * 100` : this.numeric(expression);\n if (mode === \"exact\")\n {\n return `{ value: String(${value}), categories: [] }`;\n }\n const type = jsLiteral(mode === \"ordinal\" ? \"ordinal\" : \"cardinal\");\n const reads = this.reads;\n const options = this.numberOptions(expression);\n if (this.reads === reads)\n {\n return `{ value: String(${value}), categories: [${this.shared(`new Intl.PluralRules(locale, { ...new Intl.NumberFormat(locale, ${options}).resolvedOptions(), type: ${type} })`)}().select(${value})] }`;\n }\n this.used.add(\"plural\");\n return `{ value: String(${value}), categories: [$plural(${value}, ${type}, ${options})] }`;\n }\n if (fn === \"string\")\n {\n const operand = expression.operand;\n if (operand === undefined)\n {\n this.fail(\"a selector needs an operand\");\n }\n const value = operand.kind === \"literal\" ? jsLiteral(operand.value) : `String(${this.argument(operand.name, \"string\")})`;\n return `{ value: ${value}, categories: [] }`;\n }\n this.fail(`:${fn} cannot select`);\n }\n\n pattern(parts: Part[]): string\n {\n if (parts.length === 0)\n {\n return \"\\\"\\\"\";\n }\n return parts.map((part) => (typeof part === \"string\" ? jsLiteral(part) : this.format(part))).join(\" + \");\n }\n\n body(): string\n {\n for (const [name, declaration] of this.message.declarations)\n {\n if (declaration.local)\n {\n const value = this.format(declaration.expression);\n const binding = PLAIN_NAME.test(name) ? `local_${name}` : `local_${this.locals.size}`;\n this.locals.set(name, binding);\n this.prelude.push(`const ${binding} = ${value};`);\n }\n }\n if (this.message.pattern !== undefined)\n {\n return this.pattern(this.message.pattern);\n }\n const selectors = this.message.selectors.map((selector) => this.selector(selector));\n const variants = this.message.variants.map((variant) => `{ keys: ${jsLiteral(variant.keys)}, pattern: () => ${this.pattern(variant.pattern)} }`);\n this.used.add(\"select\");\n return `$select([${selectors.join(\", \")}], [${variants.join(\", \")}])`;\n }\n}\n\n/** A group of helpers a compiled module shares; each is written only when one of the module's messages uses it. */\ntype Helper = \"cache\" | \"once\" | \"number\" | \"plural\" | \"select\";\n\n/** The helpers in JavaScript and in TypeScript, in the order a module writes them. */\nconst HELPERS: Record<Helper, { js: string; ts: string }> = {\n cache: {\n js: `const $formats = new Map();\nfunction $cached(kind, options, create)\n{\n const key = kind + JSON.stringify(options);\n let instance = $formats.get(key);\n if (instance === undefined)\n {\n instance = create();\n $formats.set(key, instance);\n }\n return instance;\n}`,\n ts: `const $formats: Map<string, unknown> = new Map();\nfunction $cached<T>(kind: string, options: object, create: () => T): T\n{\n const key = kind + JSON.stringify(options);\n let instance = $formats.get(key) as T | undefined;\n if (instance === undefined)\n {\n instance = create();\n $formats.set(key, instance);\n }\n return instance;\n}`\n },\n once: {\n js: `function $once(create)\n{\n let instance;\n return () => (instance ??= create());\n}`,\n ts: `function $once<T>(create: () => T): () => T\n{\n let instance: T | undefined;\n return () => (instance ??= create());\n}`\n },\n number: {\n js: `function $number(value, options)\n{\n return $cached(\"n\", options, () => new Intl.NumberFormat(locale, options)).format(value);\n}`,\n ts: `function $number(value: number, options: Intl.NumberFormatOptions): string\n{\n return $cached(\"n\", options, () => new Intl.NumberFormat(locale, options)).format(value);\n}`\n },\n plural: {\n js: `function $plural(value, type, options)\n{\n return $cached(\"p\" + type, options, () => new Intl.PluralRules(locale, { ...$cached(\"n\", options, () => new Intl.NumberFormat(locale, options)).resolvedOptions(), type })).select(value);\n}`,\n ts: `function $plural(value: number, type: \"cardinal\" | \"ordinal\", options: Intl.NumberFormatOptions): string\n{\n return $cached(\"p\" + type, options, () => new Intl.PluralRules(locale, { ...$cached(\"n\", options, () => new Intl.NumberFormat(locale, options)).resolvedOptions(), type })).select(value);\n}`\n },\n select: {\n js: `function $select(selectors, variants)\n{\n let best;\n let bestRank;\n for (const variant of variants)\n {\n const rank = [];\n let matches = true;\n for (const [index, key] of variant.keys.entries())\n {\n const selector = selectors[index];\n if (key === \"*\")\n {\n rank.push(0);\n }\n else if (key === selector.value)\n {\n rank.push(2);\n }\n else if (selector.categories.includes(key))\n {\n rank.push(1);\n }\n else\n {\n matches = false;\n break;\n }\n }\n if (!matches)\n {\n continue;\n }\n if (matches && $better(rank, bestRank))\n {\n best = variant;\n bestRank = rank;\n }\n }\n return best === undefined ? \"\" : best.pattern();\n}\nfunction $better(rank, current)\n{\n if (current === undefined)\n {\n return true;\n }\n for (const [index, score] of rank.entries())\n {\n const other = current[index] ?? 0;\n if (score !== other)\n {\n return score > other;\n }\n }\n return false;\n}`,\n ts: `interface Selector\n{\n value: string;\n categories: string[];\n}\ninterface Variant\n{\n keys: string[];\n pattern: () => string;\n}\nfunction $better(rank: number[], current: number[] | undefined): boolean\n{\n if (current === undefined)\n {\n return true;\n }\n for (const [index, score] of rank.entries())\n {\n const other = current[index] ?? 0;\n if (score !== other)\n {\n return score > other;\n }\n }\n return false;\n}\nfunction $select(selectors: Selector[], variants: Variant[]): string\n{\n let best: Variant | undefined;\n let bestRank: number[] | undefined;\n for (const variant of variants)\n {\n const rank: number[] = [];\n let matches = true;\n for (const [index, key] of variant.keys.entries())\n {\n const selector = selectors[index];\n if (key === \"*\")\n {\n rank.push(0);\n }\n else if (selector !== undefined && key === selector.value)\n {\n rank.push(2);\n }\n else if (selector !== undefined && selector.categories.includes(key))\n {\n rank.push(1);\n }\n else\n {\n matches = false;\n break;\n }\n }\n if (matches && $better(rank, bestRank))\n {\n best = variant;\n bestRank = rank;\n }\n }\n return best === undefined ? \"\" : best.pattern();\n}`\n }\n};\n\n/** The helpers a module's messages use, with the cache that `$number` and `$plural` share. */\nfunction helpersFor(used: ReadonlySet<Helper>, javascript: boolean): string\n{\n const needed = new Set(used);\n if (needed.has(\"number\") || needed.has(\"plural\"))\n {\n needed.add(\"cache\");\n }\n return (Object.keys(HELPERS) as Helper[]).filter((name) => needed.has(name)).map((name) => HELPERS[name][javascript ? \"js\" : \"ts\"]).join(\"\\n\");\n}\n\nfunction typeOf(type: ArgumentType): string\n{\n return type === \"number\" ? \"number\" : type === \"date\" ? \"Date | number\" : \"string | number\";\n}\n\n/**\n * Compiles one locale's catalog into a module: `locale`, one exported\n * function per message named from its key, and the `Intl` helpers they\n * share. Each function takes an `args` object typed from the message's\n * placeholders, or nothing when the message has none. A formatter whose\n * options are all literals is a module-level binding created on first use\n * and shared by every message that formats the same way; options that read\n * an argument find their formatter in a cache keyed by the options. Only\n * the helpers the messages use are written.\n */\nexport function compileMessages(locale: string, catalog: Catalog, options: CompileOptions = {}): CompiledCatalog\n{\n const javascript = options.language === \"js\";\n const out: string[] = [];\n out.push(`// Generated by @zerolith/i18n from ${commentText(options.source ?? `the ${locale} catalog`)}. Do not edit; regenerate instead.`);\n if (javascript)\n {\n out.push(\"// @ts-check\");\n }\n out.push(`export const locale${javascript ? \"\" : \": string\"} = ${jsLiteral(locale)};`);\n out.push(\"\");\n const head = out.length;\n const formatters = new Map<string, string>();\n const used = new Set<Helper>();\n const names: string[] = [];\n const seen = new Set<string>();\n for (const [key, source] of Object.entries(catalog))\n {\n const name = identifier(key);\n if (seen.has(name))\n {\n throw new Error(`zerolith/i18n: keys \"${key}\" and another one both become ${name}`);\n }\n if (name === \"locale\")\n {\n throw new Error(`zerolith/i18n: key \"${key}\" becomes locale, which every compiled module exports; rename the key`);\n }\n const binding = RESERVED.has(name) ? `message_${name}` : name;\n seen.add(name);\n names.push(name);\n const message = new Parser(source, key).parse();\n const emitter = new Emitter(key, message, formatters, used);\n const body = emitter.body();\n const args = [...emitter.arguments.entries()].toSorted(([a], [b]) => a.localeCompare(b));\n const doc = source.replace(/\\*\\//g, \"* /\").replaceAll(\"<\", \"<\").split(SOURCE_LINES).map((line) => ` * ${line}`.trimEnd()).join(\"\\n\");\n const argumentType = `{ ${args.map(([argument, type]) => `${property(argument)}: ${typeOf(type)}`).join(\"; \")} }`;\n if (javascript)\n {\n out.push(`/**\\n${doc}${args.length > 0 ? `\\n * @param {${argumentType}} args` : \"\"}\\n * @returns {string}\\n */`);\n out.push(`${binding === name ? \"export \" : \"\"}function ${binding}(${args.length > 0 ? \"args\" : \"\"})`);\n }\n else\n {\n out.push(`/**\\n${doc}\\n */`);\n out.push(`${binding === name ? \"export \" : \"\"}function ${binding}(${args.length > 0 ? `args: ${argumentType}` : \"\"}): string`);\n }\n out.push(\"{\");\n for (const line of emitter.prelude)\n {\n out.push(` ${line}`);\n }\n out.push(` return ${body};`);\n out.push(\"}\");\n if (binding !== name)\n {\n out.push(`export { ${binding} as ${name} };`);\n }\n out.push(\"\");\n }\n const helpers = helpersFor(used, javascript);\n const shared = Array.from(formatters, ([create, binding]) => `const ${binding} = $once(() => ${create});`);\n out.splice(head, 0, ...(helpers === \"\" ? [] : [helpers, \"\"]), ...(shared.length === 0 ? [] : [...shared, \"\"]));\n return { code: out.join(\"\\n\"), names };\n}\n\n/** The keys of a catalog as function names, for comparing locales. */\nexport function messageNames(catalog: Catalog): string[]\n{\n return Object.keys(catalog).map(identifier);\n}\n\n/**\n * The index module for a set of locales: the list of locales and one lazy\n * loader per locale, so each locale is its own chunk.\n */\nexport function compileIndex(locales: readonly string[], options: CompileOptions = {}): string\n{\n const javascript = options.language === \"js\";\n const extension = javascript ? \"js\" : \"ts\";\n const lines = [`// Generated by @zerolith/i18n. Do not edit; regenerate instead.`];\n if (javascript)\n {\n lines.push(\"// @ts-check\");\n }\n if (!javascript)\n {\n lines.push(`import type * as first from ${jsLiteral(`./${locales[0] ?? \"en\"}.${extension}`)};`);\n lines.push(\"\");\n }\n lines.push(`export const locales${javascript ? \"\" : \": readonly string[]\"} = ${jsLiteral(locales)};`);\n lines.push(\"\");\n lines.push(`/** Loads one locale's messages; each locale is its own module. */`);\n lines.push(javascript ? \"export const loaders = {\" : \"export const loaders: Readonly<Record<string, () => Promise<typeof first>>> = {\");\n lines.push(locales.map((locale) => ` ${jsLiteral(locale)}: () => import(${jsLiteral(`./${locale}.${extension}`)})`).join(\",\\n\"));\n lines.push(\"};\");\n lines.push(\"\");\n return lines.join(\"\\n\");\n}\n"],"names":["Parser","text","key","message","offset","token","match","value","operand","fn","options","option","parts","char","quoted","next","expression","trimmed","local","name","keys","variant","NUMBER_FUNCTIONS","DATE_FUNCTIONS","NUMBER_OPTIONS","RESERVED","SCRIPT_UNSAFE","SOURCE_LINES","jsLiteral","character","commentText","PLAIN_NAME","property","identifier","word","index","Emitter","formatters","used","binding","create","existing","type","entries","currency","\"currency\"","mapped","literal","numeric","length","precision","zone","hour12","style","add","\"add\"","subtract","\"subtract\"","declared","locals","raw","reads","select","\"select\"","mode","part","declaration","selectors","selector","variants","HELPERS","helpersFor","needed","javascript","typeOf","out","locale","head","names","seen","source","catalog","emitter","body","args","a","b","doc","line","argumentType","argument","helpers","shared","extension","lines","locales"],"mappings":"AAsEA,MAAMA,CAAM,CAEA,MAAQ,EACC,KACA,IAEjB,YAAY,EAAc,EAAW,CAEjC,KAAK,KAAOC,EACZ,KAAK,IAAMC,CACf,CAEQ,KAAK,EAAe,CAExB,MAAU,MAAM,2BAA2B,KAAK,IAAG,KAAMC,EAAO,aAAc,KAAK,OAAO,CAC9F,CAEQ,KAAK,EAAS,EAAC,CAEnB,OAAO,KAAK,KAAK,OAAO,KAAK,MAAQC,CAAM,CAC/C,CAEQ,WAAS,CAEb,KAAO,aAAa,KAAK,KAAK,KAAI,CAAE,GAEhC,KAAK,OAEb,CAEQ,OAAO,EAAa,CAEnB,KAAK,KAAK,WAAWC,EAAO,KAAK,KAAK,GAEvC,KAAK,KAAK,YAAY,KAAK,UAAUA,CAAK,GAAG,EAEjD,KAAK,OAASA,EAAM,MACxB,CAEQ,MAAI,CAER,IAAMC,EAAQ,4BAA4B,KA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,OAAO,OAAO,KAAKM,CAAO,CAAC,CAAC,IAAIhD,CAAU,CAC9C,CAMA,OAAM,SAAU,aAAa,EAA4B,EAA0B,CAAA,EAAE,CAEjF,IAAMwC,EAAa/D,EAAQ,WAAa,KAClCmF,EAAYpB,EAAa,KAAO,KAChCqB,EAAQ,CAAC,kEAAkE,EAiBjF,OAhBIrB,GAEAqB,EAAM,KAAK,cAAc,EAExBrB,IAEDqB,EAAM,KAAK,+BAA+BlE,EAAU,KAAKmE,EAAQ,IAAM,KAAI,GAAIF,GAAW,EAAC,EAAG,EAC9FC,EAAM,KAAK,EAAE,GAEjBA,EAAM,KAAK,uBAAuBrB,EAAa,GAAK,sBAAqB,KAAM7C,EAAUmE,CAAO,EAAC,EAAG,EACpGD,EAAM,KAAK,EAAE,EACbA,EAAM,KAAK,oEAAoE,EAC/EA,EAAM,KAAKrB,EAAa,2BAA6B,iFAAiF,EACtIqB,EAAM,KAAKC,EAAQ,IAAK,GAAW,OAAOnE,EAAUgD,CAAM,EAAC,iBAAkBhD,EAAU,KAAKgD,EAAM,GAAIiB,GAAW,EAAC,EAAG,CAAC,CAAC,KAAK;CAAK,CAAC,EAClIC,EAAM,KAAK,IAAI,EACfA,EAAM,KAAK,EAAE,EACNA,EAAM,KAAK;CAAI,CAC1B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{computed as e,effect as t,signal as n}from"zerolith";export function parseAcceptLanguage(e){if(e==null||e.trim()===``)return[];let t=[];for(let[n,r]of e.split(`,`).entries()){let[e=``,...i]=r.split(`;`),a=e.trim();if(a===``)continue;let o=1;for(let e of i){let[t=``,n=``]=e.split(`=`);if(t.trim().toLowerCase()===`q`){let e=Number(n.trim());o=Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}}o>0&&t.push({range:a,quality:o-n*1e-9})}return t.toSorted((e,t)=>t.quality-e.quality).map(({range:e,quality:t})=>({range:e,quality:Math.round(t*1e3)/1e3}))}function r(e){try{return Intl.getCanonicalLocales(e)[0]??e}catch{return e}}export function negotiateLocale(e,t,n){let a=typeof e==`string`?parseAcceptLanguage(e).map(e=>e.range):[...e??[]],o=t.map(e=>({tag:e,lower:r(e).toLowerCase()}));for(let e of a){let t=r(e).toLowerCase();if(t===`*`)return n;for(let e=t;e!==``;e=e.includes(`-`)?e.slice(0,e.lastIndexOf(`-`)):``){let t=o.find(t=>t.lower===e);if(t!==void 0)return t.tag}let a=t.split(`-`)[0]??t,s=o.filter(e=>e.lower.startsWith(`${a}-`));if(s.length>0){let t=i(e);return(s.find(e=>i(e.tag)===t)??s[0])?.tag??n}}return n}function i(e){try{return new Intl.Locale(e).maximize().script}catch{return}}const a=new Set([`adlm`,`arab`,`hebr`,`mand`,`mend`,`nkoo`,`rohg`,`samr`,`syrc`,`thaa`,`yezi`]);export function localeDirection(e){try{let t=new Intl.Locale(e),n=t,r=n.getTextInfo?.()??n.textInfo;return r===void 0?a.has((t.maximize().script??``).toLowerCase())?`rtl`:`ltr`:r.direction===`rtl`?`rtl`:`ltr`}catch{return`ltr`}}export function createLocale(t){let i=[...t.supported];if(i.length===0)throw TypeError(`zerolith/i18n: createLocale needs at least one supported locale`);let a=t.fallback===void 0?i[0]??``:i.find(e=>r(e).toLowerCase()===r(t.fallback??``).toLowerCase());if(a===void 0)throw TypeError(`zerolith/i18n: the fallback ${t.fallback??``} is not one of the supported locales, ${i.join(`, `)}`);let o=n(negotiateLocale(t.initial??a,i,a),{name:`locale`});return{locale:o,direction:e(()=>localeDirection(o.get())),supported:i,set(e){o.set(negotiateLocale(e,i,a))}}}export function applyLocale(e,n=document){return t(()=>{n.documentElement.lang=e.locale.get(),n.documentElement.dir=e.direction.get()})}const o=new Map;function s(e,t,n,r){let i=`${e}\u0000${t}\u0000${n===void 0?``:JSON.stringify(n)}`,a=o.get(i);return a===void 0&&(a=r(),o.set(i,a)),a}export function formatters(e){let t=()=>typeof e==`string`?e:e.get();return{number:(e,n)=>s(`number`,t(),n,()=>new Intl.NumberFormat(t(),n)).format(e),date:(e,n)=>s(`date`,t(),n,()=>new Intl.DateTimeFormat(t(),n)).format(e),relative:(e,n,r)=>s(`relative`,t(),r,()=>new Intl.RelativeTimeFormat(t(),r)).format(e,n),list:(e,n)=>s(`list`,t(),n,()=>new Intl.ListFormat(t(),n)).format(e),plural:(e,n)=>s(`plural`,t(),n,()=>new Intl.PluralRules(t(),n)).select(e)}}
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["/**\n * @zerolith/i18n: the locale layer, built on `Intl` with nothing shipped.\n * Negotiation of the request's or the browser's languages against the\n * locales an application supports, the current locale and its direction\n * as signals, the document's `lang` and `dir`, and formatters cached per\n * locale. Message catalogs are compiled ahead of time by\n * `@zerolith/i18n/compile` into plain functions, so no message runtime\n * exists here either.\n */\nimport { type ReadableSignal, type Signal, computed, effect, signal } from \"zerolith\";\n\n/** One entry of an `Accept-Language` header or of `navigator.languages`. */\nexport interface LanguageRange\n{\n /** The language tag, or `*` for any language, as written before any `;` parameters. */\n readonly range: string;\n /** The entry's `q` weight between 0 and 1, rounded to three decimals; 1 when the entry gives none. */\n readonly quality: number;\n}\n\n/** Parses an `Accept-Language` header into ranges ordered by quality, dropping those with quality zero. */\nexport function parseAcceptLanguage(header: string | null | undefined): LanguageRange[]\n{\n if (header === null || header === undefined || header.trim() === \"\")\n {\n return [];\n }\n const ranges: LanguageRange[] = [];\n for (const [index, part] of header.split(\",\").entries())\n {\n const [rawRange = \"\", ...parameters] = part.split(\";\");\n const range = rawRange.trim();\n if (range === \"\")\n {\n continue;\n }\n let quality = 1;\n for (const parameter of parameters)\n {\n const [key = \"\", value = \"\"] = parameter.split(\"=\");\n if (key.trim().toLowerCase() === \"q\")\n {\n const parsed = Number(value.trim());\n quality = Number.isFinite(parsed) ? Math.min(1, Math.max(0, parsed)) : 0;\n }\n }\n if (quality > 0)\n {\n ranges.push({ range, quality: quality - index * 1e-9 });\n }\n }\n return ranges.toSorted((a, b) => b.quality - a.quality).map(({ range, quality }) => ({ range, quality: Math.round(quality * 1000) / 1000 }));\n}\n\nfunction canonical(tag: string): string\n{\n try\n {\n return Intl.getCanonicalLocales(tag)[0] ?? tag;\n }\n catch\n {\n return tag;\n }\n}\n\n/**\n * Picks the supported locale that best matches what was requested: an\n * `Accept-Language` header, `navigator.languages`, or one tag. Each range\n * is tried in order of quality, first as an exact match, then by dropping\n * subtags from the end as RFC 4647 lookup does, then as the language of a\n * more specific supported locale, preferring one written in the same\n * script, so `zh-HK` finds `zh-TW` before `zh-CN`. `*` and no match at all\n * give `fallback`.\n */\nexport function negotiateLocale(requested: string | readonly string[] | null | undefined, supported: readonly string[], fallback: string): string\n{\n const ranges = typeof requested === \"string\" ? parseAcceptLanguage(requested).map((entry) => entry.range) : [...(requested ?? [])];\n const candidates = supported.map((tag) => ({ tag, lower: canonical(tag).toLowerCase() }));\n for (const range of ranges)\n {\n const wanted = canonical(range).toLowerCase();\n if (wanted === \"*\")\n {\n return fallback;\n }\n for (let prefix = wanted; prefix !== \"\"; prefix = prefix.includes(\"-\") ? prefix.slice(0, prefix.lastIndexOf(\"-\")) : \"\")\n {\n const exact = candidates.find((candidate) => candidate.lower === prefix);\n if (exact !== undefined)\n {\n return exact.tag;\n }\n }\n const language = wanted.split(\"-\")[0] ?? wanted;\n const related = candidates.filter((candidate) => candidate.lower.startsWith(`${language}-`));\n if (related.length > 0)\n {\n const script = scriptOf(range);\n return (related.find((candidate) => scriptOf(candidate.tag) === script) ?? related[0])?.tag ?? fallback;\n }\n }\n return fallback;\n}\n\n/** The script a locale is written in, with the likely script filled in, as `Hant` for `zh-TW`; undefined for a tag that does not parse. */\nfunction scriptOf(tag: string): string | undefined\n{\n try\n {\n return new Intl.Locale(tag).maximize().script;\n }\n catch\n {\n return undefined;\n }\n}\n\n/** The scripts written right to left, by their ISO 15924 codes in lowercase. */\nconst RTL_SCRIPTS: ReadonlySet<string> = new Set([\"adlm\", \"arab\", \"hebr\", \"mand\", \"mend\", \"nkoo\", \"rohg\", \"samr\", \"syrc\", \"thaa\", \"yezi\"]);\n\n/** The writing direction of a locale, from `Intl.Locale` where the engine provides it and otherwise from its script, the likely one when the tag names none, as engines decide. */\nexport function localeDirection(locale: string): \"ltr\" | \"rtl\"\n{\n try\n {\n const parsed = new Intl.Locale(locale);\n const withInfo = parsed as Intl.Locale & { getTextInfo?: () => { direction: string }; textInfo?: { direction: string } };\n const info = withInfo.getTextInfo?.() ?? withInfo.textInfo;\n if (info !== undefined)\n {\n return info.direction === \"rtl\" ? \"rtl\" : \"ltr\";\n }\n return RTL_SCRIPTS.has((parsed.maximize().script ?? \"\").toLowerCase()) ? \"rtl\" : \"ltr\";\n }\n catch\n {\n return \"ltr\";\n }\n}\n\n/** Options for `createLocale`. */\nexport interface LocaleOptions\n{\n /** The locales the application ships, most preferred first. */\n supported: readonly string[];\n /** The locale used when nothing matches, one of `supported`. Defaults to the first supported one. */\n fallback?: string;\n /** What to negotiate from at first: an `Accept-Language` header, `navigator.languages`, or a tag. Defaults to the fallback. */\n initial?: string | readonly string[] | null;\n}\n\n/** The current locale as state. */\nexport interface LocaleState\n{\n /** The current locale, always one of `supported`. */\n readonly locale: ReadableSignal<string>;\n /** The writing direction of the current locale. */\n readonly direction: ReadableSignal<\"ltr\" | \"rtl\">;\n /** A copy of the `supported` option, in the same order; `set` negotiates against it. */\n readonly supported: readonly string[];\n /** Switches locales after negotiating the request against `supported`. */\n set(requested: string | readonly string[]): void;\n}\n\n/** Creates the locale state for an application. Throws a `TypeError` when `supported` is empty or `fallback` is not one of its locales, since the locale must always be one of them. */\nexport function createLocale(options: LocaleOptions): LocaleState\n{\n const supported = [...options.supported];\n if (supported.length === 0)\n {\n throw new TypeError(\"zerolith/i18n: createLocale needs at least one supported locale\");\n }\n const fallback = options.fallback === undefined ? (supported[0] ?? \"\") : supported.find((tag) => canonical(tag).toLowerCase() === canonical(options.fallback ?? \"\").toLowerCase());\n if (fallback === undefined)\n {\n throw new TypeError(`zerolith/i18n: the fallback ${options.fallback ?? \"\"} is not one of the supported locales, ${supported.join(\", \")}`);\n }\n const locale: Signal<string> = signal(negotiateLocale(options.initial ?? fallback, supported, fallback), { name: \"locale\" });\n return {\n locale,\n direction: computed(() => localeDirection(locale.get())),\n supported,\n set(requested)\n {\n locale.set(negotiateLocale(requested, supported, fallback));\n }\n };\n}\n\n/** Keeps the document's `lang` and `dir` attributes in step with the locale; returns the effect's disposer. */\nexport function applyLocale(state: LocaleState, doc: Document = document): () => void\n{\n return effect(() =>\n {\n doc.documentElement.lang = state.locale.get();\n doc.documentElement.dir = state.direction.get();\n });\n}\n\n/** Formatters for the current locale; each reads the locale signal when called, so a computed value or template re-renders on a locale change. */\nexport interface Formatters\n{\n /** Formats a number with `Intl.NumberFormat`. */\n number(value: number, options?: Intl.NumberFormatOptions): string;\n /** Formats a `Date`, or a timestamp in milliseconds since the epoch, with `Intl.DateTimeFormat`. */\n date(value: Date | number, options?: Intl.DateTimeFormatOptions): string;\n /** Formats a time `value` units of `unit` away from now with `Intl.RelativeTimeFormat`, such as `in 2 hours`; a negative value lies in the past. */\n relative(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string;\n /** Joins strings into a list with `Intl.ListFormat`, such as `a, b, and c` in English. */\n list(values: Iterable<string>, options?: Intl.ListFormatOptions): string;\n /** Selects the plural category of a number with `Intl.PluralRules`, such as `one` or `other`, for choosing a message variant. */\n plural(value: number, options?: Intl.PluralRulesOptions): Intl.LDMLPluralRule;\n}\n\nconst cache = new Map<string, unknown>();\n\nfunction cached<T>(kind: string, locale: string, options: object | undefined, create: () => T): T\n{\n const key = `${kind}\\u0000${locale}\\u0000${options === undefined ? \"\" : JSON.stringify(options)}`;\n let instance = cache.get(key) as T | undefined;\n if (instance === undefined)\n {\n instance = create();\n cache.set(key, instance);\n }\n return instance;\n}\n\n/** Creates formatters over a locale, given as a signal or as a fixed tag. Instances are cached per locale and options. */\nexport function formatters(locale: ReadableSignal<string> | string): Formatters\n{\n const current = (): string => (typeof locale === \"string\" ? locale : locale.get());\n return {\n number: (value, options) => cached(\"number\", current(), options, () => new Intl.NumberFormat(current(), options)).format(value),\n date: (value, options) => cached(\"date\", current(), options, () => new Intl.DateTimeFormat(current(), options)).format(value),\n relative: (value, unit, options) => cached(\"relative\", current(), options, () => new Intl.RelativeTimeFormat(current(), options)).format(value, unit),\n list: (values, options) => cached(\"list\", current(), options, () => new Intl.ListFormat(current(), options)).format(values),\n plural: (value, options) => cached(\"plural\", current(), options, () => new Intl.PluralRules(current(), options)).select(value)\n };\n}\n"],"names":["header","ranges","index","part","rawRange","parameters","range","quality","parameter","key","value","parsed","b","a","canonical","tag","requested","entry","candidates","supported","wanted","fallback","prefix","exact","candidate","language","related","script","scriptOf","RTL_SCRIPTS","locale","withInfo","info","options","signal","computed","effect","state","cache","cached","kind","instance","create","current","unit","values"],"mappings":"AASA,OAA2C,cAAU,YAAQ,gBAAc,WAY3E,OAAM,SAAU,oBAAoB,EAAiC,CAEjE,GAAIA,GAAW,MAAgCA,EAAO,KAAI,IAAO,GAE7D,MAAO,CAAA,EAEX,IAAMC,EAA0B,CAAA,EAChC,IAAK,GAAM,CAACC,EAAOC,KAASH,EAAO,MAAM,GAAG,CAAC,CAAC,QAAO,EACrD,CACI,GAAM,CAACI,EAAW,GAAI,GAAGC,GAAcF,EAAK,MAAM,GAAG,EAC/CG,EAAQF,EAAS,KAAI,EAC3B,GAAIE,IAAU,GAEV,SAEJ,IAAIC,EAAU,EACd,IAAK,IAAMC,KAAaH,EACxB,CACI,GAAM,CAACI,EAAM,GAAIC,EAAQ,IAAMF,EAAU,MAAM,GAAG,EAClD,GAAIC,EAAI,KAAI,CAAE,CAAC,YAAW,IAAO,IACjC,CACI,IAAME,EAAS,OAAOD,EAAM,KAAI,CAAE,EAClC,EAAU,OAAO,SAASC,CAAM,EAAI,KAAK,IAAI,EAAG,KAAK,IAAI,EAAGA,CAAM,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C,CAAC,OAAOY,CAAM,EAC1H,QAAS,EAAO,IAAYN,EAAO,SAAUI,EAAO,EAAIV,MAAe,IAAI,KAAK,YAAYU,EAAO,EAAIV,CAAO,CAAC,CAAC,CAAC,OAAOvB,CAAK,CAChI,CACL"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerolith/i18n",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
4
|
"description": "Internationalization for zerolith built on Intl with nothing shipped: locale negotiation and state, direction and document language, cached formatters, and a compiler that turns MessageFormat 2 catalogs into per-locale modules",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "molexxxx",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://zerolith.dev/",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/molexxxx/zerolith.git",
|
|
@@ -30,11 +30,13 @@
|
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
|
-
"
|
|
33
|
+
"development": "./dist/index.js",
|
|
34
|
+
"default": "./dist/production/index.js"
|
|
34
35
|
},
|
|
35
36
|
"./compile": {
|
|
36
37
|
"types": "./dist/compile.d.ts",
|
|
37
|
-
"
|
|
38
|
+
"development": "./dist/compile.js",
|
|
39
|
+
"default": "./dist/production/compile.js"
|
|
38
40
|
},
|
|
39
41
|
"./package.json": "./package.json"
|
|
40
42
|
},
|
|
@@ -45,12 +47,12 @@
|
|
|
45
47
|
"README.md"
|
|
46
48
|
],
|
|
47
49
|
"scripts": {
|
|
48
|
-
"build": "tsc -p tsconfig.build.json"
|
|
50
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/production.ts"
|
|
49
51
|
},
|
|
50
52
|
"peerDependencies": {
|
|
51
|
-
"zerolith": "^0.1.0-alpha.
|
|
53
|
+
"zerolith": "^0.1.0-alpha.10"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
54
|
-
"zerolith": "^0.1.0-alpha.
|
|
56
|
+
"zerolith": "^0.1.0-alpha.10"
|
|
55
57
|
}
|
|
56
58
|
}
|