@k8ordo/i18n 2.3.1 → 3.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 CHANGED
@@ -125,7 +125,7 @@ Where a Server Component hands text to a Client Component as a prop, it calls
125
125
  the message and passes the string: a function does not cross that boundary.
126
126
 
127
127
  `/` negotiates and redirects; `<html lang>` and a language switcher read
128
- `locales.getLocale()`, and `<html dir>` its `locales.definitions[…].dir`; a static build passes `paths: locales.paths`. Links
128
+ `locales.getLocale()`, and `<html dir>` its `locales.definitions[…].dir`; a static build's `src/routes/[locale]/paths.ts` returns `locales.all`. Links
129
129
  stay the router's: `bindParams(() => ({ locale: locales.getLocale() }))`
130
130
  (imported from `@k8ordo/framework` in a framework application) gives an `href` that spells `/:locale/…` patterns without the locale.
131
131
 
@@ -91,18 +91,6 @@ export type Locales<L extends string = string, D extends L = L> = IntlFormats &
91
91
  readonly localize: (pathname: string, locale: L) => string;
92
92
  /** The inverse: `'/en/ui'` → `{ locale: 'en', pathname: '/ui' }`, `'/x'` → `{ locale: null, pathname: '/x' }`. */
93
93
  readonly delocalize: (pathname: string) => Delocalized<L>;
