@dokebi/i18n 0.2.4 → 0.2.5
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.js +7 -2
- package/dist/plugin.js +1 -1
- package/package.json +1 -1
package/AI.md
CHANGED
|
@@ -164,7 +164,7 @@ const { t, n, d, locale, switchLocale } = useI18n();
|
|
|
164
164
|
|
|
165
165
|
- **Which namespaces.** `http.pageMessages` (default `['*']`, every namespace) names what every page gets; a route adds more with `pageMessages(request, 'posts', 'editor')` before `render` (an unknown name fails that render with `UNKNOWN_NAMESPACE`). With `[]` pages get only what routes add (`locale`, `version` and `settings` still come).
|
|
166
166
|
- **Per app (D-0196).** Several apps on one server (a member site and an admin) share one catalog, so `['*']` sends the admin's wording in the member site's first HTML too, and a public page (D-0195) sends every bundle on every load. `http.apps.<app>.pageMessages` gives that app's pages their own list instead (`apps: { frontend: { pageMessages: [front, site, common] } }`); a route of the app still adds more with `pageMessages(request, …)`, and apps not listed get `http.pageMessages`. The app is @dokebi/web's `appOf(request)` (@dokebi/app answers it from the host); with `http.apps` and nothing that tells a request's app, the start warns `I18N_PAGE_APPS_UNUSED` and every page gets `http.pageMessages`. An app's list is joined like a route's table (`http.maxJoinedSets`).
|
|
167
|
-
- **Sent once per browser.** The runtime names what the document holds on every Inertia visit (request header `X-Dokebi-I18n: v=<version>; h=<token><token>…`, `PAGE_HEADER`, at most `http.maxPageHeaderBytes`); the prop then carries only bundles it lacks, and no `settings` while the version matches. Tokens address content, so after a deploy a visit gets the settings again but only the bundles whose messages changed. Unknown tokens, another locale's tokens and a malformed or over-long header mean "nothing held" (never an error). Inertia answers name `X-Dokebi-I18n` in `Vary`.
|
|
167
|
+
- **Sent once per browser.** The runtime names what the document holds on every Inertia visit (request header `X-Dokebi-I18n: v=<version>; h=<token><token>…`, `PAGE_HEADER`, at most `http.maxPageHeaderBytes`); the prop then carries only bundles it lacks, and no `settings` while the version matches. The header is read **only on an Inertia visit** (`X-Inertia: true`): a full page request that carries it (any client can send it) gets the whole payload, so HTML that a cache keeps never lacks bundles. Tokens address content, so after a deploy a visit gets the settings again but only the bundles whose messages changed. Unknown tokens, another locale's tokens and a malformed or over-long header mean "nothing held" (never an error). Inertia answers name `X-Dokebi-I18n` in `Vary`.
|
|
168
168
|
- **Kept between page loads (D-0126, `http.pageCache`, on by default).** The runtime keeps the bundles it receives in localStorage (one item per bundle, bounded by `maxBundles` and `maxStoreCharacters`) and writes the cookie `dokebi-i18n-held` with their tokens (`maxCookieBytes`; 61 bundles take 488 bytes). On a full page load (no header) the server leaves the bundles the cookie names out of the HTML and lists them in `held`; the settings always come. Measured with 85 bundles (125 KB Korean, example 48): a home page that needs 60 is 93 KB of HTML (44 KB gzip) on the first load and 2.4 KB (1.4 KB gzip) on a reload; a visit is unchanged. The cookie is no proof: when the browser lacks a named bundle (storage cleared, the cookie changed, the quota full) the runtime fetches the missing messages (an Inertia partial reload of `i18n`) **before it mounts** the app, so no screen is drawn without them; SSR renders the left-out bundles from the server's own catalogs. A seal host never reads the cookie and tells the browser to keep nothing. Turning `pageCache.enabled` off makes the server ignore the cookie (it expires by itself). The cookie and the store are browser data like a cache: an app with a strict cookie policy can turn it off.
|
|
169
169
|
- **Payload** (D-0099, measured on the example 37 blog catalogs: 166 messages per locale in five namespaces): the first Korean page with every namespace carries 10.7 KB (3.6 KB gzip) once; a later visit's prop is about 125 bytes. With `pageMessages: ['common']` the first page carries 1.3 KB, and the first visit that adds `posts` 3.1 KB. Choosing the prop costs well under a microsecond per page (fragments are joined at startup).
|
|
170
170
|
- **Language switch.** `switchLocale(locale)` writes the preference cookie (`settings.cookie`) and reloads the page's props through Inertia (no document reload); the server answers in the new language and sends what the browser does not hold yet. `<html lang>` follows.
|
package/dist/page.js
CHANGED
|
@@ -384,12 +384,17 @@ export class PageMessages {
|
|
|
384
384
|
// X-Dokebi-I18n, so a request that sent the header (the version and the tokens are in every
|
|
385
385
|
// page) would have left the bundles and the settings out of the HTML a shared cache then
|
|
386
386
|
// gives everyone (audit R9-g13-1).
|
|
387
|
-
|
|
387
|
+
// The visit header is a claim of the Inertia runtime, and only an Inertia visit's answer
|
|
388
|
+
// (JSON, never cached as a page) may lean on it. A full page request that carries it (any
|
|
389
|
+
// client can send it) gets the whole payload: its HTML may be kept by a cache the app set up
|
|
390
|
+
// (a URL-locale page has no Vary), and would then lack the bundles for everyone else.
|
|
391
|
+
const visit = request.headers['x-inertia'] === 'true';
|
|
392
|
+
const header = publicPage || !visit ? undefined : request.headers[PAGE_HEADER];
|
|
388
393
|
let claim = NOTHING;
|
|
389
394
|
let fromCookie = false;
|
|
390
395
|
if (header !== undefined)
|
|
391
396
|
claim = this.#fromHeader(header, at);
|
|
392
|
-
else if (this.#cookie && !sealed && !publicPage &&
|
|
397
|
+
else if (this.#cookie && !sealed && !publicPage && !visit) {
|
|
393
398
|
claim = this.#fromCookie(request.headers.cookie, at);
|
|
394
399
|
fromCookie = claim.namespaces.size > 0;
|
|
395
400
|
}
|
package/dist/plugin.js
CHANGED