@k8ordo/i18n 0.1.0 → 1.1.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/docs/llms.txt CHANGED
@@ -1,15 +1,19 @@
1
1
  # @k8ordo/i18n
2
2
 
3
- > The locale axis of an application, owned. `defineLocales(['ja', 'en'])`
4
- > declares the set once and derives membership, negotiation, the URL segment
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/static` / `@k8ordo/server` run, and the current locale
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`, the Server
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, `/` and `<html lang>`, static path expansion, and
28
- pairing with `@k8ordo/router` / `@k8ordo/ui` / `@k8ordo/form`.
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(all, { default? })` returns `{ all,
33
- default, is, negotiate, localize, delocalize, paramsSchema, getLocale,
34
- run }`; the first entry is the default unless told otherwise, every tag
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. `parseAcceptLanguage(header)` turns
39
- an `Accept-Language` header into a preference list. `message(variants)`
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": "0.1.0",
3
+ "version": "1.1.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.0",
44
- "publint": "0.3.24",
43
+ "@vitest/browser-playwright": "5.0.5",
44
+ "publint": "0.3.25",
45
45
  "typescript": "7.0.2",
46
- "vite": "8.2.2",
47
- "vite-plus": "0.3.0",
48
- "vitest": "5.0.0"
46
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
47
+ "vite-plus": "1.3.0",
48
+ "vitest": "5.0.5"
49
49
  },
50
50
  "peerDependencies": {
51
- "typescript": ">=7.0.2"
51
+ "typescript": ">=7.0.0"
52
52
  },
53
53
  "peerDependenciesMeta": {
54
54
  "typescript": {