@dokebi/i18n 0.2.1 → 0.2.2
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/AI.md +1 -1
- package/dist/page.d.ts +6 -1
- package/dist/page.js +8 -2
- package/dist/plugin.js +8 -2
- package/package.json +2 -2
package/AI.md
CHANGED
|
@@ -105,7 +105,7 @@ options:
|
|
|
105
105
|
|
|
106
106
|
With web registered, the plugin attaches `request.i18n`, selects a configured locale from the preference cookie, then Accept-Language, then the default locale. It contributes the `locale` and `i18n` page props through the existing web view-data point (`i18n`: §Vue pages). HTML, JSON (any JSON media type, `application/problem+json` included; the type is compared without case; also a JSON answer @dokebi/web sealed on a seal host, `x-dokebi-sealed-path`) and Inertia responses preserve existing Vary fields and include Accept-Language and Cookie. Other response types have no added language header (the adapter removes only the label it wrote; one the answer set itself stays, also when it equals the selected locale). A Content-Language the handler or an error handler sets on a document is the body's real language and is kept (an untranslated English error answers `en` on a French request). The adapter never rewrites HTML. Inertia 0.4.4 renders a single Content-Language tag as the document's `lang` attribute; EJS templates use the contributed locale explicitly.
|
|
107
107
|
|
|
108
|
-
**Locales in the URL** (`/ja/p/1`, `/products/:id?lang=`… as a route parameter): the answer varies by its URL only, so it must not say `Vary: Accept-Language, Cookie` (a shared cache or CDN could not keep a public page) and its `Content-Language` is the URL's locale. With `http.pathLocale: true` a first path segment that is a configured locale decides by itself (no cookie, no Accept-Language; `/fr/nowhere` too, so the app's own 404 page under `/fr/` says `fr`); a path without such a segment (`/`, a redirect page) negotiates as above and varies by it. For a route parameter call `useUrlLocale(request, reply, locale)` before rendering: it switches `request.i18n` (and the page props `locale`/`i18n`), relabels `Content-Language` unless the answer set its own, and drops the Vary; a locale without a catalog is `INVALID_LOCALE` (answer your 404). An Inertia visit still varies by `X-Dokebi-I18n`, and a full page load whose bundles the `http.pageCache` cookie left out (`held`) says `Vary: Cookie`: that HTML is right only for the browser that keeps those bundles, so a shared cache must not hand it to another one. An answer's own `Content-Language` stays (web's untranslated error pages say `en`). The browser runtime's `switchLocale` writes the preference cookie; with URL locales navigate to the other URL instead.
|
|
108
|
+
**Locales in the URL** (`/ja/p/1`, `/products/:id?lang=`… as a route parameter): the answer varies by its URL only, so it must not say `Vary: Accept-Language, Cookie` (a shared cache or CDN could not keep a public page) and its `Content-Language` is the URL's locale. With `http.pathLocale: true` a first path segment that is a configured locale decides by itself (no cookie, no Accept-Language; `/fr/nowhere` too, so the app's own 404 page under `/fr/` says `fr`); a path without such a segment (`/`, a redirect page) negotiates as above and varies by it. For a route parameter call `useUrlLocale(request, reply, locale)` before rendering: it switches `request.i18n` (and the page props `locale`/`i18n`), relabels `Content-Language` unless the answer set its own, and drops the Vary; a locale without a catalog is `INVALID_LOCALE` (answer your 404). An Inertia visit still varies by `X-Dokebi-I18n`, and a full page load whose bundles the `http.pageCache` cookie left out (`held`) says `Vary: Cookie`: that HTML is right only for the browser that keeps those bundles, so a shared cache must not hand it to another one. The first HTML of a template-inertia **public page** (`render(…, { public: true })`, 0.2.2, D-0195) reads no such cookie: `locale` and `i18n` are view data marked `public`, and asked for a public page they send every bundle, so that HTML is the same for every browser of the URL and language (no `Vary: Cookie`). An answer's own `Content-Language` stays (web's untranslated error pages say `en`). The browser runtime's `switchLocale` writes the preference cookie; with URL locales navigate to the other URL instead.
|
|
109
109
|
|
|
110
110
|
The cookie is a client preference, not authentication. Only known locale values are accepted; a Cookie header above `http.maxCookieHeaderBytes` (16 KiB) is ignored. This plugin reads but does not write the preference cookie. Browser locale selection can continue to write it. All-excluded Accept-Language preferences fall back to the configured default in the automatic adapter, and so does a header past the `negotiate` input limits (it is client input, not a server error: the request continues, with a debug log `I18N_HTTP_HEADER_IGNORED`). An endpoint that requires 406 explicitly checks `negotiate` as in example 42.
|
|
111
111
|
|
package/dist/page.d.ts
CHANGED
|
@@ -89,5 +89,10 @@ export declare class PageMessages {
|
|
|
89
89
|
readonly headers: Record<string, unknown>;
|
|
90
90
|
}, locale: string, sealed?: boolean,
|
|
91
91
|
/** D-0181: the request's app; its scope's bundles (the base for an app without a layer). */
|
|
92
|
-
app?: string
|
|
92
|
+
app?: string,
|
|
93
|
+
/**
|
|
94
|
+
* D-0195: the first HTML of a public page, the same for every visitor: the claim cookie is
|
|
95
|
+
* not read, so every bundle is sent.
|
|
96
|
+
*/
|
|
97
|
+
publicPage?: boolean): PageI18nPayload;
|
|
93
98
|
}
|
package/dist/page.js
CHANGED
|
@@ -345,7 +345,12 @@ export class PageMessages {
|
|
|
345
345
|
*/
|
|
346
346
|
value(request, locale, sealed = false,
|
|
347
347
|
/** D-0181: the request's app; its scope's bundles (the base for an app without a layer). */
|
|
348
|
-
app
|
|
348
|
+
app,
|
|
349
|
+
/**
|
|
350
|
+
* D-0195: the first HTML of a public page, the same for every visitor: the claim cookie is
|
|
351
|
+
* not read, so every bundle is sent.
|
|
352
|
+
*/
|
|
353
|
+
publicPage = false) {
|
|
349
354
|
const at = slot(app !== undefined && this.#scopes.has(app) ? app : BASE, locale);
|
|
350
355
|
const fragments = this.#fragments.get(at);
|
|
351
356
|
const chain = this.#chains.get(at);
|
|
@@ -369,7 +374,7 @@ export class PageMessages {
|
|
|
369
374
|
let fromCookie = false;
|
|
370
375
|
if (header !== undefined)
|
|
371
376
|
claim = this.#fromHeader(header, at);
|
|
372
|
-
else if (this.#cookie && !sealed && request.headers['x-inertia'] !== 'true') {
|
|
377
|
+
else if (this.#cookie && !sealed && !publicPage && request.headers['x-inertia'] !== 'true') {
|
|
373
378
|
claim = this.#fromCookie(request.headers.cookie, at);
|
|
374
379
|
fromCookie = claim.namespaces.size > 0;
|
|
375
380
|
}
|
|
@@ -418,6 +423,7 @@ export class PageMessages {
|
|
|
418
423
|
sent: missing.length,
|
|
419
424
|
held: wanted.length - missing.length,
|
|
420
425
|
claim: header !== undefined ? 'header' : fromCookie ? 'cookie' : 'none',
|
|
426
|
+
...(publicPage ? { publicPage } : {}),
|
|
421
427
|
settings,
|
|
422
428
|
});
|
|
423
429
|
return {
|
package/dist/plugin.js
CHANGED
|
@@ -43,14 +43,20 @@ export class I18nRuntime {
|
|
|
43
43
|
negotiation: negotiationLimits(this.#options),
|
|
44
44
|
...(appOf ? { appOf } : {}),
|
|
45
45
|
}, 'X-Dokebi-I18n'), {});
|
|
46
|
+
// D-0195: both are the same for every visitor of a URL and language, so they go into
|
|
47
|
+
// the first HTML of a public page (template-inertia `render(…, { public: true })`).
|
|
46
48
|
context.contribute(localeData, {
|
|
47
49
|
key: 'locale',
|
|
50
|
+
public: true,
|
|
48
51
|
value: (request) => request.i18n?.locale ?? api.defaultLocale,
|
|
49
52
|
});
|
|
50
53
|
context.contribute(localeData, {
|
|
51
54
|
key: 'i18n',
|
|
55
|
+
public: true,
|
|
52
56
|
// D-0126: a sealed answer's browser keeps no bundles (the page leaves through the seal).
|
|
53
|
-
|
|
57
|
+
// D-0195: a public page's first HTML sends every bundle (the claim cookie of this
|
|
58
|
+
// browser is not read), so one HTML serves every visitor of the URL and language.
|
|
59
|
+
value: (request, view) => page.value(request, request.i18n?.locale ?? api.defaultLocale, server.sealOf(request) !== undefined, appOf?.(request), view?.public === true),
|
|
54
60
|
});
|
|
55
61
|
context.defer(() => page.close());
|
|
56
62
|
context.logger.log('debug', 'Translation HTTP integration registered', {
|
|
@@ -82,7 +88,7 @@ export class I18nRuntime {
|
|
|
82
88
|
}
|
|
83
89
|
export const createPlugin = definePlugin({
|
|
84
90
|
name: 'dokebi-i18n',
|
|
85
|
-
version: '0.2.
|
|
91
|
+
version: '0.2.2',
|
|
86
92
|
core: '^0.4.0',
|
|
87
93
|
options,
|
|
88
94
|
contributes: [localeData],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/i18n",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Compiled translation catalogs, locale negotiation, cardinal plurals and named Intl formats.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dokebi",
|
|
@@ -97,6 +97,6 @@
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
|
-
"@dokebi/web": "0.4.
|
|
100
|
+
"@dokebi/web": "0.4.6"
|
|
101
101
|
}
|
|
102
102
|
}
|