94
- /**
95
- * The static build's `paths` option: every pattern that has a `/:locale`
96
- * segment, once per locale, so
97
- * `framework({ mode: 'static', paths: locales.paths })` is the whole
98
- * answer for a site whose only parameter is the locale. A pattern with
99
- * another parameter comes back still holding it (`/ja/blog/:slug`), which
100
- * the build renders only as the location of a `fallback.tsx`'s shell, and
101
- * otherwise refuses: expand the rest in the same function. A shell runs
102
- * only its layouts' schemas, so it renders in its locale when this set's
103
- * `paramsSchema` sits on `[locale]/layout.tsx`.
104
- */
105
- readonly paths: (patterns: readonly string[]) => string[];
106
94
  /**
107
95
  * A params schema for a `[locale]` route segment, in the shape
108
96
  * `@k8ordo/framework` runs: `export const paramsSchema =
package/dist/locales.mjs CHANGED
@@ -92,11 +92,6 @@ const defineLocales = (definitions, options) => {
92
92
  const chosen = cookie === void 0 ? null : readCookie(request.headers.get("cookie"), cookie);
93
93
  return negotiate([...chosen === null ? [] : [chosen], ...parseAcceptLanguage(request.headers.get("accept-language"))]);
94
94
  };
95
- const paths = (patterns) => patterns.flatMap((pattern) => {
96
- const segments = pattern.split("/");
97
- if (!segments.includes(":locale")) return [pattern];
98
- return list.map((locale) => segments.map((segment) => segment === ":locale" ? locale : segment).join("/"));
99
- });
100
95
  const delocalize = (pathname) => {
101
96
  const first = pathname.split("/")[1] ?? "";
102
97
  if (!is(first)) return {
@@ -140,7 +135,6 @@ const defineLocales = (definitions, options) => {
140
135
  negotiateRequest,
141
136
  localize,
142
137
  delocalize,
143
- paths,
144
138
  paramsSchema,
145
139
  getLocale,
146
140
  run,
package/docs/GUIDE.md CHANGED
@@ -118,7 +118,6 @@ the definition, not later.
118
118
  | `negotiateRequest(…)` | The best supported tag for a `Request`: a cookie, then `Accept-Language`. |
119
119
  | `localize` | `'/ui'` → `'/en/ui'`; `'/'` → `'/en'`. |
120
120
  | `delocalize` | `'/en/ui'` → `{ locale: 'en', pathname: '/ui' }`; `'/x'` → `{ locale: null, … }`. |
121
- | `paths` | The static build's `paths` option: `/:locale` expanded to every locale. |
122
121
  | `paramsSchema` | The `[locale]` segment's schema (Standard Schema; no schema library). |
123
122
  | `getLocale()` | The locale of the render in progress. Not a hook. |
124
123
  | `run(locale, fn)` | Server only: runs `fn` with `locale` current. |
@@ -449,33 +448,50 @@ const locale = locales.delocalize(pathname).locale ?? locales.default;
449
448
 
450
449
  ## Static builds
451
450
 
452
- Static mode asks for the pathnames of every pattern with a parameter.
453
- The set answers for its own segment:
451
+ Static mode asks each parameter's directory for the values it takes, in a
452
+ `paths.ts`. The locale directory answers with the set:
454
453
 
455
454
  ```ts
456
- framework({ mode: 'static', paths: locales.paths });
455
+ // src/routes/[locale]/paths.ts
456
+ import type { Paths } from '@k8ordo/framework';
457
+
458
+ import { locales } from '../../i18n';
459
+
460
+ const paths: Paths<'/:locale'> = () => locales.all;
461
+
462
+ export default paths;
463
+ ```
464
+
465
+ Every page, `route.ts` and `redirect.ts` below `[locale]/` is written once
466
+ per locale. A parameter further down has a `paths.ts` of its own, which
467
+ receives the locale it is asked for:
468
+
469
+ ```ts
470
+ // src/routes/[locale]/blog/[slug]/paths.ts
471
+ import type { Paths } from '@k8ordo/framework';
472
+
473
+ import { slugsIn } from '../../../../lib/blog';
474
+
475
+ const paths: Paths<'/:locale/blog/:slug'> = ({ locale }) => slugsIn(locale);
476
+
477
+ export default paths;
457
478
  ```
458
479
 
459
- `/:locale` in every pattern becomes one pathname per locale. A pattern with
460
- another parameter comes back still holding it (`/ja/blog/:slug`). Only a
461
- page with a `fallback.tsx` beside it takes such a pathname, as the location
462
- of its shell: one per locale, answering in the browser the slugs the build
463
- did not write. For any other route the build stops:
480
+ Without one the build stops:
464
481
 
465
482
  ```
466
- the "paths" option supplied pathnames that still hold a parameter, and only a page with a fallback.tsx beside it takes one: /ja/blog/:slug ([locale]/blog/[slug]/page.tsx has none)
483
+ static build needs the values of /:locale/blog/:slug — a paths.ts in each parameter's directory returns them, and a fallback.tsx beside a page answers the ones the build does not write
467
484
  ```
468
485
 
469
- A site with a second parameter expands the rest in the same function:
470
- `paths: (patterns) => locales.paths(patterns).flatMap(expandSlug)`, where
471
- `expandSlug` keeps `/ja/blog/:slug` beside the slugs for a page that has a
472
- `fallback.tsx`.
486
+ A page with a `fallback.tsx` beside it is the exception: its shell stands
487
+ below each locale (`/ja/blog/:slug`, `/en/blog/:slug`), answering in the
488
+ browser the slugs the build did not write.
473
489
 
474
490
  A shell runs the schemas of the layouts above it, never its page's: there
475
491
  is no value for the page's to parse. With the schema on
476
492
  `[locale]/layout.tsx`, as in [The shape of it](#the-shape-of-it), the
477
493
  locale is set for every page below it, shells included, and a shell's
478
- messages come out in the locale its location fills.
494
+ messages come out in the locale it stands under.
479
495
 
480
496
  Each path is rendered as its own request, so the schema names the locale
481
497
  for each and the messages come out in that locale; the build renders several
package/docs/llms.txt CHANGED
@@ -31,8 +31,8 @@ When installed via npm, these docs live under `node_modules/@k8ordo/i18n/docs/`.
31
31
  Component boundary (a message is called before it is passed to a
32
32
  `'use client'` component), what reaches the browser, where the locale comes
33
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` /
34
+ an effect in static mode) and `<html lang>` / `dir`, the static build's
35
+ `[locale]/paths.ts`, and pairing with `@k8ordo/router` / `@k8ordo/ui` /
36
36
  `@k8ordo/form`.
37
37
 
38
38
  ## Entry point
@@ -40,12 +40,13 @@ When installed via npm, these docs live under `node_modules/@k8ordo/i18n/docs/`.
40
40
  - `@k8ordo/i18n` — `defineLocales(definitions, { default? })` takes each
41
41
  locale's `{ timeZone, dir }` by tag (both required; an unknown time zone
42
42
  throws) and returns `{ all, definitions, default, is, negotiate, localize,
43
- delocalize, paths, paramsSchema, getLocale, run, negotiateRequest, dateTimeFormat,
43
+ delocalize, paramsSchema, getLocale, run, negotiateRequest, dateTimeFormat,
44
44
  numberFormat, relativeTimeFormat, pluralRules, listFormat }`; the last five
45
45
  return the `Intl` object for the current locale, cached per locale and
46
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
47
+ options type refuses one); a static build takes the locales from
48
+ `src/routes/[locale]/paths.ts`, which returns `locales.all`; typed links
49
+ come from
49
50
  the router's `bindParams(() => ({ locale: locales.getLocale() }))`,
50
51
  written by the application (imported from `@k8ordo/framework` in a
51
52
  framework application); the first entry is the default unless told otherwise (and `default` is then typed as the whole union), every tag
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k8ordo/i18n",
3
- "version": "2.3.1",
3
+ "version": "3.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,12 +40,12 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@arethetypeswrong/cli": "0.18.5",
43
- "@vitest/browser-playwright": "5.0.5",
43
+ "@vitest/browser-playwright": "5.1.0",
44
44
  "publint": "0.3.25",
45
45
  "typescript": "7.0.2",
46
46
  "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
47
47
  "vite-plus": "1.4.0",
48
- "vitest": "5.0.5"
48
+ "vitest": "5.1.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "typescript": ">=7.0.0"