@k8ordo/i18n 0.1.0 → 1.0.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/README.md +73 -28
- package/dist/accept-language.d.mts +7 -7
- package/dist/accept-language.mjs +5 -4
- package/dist/cookie.d.mts +10 -0
- package/dist/cookie.mjs +20 -0
- package/dist/current.d.mts +26 -23
- package/dist/current.mjs +31 -5
- package/dist/format.d.mts +32 -0
- package/dist/format.mjs +31 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +2 -1
- package/dist/locales.d.mts +76 -19
- package/dist/locales.mjs +55 -12
- package/dist/message.d.mts +5 -6
- package/dist/message.mjs +2 -2
- package/dist/register.d.mts +6 -6
- package/docs/GUIDE.md +394 -113
- package/docs/llms.txt +37 -14
- package/package.json +7 -7
package/docs/llms.txt
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
# @k8ordo/i18n
|
|
2
2
|
|
|
3
|
-
> The locale axis of an application, owned. `defineLocales(
|
|
4
|
-
> declares the set once
|
|
3
|
+
> The locale axis of an application, owned. `defineLocales({ ja: { timeZone,
|
|
4
|
+
> dir }, en: … })` declares the set once — each locale with the time zone its
|
|
5
|
+
> dates are shown in and its text direction — and derives membership,
|
|
6
|
+
> negotiation, the URL segment
|
|
5
7
|
> (`localize` / `delocalize`), the `[locale]` params schema in the shape
|
|
6
|
-
> `@k8ordo/
|
|
8
|
+
> `@k8ordo/framework` runs, and the current locale
|
|
7
9
|
> (`getLocale()`). Each message is a function — `message({ ja, en })` — that
|
|
8
10
|
> reads the locale where it is called: on the server the request the schema
|
|
9
11
|
> accepted, in the browser the URL. The same call renders in a Server
|
|
10
12
|
> Component and in a Client Component; there is no provider and no hook; a
|
|
11
13
|
> bundler keeps only the messages a client module names. `Register` carries
|
|
12
|
-
> the app's locale union so a message missing a locale does not compile
|
|
14
|
+
> the app's locale union so a message missing a locale does not compile;
|
|
15
|
+
> `@k8ordo/framework` generates it from the `locales` export of
|
|
16
|
+
> `src/i18n.ts`, and any other app writes it by hand.
|
|
13
17
|
>
|
|
14
18
|
> Like every k8ordo package it assumes React 19 and Server Components, uses
|
|
15
19
|
> only what has reached Baseline newly available, and ships no polyfills or
|
|
@@ -21,24 +25,43 @@ When installed via npm, these docs live under `node_modules/@k8ordo/i18n/docs/`.
|
|
|
21
25
|
|
|
22
26
|
- [Design Guide](GUIDE.md): what the package owns and does not (the locale
|
|
23
27
|
segment, not the pathname; no message grammar; no loader), the locale set
|
|
24
|
-
and negotiation, messages as functions and `Register
|
|
28
|
+
and negotiation, messages as functions and `Register` (generated under
|
|
29
|
+
`@k8ordo/framework`, hand-written elsewhere), formatting (`Intl`
|
|
30
|
+
drawn for the current locale, dates in its time zone), the Server
|
|
25
31
|
Component boundary (a message is called before it is passed to a
|
|
26
32
|
`'use client'` component), what reaches the browser, where the locale comes
|
|
27
|
-
from on each side, `/`
|
|
28
|
-
|
|
33
|
+
from on each side, `/` (a `307` from a `guard.ts` in server mode,
|
|
34
|
+
an effect in static mode) and `<html lang>` / `dir`, static path
|
|
35
|
+
expansion, and pairing with `@k8ordo/router` / `@k8ordo/ui` /
|
|
36
|
+
`@k8ordo/form`.
|
|
29
37
|
|
|
30
38
|
## Entry point
|
|
31
39
|
|
|
32
|
-
- `@k8ordo/i18n` — `defineLocales(
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
- `@k8ordo/i18n` — `defineLocales(definitions, { default? })` takes each
|
|
41
|
+
locale's `{ timeZone, dir }` by tag (both required; an unknown time zone
|
|
42
|
+
throws) and returns `{ all, definitions, default, is, negotiate, localize,
|
|
43
|
+
delocalize, paths, paramsSchema, getLocale, run, negotiateRequest, dateTimeFormat,
|
|
44
|
+
numberFormat, relativeTimeFormat, pluralRules, listFormat }`; the last five
|
|
45
|
+
return the `Intl` object for the current locale, cached per locale and
|
|
46
|
+
options, and `dateTimeFormat` always in that locale's `timeZone` (its
|
|
47
|
+
options type refuses one); `paths(patterns)` is the static build's `paths` option
|
|
48
|
+
with `/:locale` expanded to every locale; typed links come from
|
|
49
|
+
the router's `bindParams(() => ({ locale: locales.getLocale() }))`,
|
|
50
|
+
written by the application (imported from `@k8ordo/framework` in a
|
|
51
|
+
framework application); the first entry is the default unless told otherwise (and `default` is then typed as the whole union), every tag
|
|
35
52
|
must be BCP 47, `negotiate(list)` tries each requested tag in order (exact,
|
|
36
53
|
then language) before falling back to the default, `getLocale()` is the
|
|
37
54
|
locale of the render in progress (not a hook), and `run(locale, fn)`
|
|
38
|
-
(server only) runs `fn` under a locale. `
|
|
39
|
-
|
|
55
|
+
(server only) runs `fn` under a locale. `negotiateRequest(request, {
|
|
56
|
+
cookie? })` chooses for a `Request` — the named cookie (the visitor's
|
|
57
|
+
earlier choice) first, then `Accept-Language` — through the same rule as
|
|
58
|
+
`negotiate`. `parseAcceptLanguage(header)` turns an `Accept-Language`
|
|
59
|
+
header into a preference list. `currentLocale()` returns the current locale as the
|
|
60
|
+
defined set resolves it — the one named, else the set's default — or `null`
|
|
61
|
+
where no set is defined in that environment; it is for a library rendering
|
|
62
|
+
inside an application it does not know (`@k8ordo/ui`'s built-in text). `message(variants)`
|
|
40
63
|
declares one message — text in every locale, or a function of the same
|
|
41
64
|
parameters in every locale — and returns `Message<Args>`, a function that
|
|
42
|
-
renders the current locale's text. Types: `Locales`, `LocaleOf`, `Message`,
|
|
65
|
+
renders the current locale's text. Types: `Locales`, `LocaleOf`, `LocaleDefinition`, `IntlFormats`, `LocaleDateTimeFormatOptions`, `Message`,
|
|
43
66
|
`Variants`, `Register`, `RegisteredLocale`, `Delocalized`,
|
|
44
|
-
`LocaleParamsSchema`, `LocalesOptions`.
|
|
67
|
+
`LocaleParamsSchema`, `LocalesOptions`, `NegotiateRequestOptions`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k8ordo/i18n",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
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",
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@arethetypeswrong/cli": "0.18.5",
|
|
43
|
-
"@vitest/browser-playwright": "5.0.
|
|
44
|
-
"publint": "0.3.
|
|
43
|
+
"@vitest/browser-playwright": "5.0.3",
|
|
44
|
+
"publint": "0.3.25",
|
|
45
45
|
"typescript": "7.0.2",
|
|
46
|
-
"vite": "
|
|
47
|
-
"vite-plus": "
|
|
48
|
-
"vitest": "5.0.
|
|
46
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
|
|
47
|
+
"vite-plus": "1.1.0",
|
|
48
|
+
"vitest": "5.0.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"typescript": ">=7.0.
|
|
51
|
+
"typescript": ">=7.0.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"typescript": {
|