@k8ordo/i18n 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accept-language.d.mts +1 -3
- package/dist/accept-language.mjs +1 -2
- package/dist/cookie.d.mts +1 -3
- package/dist/cookie.mjs +1 -2
- package/dist/current.d.mts +1 -3
- package/dist/current.mjs +1 -2
- package/dist/format.d.mts +1 -3
- package/dist/format.mjs +1 -2
- package/dist/locales.d.mts +1 -3
- package/dist/locales.mjs +1 -2
- package/dist/message.d.mts +1 -3
- package/dist/message.mjs +1 -2
- package/dist/register.d.mts +1 -3
- package/package.json +3 -3
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/accept-language.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* The tags of an `Accept-Language` header, most preferred first: `q` weights
|
|
4
3
|
* decide the order (a tag without one, or with one that is not a number,
|
|
@@ -7,5 +6,4 @@
|
|
|
7
6
|
* "anything", which is what the default locale already means. Feed the result
|
|
8
7
|
* to `locales.negotiate`; a missing header (`null`) is an empty list.
|
|
9
8
|
*/
|
|
10
|
-
export declare const parseAcceptLanguage: (header: string | null) => string[];
|
|
11
|
-
//#endregion
|
|
9
|
+
export declare const parseAcceptLanguage: (header: string | null) => string[];
|
package/dist/accept-language.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/accept-language.ts
|
|
2
2
|
/**
|
|
3
3
|
* The tags of an `Accept-Language` header, most preferred first: `q` weights
|
|
4
4
|
* decide the order (a tag without one, or with one that is not a number,
|
|
@@ -28,5 +28,4 @@ const parseAcceptLanguage = (header) => {
|
|
|
28
28
|
}] : [];
|
|
29
29
|
}).toSorted((a, b) => b.quality - a.quality || a.index - b.index).map((entry) => entry.tag);
|
|
30
30
|
};
|
|
31
|
-
//#endregion
|
|
32
31
|
export { parseAcceptLanguage };
|
package/dist/cookie.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/cookie.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* The value of one cookie in a `Cookie` header, or `null` when the header or
|
|
4
3
|
* the cookie is missing. The first cookie of that name wins — a browser sends
|
|
@@ -6,5 +5,4 @@
|
|
|
6
5
|
* (RFC 6265 allows them) comes back without them. Values are not
|
|
7
6
|
* percent-decoded: a locale tag needs no encoding.
|
|
8
7
|
*/
|
|
9
|
-
export declare const readCookie: (header: string | null, name: string) => string | null;
|
|
10
|
-
//#endregion
|
|
8
|
+
export declare const readCookie: (header: string | null, name: string) => string | null;
|
package/dist/cookie.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/cookie.ts
|
|
2
2
|
/**
|
|
3
3
|
* The value of one cookie in a `Cookie` header, or `null` when the header or
|
|
4
4
|
* the cookie is missing. The first cookie of that name wins — a browser sends
|
|
@@ -16,5 +16,4 @@ const readCookie = (header, name) => {
|
|
|
16
16
|
}
|
|
17
17
|
return null;
|
|
18
18
|
};
|
|
19
|
-
//#endregion
|
|
20
19
|
export { readCookie };
|
package/dist/current.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RegisteredLocale } from "./register.mjs";
|
|
2
|
-
//#region src/current.d.ts
|
|
3
2
|
export type LocaleStorage = {
|
|
4
3
|
getStore: () => string | undefined;
|
|
5
4
|
enterWith: (locale: string) => void;
|
|
@@ -46,5 +45,4 @@ export declare const registeredDefault: () => string | null;
|
|
|
46
45
|
* set has no locale, whatever its URL happens to start with, so the server
|
|
47
46
|
* and the browser both answer `null` and agree.
|
|
48
47
|
*/
|
|
49
|
-
export declare const currentLocale: () => RegisteredLocale | null;
|
|
50
|
-
//#endregion
|
|
48
|
+
export declare const currentLocale: () => RegisteredLocale | null;
|
package/dist/current.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/current.ts
|
|
2
2
|
const STORAGE_KEY = Symbol.for("@k8ordo/i18n/storage");
|
|
3
3
|
const SET_KEY = Symbol.for("@k8ordo/i18n/locales");
|
|
4
4
|
const global = globalThis;
|
|
@@ -69,5 +69,4 @@ const currentLocale = () => {
|
|
|
69
69
|
if (set === void 0) return null;
|
|
70
70
|
return namedLocale() ?? set.default;
|
|
71
71
|
};
|
|
72
|
-
//#endregion
|
|
73
72
|
export { browserPathname, currentLocale, inBrowser, localeStorage, namedLocale, register, registeredDefault, setRegistered };
|
package/dist/format.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { LocaleDefinition } from "./locales.mjs";
|
|
2
|
-
//#region src/format.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* `Intl.DateTimeFormatOptions` without a `timeZone`: the locale's own is the
|
|
5
4
|
* only one a date is written in, so the server's HTML and the browser's
|
|
@@ -28,5 +27,4 @@ export type IntlFormats = {
|
|
|
28
27
|
readonly listFormat: (options?: Intl.ListFormatOptions) => Intl.ListFormat;
|
|
29
28
|
};
|
|
30
29
|
/** The members of a locale set that draw `Intl` for its current locale. */
|
|
31
|
-
export declare const intlFormats: <L extends string>(getLocale: () => L, definitions: Readonly<Record<L, LocaleDefinition>>) => IntlFormats;
|
|
32
|
-
//#endregion
|
|
30
|
+
export declare const intlFormats: <L extends string>(getLocale: () => L, definitions: Readonly<Record<L, LocaleDefinition>>) => IntlFormats;
|
package/dist/format.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/format.ts
|
|
2
2
|
/**
|
|
3
3
|
* An `Intl` constructor behind a cache keyed by locale and options. The
|
|
4
4
|
* options are keyed by their JSON: two spellings of the same options make two
|
|
@@ -27,5 +27,4 @@ const intlFormats = (getLocale, definitions) => ({
|
|
|
27
27
|
pluralRules: cached(getLocale, (locale, options) => new Intl.PluralRules(locale, options)),
|
|
28
28
|
listFormat: cached(getLocale, (locale, options) => new Intl.ListFormat(locale, options))
|
|
29
29
|
});
|
|
30
|
-
//#endregion
|
|
31
30
|
export { intlFormats };
|
package/dist/locales.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IntlFormats } from "./format.mjs";
|
|
2
|
-
//#region src/locales.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* The one shape every validation library agrees on (Standard Schema), as far
|
|
5
4
|
* as `@k8ordo/framework` reads it for a route's `paramsSchema`.
|
|
@@ -156,5 +155,4 @@ export type LocaleOf<Ls> = Ls extends Locales<infer L, infer _D> ? L : never;
|
|
|
156
155
|
* });
|
|
157
156
|
* ```
|
|
158
157
|
*/
|
|
159
|
-
export declare const defineLocales: <const Definitions extends Readonly<Record<string, LocaleDefinition>>, D extends keyof Definitions & string = keyof Definitions & string>(definitions: Definitions, options?: LocalesOptions<D>) => Locales<keyof Definitions & string, D>;
|
|
160
|
-
//#endregion
|
|
158
|
+
export declare const defineLocales: <const Definitions extends Readonly<Record<string, LocaleDefinition>>, D extends keyof Definitions & string = keyof Definitions & string>(definitions: Definitions, options?: LocalesOptions<D>) => Locales<keyof Definitions & string, D>;
|
package/dist/locales.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { parseAcceptLanguage } from "./accept-language.mjs";
|
|
|
2
2
|
import { readCookie } from "./cookie.mjs";
|
|
3
3
|
import { browserPathname, inBrowser, localeStorage, register } from "./current.mjs";
|
|
4
4
|
import { intlFormats } from "./format.mjs";
|
|
5
|
-
|
|
5
|
+
// src/locales.ts
|
|
6
6
|
/** `Intl.Locale` throws a RangeError on a tag that is not BCP 47; that is the only check a tag needs. */
|
|
7
7
|
const parseTag = (tag) => {
|
|
8
8
|
try {
|
|
@@ -147,5 +147,4 @@ const defineLocales = (definitions, options) => {
|
|
|
147
147
|
...intlFormats(getLocale, byTag)
|
|
148
148
|
};
|
|
149
149
|
};
|
|
150
|
-
//#endregion
|
|
151
150
|
export { defineLocales };
|
package/dist/message.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RegisteredLocale } from "./register.mjs";
|
|
2
|
-
//#region src/message.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* A message: a function of the values its text needs (none for a plain
|
|
5
4
|
* string), returning the text in the current locale. What a component that
|
|
@@ -26,5 +25,4 @@ export type Variants<V> = Readonly<Record<RegisteredLocale, V>>;
|
|
|
26
25
|
* `defineLocales` registered, else the first variant written.
|
|
27
26
|
*/
|
|
28
27
|
export declare function message(variants: Variants<string>): Message;
|
|
29
|
-
export declare function message<A extends readonly unknown[]>(variants: Variants<(...args: A) => string>): Message<A>;
|
|
30
|
-
//#endregion
|
|
28
|
+
export declare function message<A extends readonly unknown[]>(variants: Variants<(...args: A) => string>): Message<A>;
|
package/dist/message.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { namedLocale, registeredDefault, setRegistered } from "./current.mjs";
|
|
2
|
-
|
|
2
|
+
// src/message.ts
|
|
3
3
|
function message(variants) {
|
|
4
4
|
return (...args) => {
|
|
5
5
|
const named = namedLocale();
|
|
@@ -9,5 +9,4 @@ function message(variants) {
|
|
|
9
9
|
return typeof variant === "function" ? variant(...args) : variant;
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
//#endregion
|
|
13
12
|
export { message };
|
package/dist/register.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/register.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Merged once, so `message()` knows which locales every message must carry —
|
|
4
3
|
* without each message naming the set. `@k8ordo/framework` generates it from
|
|
@@ -19,5 +18,4 @@ export interface Register {}
|
|
|
19
18
|
/** The application's locale union once `Register` is merged; `string` before. */
|
|
20
19
|
export type RegisteredLocale = Register extends {
|
|
21
20
|
locale: infer L extends string;
|
|
22
|
-
} ? L : string;
|
|
23
|
-
//#endregion
|
|
21
|
+
} ? L : string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k8ordo/i18n",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "The locale axis of an application, owned. One locale set derives the URL segment, negotiation, the params schema, the static paths, and the current locale on either side of the network; each message is a function that reads it, so a bundler keeps only what a page names.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"@vitest/browser-playwright": "5.0.5",
|
|
44
44
|
"publint": "0.3.25",
|
|
45
45
|
"typescript": "7.0.2",
|
|
46
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@1.
|
|
47
|
-
"vite-plus": "1.
|
|
46
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
47
|
+
"vite-plus": "1.4.0",
|
|
48
48
|
"vitest": "5.0.5"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|