@trebired/frontend 12.18.0 → 13.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/CHANGELOG.md +15 -0
- package/dist/language/routing/boot.d.ts +6 -2
- package/dist/language/routing/boot.d.ts.map +1 -1
- package/dist/language/routing/boot.js +25 -18
- package/dist/language/routing/boot.js.map +1 -1
- package/dist/language/routing/document.d.ts +10 -0
- package/dist/language/routing/document.d.ts.map +1 -0
- package/dist/language/routing/document.js +63 -0
- package/dist/language/routing/document.js.map +1 -0
- package/dist/language/routing/index.d.ts +10 -5
- package/dist/language/routing/index.d.ts.map +1 -1
- package/dist/language/routing/index.js +5 -3
- package/dist/language/routing/index.js.map +1 -1
- package/dist/language/routing/options.d.ts +6 -2
- package/dist/language/routing/options.d.ts.map +1 -1
- package/dist/language/routing/options.js +3 -1
- package/dist/language/routing/options.js.map +1 -1
- package/dist/language/routing/runtime.d.ts +1 -2
- package/dist/language/routing/runtime.d.ts.map +1 -1
- package/dist/language/routing/runtime.js +20 -14
- package/dist/language/routing/runtime.js.map +1 -1
- package/dist/language/routing/shell.d.ts +22 -0
- package/dist/language/routing/shell.d.ts.map +1 -0
- package/dist/language/routing/shell.js +34 -0
- package/dist/language/routing/shell.js.map +1 -0
- package/dist/language/routing/view.d.ts +16 -0
- package/dist/language/routing/view.d.ts.map +1 -0
- package/dist/language/routing/view.js +66 -0
- package/dist/language/routing/view.js.map +1 -0
- package/dist/react/locale.d.ts.map +1 -1
- package/dist/react/locale.js +13 -9
- package/dist/react/locale.js.map +1 -1
- package/dist/server/language.d.ts.map +1 -1
- package/dist/server/language.js +2 -1
- package/dist/server/language.js.map +1 -1
- package/dist/spa/fetch-document.d.ts +6 -0
- package/dist/spa/fetch-document.d.ts.map +1 -0
- package/dist/spa/fetch-document.js +23 -0
- package/dist/spa/fetch-document.js.map +1 -0
- package/dist/spa/navigate.d.ts.map +1 -1
- package/dist/spa/navigate.js +2 -21
- package/dist/spa/navigate.js.map +1 -1
- package/dist/src/language/routing/boot.d.ts +6 -2
- package/dist/src/language/routing/boot.d.ts.map +1 -1
- package/dist/src/language/routing/boot.js +25 -18
- package/dist/src/language/routing/boot.js.map +1 -1
- package/dist/src/language/routing/document.d.ts +10 -0
- package/dist/src/language/routing/document.d.ts.map +1 -0
- package/dist/src/language/routing/document.js +63 -0
- package/dist/src/language/routing/document.js.map +1 -0
- package/dist/src/language/routing/index.d.ts +10 -5
- package/dist/src/language/routing/index.d.ts.map +1 -1
- package/dist/src/language/routing/index.js +5 -3
- package/dist/src/language/routing/index.js.map +1 -1
- package/dist/src/language/routing/options.d.ts +6 -2
- package/dist/src/language/routing/options.d.ts.map +1 -1
- package/dist/src/language/routing/options.js +3 -1
- package/dist/src/language/routing/options.js.map +1 -1
- package/dist/src/language/routing/runtime.d.ts +1 -2
- package/dist/src/language/routing/runtime.d.ts.map +1 -1
- package/dist/src/language/routing/runtime.js +20 -14
- package/dist/src/language/routing/runtime.js.map +1 -1
- package/dist/src/language/routing/shell.d.ts +22 -0
- package/dist/src/language/routing/shell.d.ts.map +1 -0
- package/dist/src/language/routing/shell.js +34 -0
- package/dist/src/language/routing/shell.js.map +1 -0
- package/dist/src/language/routing/view.d.ts +16 -0
- package/dist/src/language/routing/view.d.ts.map +1 -0
- package/dist/src/language/routing/view.js +66 -0
- package/dist/src/language/routing/view.js.map +1 -0
- package/dist/src/react/locale.d.ts.map +1 -1
- package/dist/src/react/locale.js +13 -9
- package/dist/src/react/locale.js.map +1 -1
- package/dist/src/server/language.d.ts.map +1 -1
- package/dist/src/server/language.js +2 -1
- package/dist/src/server/language.js.map +1 -1
- package/dist/src/spa/fetch-document.d.ts +6 -0
- package/dist/src/spa/fetch-document.d.ts.map +1 -0
- package/dist/src/spa/fetch-document.js +23 -0
- package/dist/src/spa/fetch-document.js.map +1 -0
- package/dist/src/spa/navigate.d.ts.map +1 -1
- package/dist/src/spa/navigate.js +2 -21
- package/dist/src/spa/navigate.js.map +1 -1
- package/package.json +1 -1
- package/dist/language/routing/path.d.ts +0 -20
- package/dist/language/routing/path.d.ts.map +0 -1
- package/dist/language/routing/path.js +0 -43
- package/dist/language/routing/path.js.map +0 -1
- package/dist/src/language/routing/path.d.ts +0 -20
- package/dist/src/language/routing/path.d.ts.map +0 -1
- package/dist/src/language/routing/path.js +0 -43
- package/dist/src/language/routing/path.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@ All notable changes to `@trebired/frontend` will be documented here.
|
|
|
4
4
|
|
|
5
5
|
This project follows semantic versioning once published.
|
|
6
6
|
|
|
7
|
+
## 13.1.0
|
|
8
|
+
|
|
9
|
+
- Added `createLocaleShellRoutes()`, so a statically prerendered site can have every language indexed without sending visitors anywhere. It renders each route once per locale and returns the documents to write. With `strategy: "none"` each route is served once in the default locale. With `strategy: "prefix"` each non-default locale also gets its own URL (`/en`, `/en/about`), rendered in that locale with the others as switchable templates and carrying that locale's head, so its canonical URL and `hreflang` links come from `@trebired/seo`. Pass `@trebired/seo`'s `localeStrategy` as the strategy; that config is the one switch.
|
|
10
|
+
- Visitors are never redirected to those URLs. Switching language still re-renders in place and leaves the URL alone; a visitor arriving on a locale URL from a search result sees their saved language if they have one.
|
|
11
|
+
- `createLocaleBootScript()` takes the same `strategy`. With `"prefix"` it no longer picks the browser language, so a crawler rendering a page with an English browser indexes each URL in its own language instead of seeing it swapped. A saved choice still applies.
|
|
12
|
+
|
|
13
|
+
## 13.0.0
|
|
14
|
+
|
|
15
|
+
- Statically prerendered sites now serve every language from one URL and switch language in place. 12.15.0 gave each locale its own prefixed URL and changed language by navigating to it, so every switch reloaded the page and a saved preference redirected before paint.
|
|
16
|
+
- `createLocaleDocumentBody()` composes a route's prerendered bodies: the default locale as live markup, every other locale in an inert `<template>`, a title and description per locale, and a short inline script. `createLocaleBootScript()` resolves the locale before first paint (stored choice, then the `ui_lang` cookie the server runtime also reads, then the browser language) and sets `<html lang>`. When that differs from the prerendered locale, the inline script swaps the matching template in while the document is still parsing, so a reload shows the right language without waiting for the application bundle. Templates are inert, so their images and frames do not load and crawlers index the default locale.
|
|
17
|
+
- `setCurrentLocale()` no longer navigates. It persists the choice, updates `<html lang>`, the title and the description, and notifies `onLocaleChanged()` listeners. `LocaleProvider` and `useLocale()` follow it, so every React root re-renders in place. Pass `locale` to `LocaleProvider` only when rendering on the server.
|
|
18
|
+
- Soft navigation applies the same swap to the document it fetches, so moving between routes stays in the chosen language.
|
|
19
|
+
- Removed `parseLocalePathname()`, `buildLocalePathname()`, `localeShellRoutes()`, `localeShellOutFile()`, `normalizePathname()` and `localeHref()`. Prerender each route once per locale and pass the bodies to `createLocaleDocumentBody()`; set `@trebired/seo`'s `localeStrategy` to `"none"`.
|
|
20
|
+
- The server-backed `bindLocaleSwitchers()` model is unchanged.
|
|
21
|
+
|
|
7
22
|
## 12.18.0
|
|
8
23
|
|
|
9
24
|
- Added the `components.media` token group, so an application can shape `ExpandableImage` and the lightbox from its frontend config instead of overriding package CSS. `expandableImage.icon` sets the hover badge's size, radius, background and blur. `lightbox` sets the backdrop colour and blur, the close and navigation controls (size, wide-screen size, radius, background, blur, hover background), the image radius and shadow, and the caption colour, size and weight. The defaults are the values the styles used before, so an application that sets nothing renders exactly as it did.
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type { LocaleRoutingOptions } from "./options.js";
|
|
2
|
-
|
|
1
|
+
import type { LocaleRoutingOptions, LocaleStrategy } from "./options.js";
|
|
2
|
+
type LocaleBootOptions = {
|
|
3
|
+
strategy?: LocaleStrategy;
|
|
4
|
+
};
|
|
5
|
+
declare function createLocaleBootScript(options?: LocaleRoutingOptions, boot?: LocaleBootOptions): string;
|
|
3
6
|
export { createLocaleBootScript };
|
|
7
|
+
export type { LocaleBootOptions };
|
|
4
8
|
//# sourceMappingURL=boot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boot.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/boot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"boot.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/boot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAoCzE,KAAK,iBAAiB,GAAG;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,iBAAS,sBAAsB,CAAC,OAAO,GAAE,oBAAyB,EAAE,IAAI,GAAE,iBAAsB,GAAG,MAAM,CAgBxG;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAClC,YAAY,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
import { normalizeLocaleRouting } from "./options.js";
|
|
2
|
+
import { LOCALE_PENDING_ATTR, LOCALE_RENDERED_ATTR } from "./view.js";
|
|
2
3
|
function scriptJson(value) {
|
|
3
4
|
return JSON.stringify(value ?? null).replace(/</gu, "\\u003c");
|
|
4
5
|
}
|
|
5
|
-
function
|
|
6
|
+
function matchSource() {
|
|
6
7
|
return [
|
|
7
|
-
"var
|
|
8
|
-
"if(L.indexOf(
|
|
8
|
+
"function m(v){var t=String(v||'').trim().toLowerCase().replace(/_/g,'-');",
|
|
9
|
+
"if(L.indexOf(t)>=0)return t;var b=t.split('-')[0];return L.indexOf(b)>=0?b:''}",
|
|
9
10
|
];
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
+
function storedLocaleSource() {
|
|
12
13
|
return [
|
|
13
|
-
"var
|
|
14
|
-
"if(
|
|
14
|
+
"var n='';try{n=m(window.localStorage.getItem(K))}catch(e){}",
|
|
15
|
+
"if(!n){try{var c=('; '+d.cookie).split('; '+C+'=');",
|
|
16
|
+
"if(c.length>1)n=m(decodeURIComponent(c[1].split(';')[0]))}catch(e){}}",
|
|
15
17
|
];
|
|
16
18
|
}
|
|
17
19
|
function navigatorLocaleSource() {
|
|
18
20
|
return [
|
|
19
21
|
"if(!n){try{var g=navigator.languages||[navigator.language||''];",
|
|
20
|
-
"for(var i=0;i<g.length;i++)
|
|
21
|
-
"var b=t.split('-')[0];",
|
|
22
|
-
"if(L.indexOf(t)>=0){n=t;break}if(L.indexOf(b)>=0){n=b;break}}}catch(e){}}",
|
|
22
|
+
"for(var i=0;i<g.length&&!n;i++)n=m(g[i])}catch(e){}}",
|
|
23
23
|
];
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function pendingSource() {
|
|
26
|
+
return [
|
|
27
|
+
"if(n!==r){h.setAttribute(P,'');h.style.visibility='hidden';",
|
|
28
|
+
"d.addEventListener('DOMContentLoaded',function(){h.removeAttribute(P);h.style.visibility=''})}",
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
function createLocaleBootScript(options = {}, boot = {}) {
|
|
26
32
|
const routing = normalizeLocaleRouting(options);
|
|
33
|
+
const detectBrowser = boot.strategy !== "prefix";
|
|
27
34
|
return [
|
|
28
35
|
"(function(){",
|
|
29
36
|
`var L=${scriptJson(routing.locales)},D=${scriptJson(routing.defaultLocale)},`,
|
|
30
|
-
`K=${scriptJson(routing.storageKey)}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...
|
|
34
|
-
|
|
35
|
-
...navigatorLocaleSource(),
|
|
36
|
-
"
|
|
37
|
-
|
|
37
|
+
`K=${scriptJson(routing.storageKey)},C=${scriptJson(routing.cookieName)},`,
|
|
38
|
+
`R=${scriptJson(LOCALE_RENDERED_ATTR)},P=${scriptJson(LOCALE_PENDING_ATTR)};`,
|
|
39
|
+
"var d=document,h=d.documentElement,r=h.lang||D;h.setAttribute(R,r);",
|
|
40
|
+
...matchSource(),
|
|
41
|
+
...storedLocaleSource(),
|
|
42
|
+
...(detectBrowser ? navigatorLocaleSource() : []),
|
|
43
|
+
"n=n||r;h.lang=n;",
|
|
44
|
+
...pendingSource(),
|
|
38
45
|
"})();",
|
|
39
46
|
].join("");
|
|
40
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boot.js","sourceRoot":"","sources":["../../../../src/language/routing/boot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"boot.js","sourceRoot":"","sources":["../../../../src/language/routing/boot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtE,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,WAAW;IAClB,OAAO;QACL,2EAA2E;QAC3E,gFAAgF;KACjF,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB;IACzB,OAAO;QACL,6DAA6D;QAC7D,qDAAqD;QACrD,uEAAuE;KACxE,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB;IAC5B,OAAO;QACL,iEAAiE;QACjE,sDAAsD;KACvD,CAAC;AACJ,CAAC;AAED,SAAS,aAAa;IACpB,OAAO;QACL,6DAA6D;QAC7D,gGAAgG;KACjG,CAAC;AACJ,CAAC;AAMD,SAAS,sBAAsB,CAAC,UAAgC,EAAE,EAAE,OAA0B,EAAE;IAC9F,MAAM,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC;IACjD,OAAO;QACL,cAAc;QACd,SAAS,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG;QAC9E,KAAK,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG;QAC1E,KAAK,UAAU,CAAC,oBAAoB,CAAC,MAAM,UAAU,CAAC,mBAAmB,CAAC,GAAG;QAC7E,qEAAqE;QACrE,GAAG,WAAW,EAAE;QAChB,GAAG,kBAAkB,EAAE;QACvB,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,qBAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,kBAAkB;QAClB,GAAG,aAAa,EAAE;QAClB,OAAO;KACR,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACb,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LocaleMeta } from "./view.js";
|
|
2
|
+
type LocaleDocumentBodyOptions = {
|
|
3
|
+
bodies: Record<string, string>;
|
|
4
|
+
defaultLocale: string;
|
|
5
|
+
meta?: Record<string, LocaleMeta>;
|
|
6
|
+
};
|
|
7
|
+
declare function createLocaleDocumentBody(options: LocaleDocumentBodyOptions): string;
|
|
8
|
+
export { createLocaleDocumentBody };
|
|
9
|
+
export type { LocaleDocumentBodyOptions };
|
|
10
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/document.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,KAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACnC,CAAC;AA+CF,iBAAS,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAkB5E;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC;AACpC,YAAY,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { cleanLocale } from "./options.js";
|
|
2
|
+
import { LOCALE_END_MARK, LOCALE_META_ATTR, LOCALE_PENDING_ATTR, LOCALE_RENDERED_ATTR, LOCALE_START_MARK, LOCALE_VIEW_ATTR, } from "./view.js";
|
|
3
|
+
function scriptJson(value) {
|
|
4
|
+
return JSON.stringify(value ?? null).replace(/</gu, "\\u003c");
|
|
5
|
+
}
|
|
6
|
+
function attributeValue(value) {
|
|
7
|
+
return value.replace(/&/gu, "&").replace(/"/gu, """).replace(/</gu, "<");
|
|
8
|
+
}
|
|
9
|
+
function swapNodesSource() {
|
|
10
|
+
return [
|
|
11
|
+
"var t=null,q=d.querySelectorAll('template['+V+']');",
|
|
12
|
+
"for(var i=0;i<q.length;i++)if(q[i].getAttribute(V)===l)t=q[i];",
|
|
13
|
+
"var s=null,e=null,c=b.childNodes;",
|
|
14
|
+
"for(var k=0;k<c.length;k++){if(c[k].nodeType!==8)continue;",
|
|
15
|
+
"if(c[k].nodeValue===S)s=c[k];if(c[k].nodeValue===E)e=c[k]}",
|
|
16
|
+
"if(t&&s&&e){while(s.nextSibling&&s.nextSibling!==e)b.removeChild(s.nextSibling);",
|
|
17
|
+
"b.insertBefore(d.importNode(t.content,true),e);h.setAttribute(R,l);",
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
function swapMetaSource() {
|
|
21
|
+
return [
|
|
22
|
+
"var m=d.querySelector('script['+M+']'),x=m?JSON.parse(m.textContent||'{}')[l]:null;",
|
|
23
|
+
"if(x&&x.title)d.title=x.title;",
|
|
24
|
+
"var n=d.querySelector('meta[name=\"description\"]');",
|
|
25
|
+
"if(x&&x.description&&n)n.setAttribute('content',x.description)",
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
function localeSwapScript() {
|
|
29
|
+
return [
|
|
30
|
+
"(function(){",
|
|
31
|
+
`var V=${scriptJson(LOCALE_VIEW_ATTR)},M=${scriptJson(LOCALE_META_ATTR)},`,
|
|
32
|
+
`R=${scriptJson(LOCALE_RENDERED_ATTR)},P=${scriptJson(LOCALE_PENDING_ATTR)},`,
|
|
33
|
+
`S=${scriptJson(LOCALE_START_MARK)},E=${scriptJson(LOCALE_END_MARK)};`,
|
|
34
|
+
"var d=document,h=d.documentElement,b=d.body,l=h.lang;",
|
|
35
|
+
"try{if(h.getAttribute(R)!==l){",
|
|
36
|
+
...swapNodesSource(),
|
|
37
|
+
...swapMetaSource(),
|
|
38
|
+
"}else h.lang=h.getAttribute(R)||l}}catch(err){h.lang=h.getAttribute(R)||l}",
|
|
39
|
+
"h.removeAttribute(P);h.style.visibility='';",
|
|
40
|
+
"})();",
|
|
41
|
+
].join("");
|
|
42
|
+
}
|
|
43
|
+
function createLocaleDocumentBody(options) {
|
|
44
|
+
const defaultLocale = cleanLocale(options.defaultLocale);
|
|
45
|
+
const entries = Object.entries(options.bodies).map(([locale, body]) => [cleanLocale(locale), String(body ?? "")]);
|
|
46
|
+
const primary = entries.find(([locale]) => locale === defaultLocale)?.[1] ?? "";
|
|
47
|
+
const templates = entries
|
|
48
|
+
.filter(([locale]) => locale !== defaultLocale)
|
|
49
|
+
.map(([locale, body]) => `<template ${LOCALE_VIEW_ATTR}="${attributeValue(locale)}">${body}</template>`);
|
|
50
|
+
const meta = options.meta
|
|
51
|
+
? `<script type="application/json" ${LOCALE_META_ATTR}>${scriptJson(options.meta)}</script>`
|
|
52
|
+
: "";
|
|
53
|
+
return [
|
|
54
|
+
`<!--${LOCALE_START_MARK}-->`,
|
|
55
|
+
primary,
|
|
56
|
+
`<!--${LOCALE_END_MARK}-->`,
|
|
57
|
+
...templates,
|
|
58
|
+
meta,
|
|
59
|
+
`<script>${localeSwapScript()}</script>`,
|
|
60
|
+
].join("");
|
|
61
|
+
}
|
|
62
|
+
export { createLocaleDocumentBody };
|
|
63
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../../../src/language/routing/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,WAAW,CAAC;AASnB,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACvF,CAAC;AAED,SAAS,eAAe;IACtB,OAAO;QACL,qDAAqD;QACrD,gEAAgE;QAChE,mCAAmC;QACnC,4DAA4D;QAC5D,4DAA4D;QAC5D,kFAAkF;QAClF,qEAAqE;KACtE,CAAC;AACJ,CAAC;AAED,SAAS,cAAc;IACrB,OAAO;QACL,qFAAqF;QACrF,gCAAgC;QAChC,sDAAsD;QACtD,gEAAgE;KACjE,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB;IACvB,OAAO;QACL,cAAc;QACd,SAAS,UAAU,CAAC,gBAAgB,CAAC,MAAM,UAAU,CAAC,gBAAgB,CAAC,GAAG;QAC1E,KAAK,UAAU,CAAC,oBAAoB,CAAC,MAAM,UAAU,CAAC,mBAAmB,CAAC,GAAG;QAC7E,KAAK,UAAU,CAAC,iBAAiB,CAAC,MAAM,UAAU,CAAC,eAAe,CAAC,GAAG;QACtE,uDAAuD;QACvD,gCAAgC;QAChC,GAAG,eAAe,EAAE;QACpB,GAAG,cAAc,EAAE;QACnB,4EAA4E;QAC5E,6C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|
|
|
1
1
|
export { createLocaleBootScript } from "./boot.js";
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
5
|
-
export type { LocaleShellRoute,
|
|
6
|
-
export {
|
|
2
|
+
export type { LocaleBootOptions } from "./boot.js";
|
|
3
|
+
export { createLocaleDocumentBody } from "./document.js";
|
|
4
|
+
export { createLocaleShellRoutes } from "./shell.js";
|
|
5
|
+
export type { LocaleShellRoute, LocaleShellRoutesOptions } from "./shell.js";
|
|
6
|
+
export type { LocaleDocumentBodyOptions } from "./document.js";
|
|
7
|
+
export { DEFAULT_LOCALE_COOKIE_NAME, DEFAULT_LOCALE_STORAGE_KEY, cleanLocale, matchLocale, normalizeLocaleRouting, pickLocale, } from "./options.js";
|
|
8
|
+
export type { LocaleRouting, LocaleRoutingOptions, LocaleStrategy } from "./options.js";
|
|
9
|
+
export { configureLocaleRouting, currentLocale, getLocaleRouting, onLocaleChanged, persistLocale, setCurrentLocale, } from "./runtime.js";
|
|
7
10
|
export type { LocaleListener } from "./runtime.js";
|
|
11
|
+
export { applyLocaleMeta, applyLocaleView, readLocaleMeta } from "./view.js";
|
|
12
|
+
export type { LocaleMeta } from "./view.js";
|
|
8
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,YAAY,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAC7E,YAAY,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC7E,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { createLocaleBootScript } from "./boot.js";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
2
|
+
export { createLocaleDocumentBody } from "./document.js";
|
|
3
|
+
export { createLocaleShellRoutes } from "./shell.js";
|
|
4
|
+
export { DEFAULT_LOCALE_COOKIE_NAME, DEFAULT_LOCALE_STORAGE_KEY, cleanLocale, matchLocale, normalizeLocaleRouting, pickLocale, } from "./options.js";
|
|
5
|
+
export { configureLocaleRouting, currentLocale, getLocaleRouting, onLocaleChanged, persistLocale, setCurrentLocale, } from "./runtime.js";
|
|
6
|
+
export { applyLocaleMeta, applyLocaleView, readLocaleMeta } from "./view.js";
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/language/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/language/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
+
type LocaleStrategy = "none" | "prefix";
|
|
1
2
|
type LocaleRoutingOptions = {
|
|
3
|
+
cookieName?: string;
|
|
2
4
|
defaultLocale?: string;
|
|
3
5
|
locales?: readonly string[];
|
|
4
6
|
storageKey?: string;
|
|
5
7
|
};
|
|
6
8
|
type LocaleRouting = {
|
|
9
|
+
cookieName: string;
|
|
7
10
|
defaultLocale: string;
|
|
8
11
|
locales: string[];
|
|
9
12
|
storageKey: string;
|
|
10
13
|
};
|
|
11
14
|
declare const DEFAULT_LOCALE_STORAGE_KEY = "tbf.locale";
|
|
15
|
+
declare const DEFAULT_LOCALE_COOKIE_NAME = "ui_lang";
|
|
12
16
|
declare function cleanLocale(value: unknown): string;
|
|
13
17
|
declare function normalizeLocaleRouting(options?: LocaleRoutingOptions): LocaleRouting;
|
|
14
18
|
declare function matchLocale(value: unknown, routing: LocaleRouting): string;
|
|
15
19
|
declare function pickLocale(values: Iterable<unknown>, routing: LocaleRouting): string;
|
|
16
|
-
export { DEFAULT_LOCALE_STORAGE_KEY, cleanLocale, matchLocale, normalizeLocaleRouting, pickLocale };
|
|
17
|
-
export type { LocaleRouting, LocaleRoutingOptions };
|
|
20
|
+
export { DEFAULT_LOCALE_COOKIE_NAME, DEFAULT_LOCALE_STORAGE_KEY, cleanLocale, matchLocale, normalizeLocaleRouting, pickLocale, };
|
|
21
|
+
export type { LocaleRouting, LocaleRoutingOptions, LocaleStrategy };
|
|
18
22
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/options.ts"],"names":[],"mappings":"AAEA,KAAK,oBAAoB,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,QAAA,MAAM,0BAA0B,eAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/options.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG,MAAM,GAAG,QAAQ,CAAC;AAExC,KAAK,oBAAoB,GAAG;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,QAAA,MAAM,0BAA0B,eAA8B,CAAC;AAC/D,QAAA,MAAM,0BAA0B,YAAY,CAAC;AAE7C,iBAAS,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE3C;AAED,iBAAS,sBAAsB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CAUjF;AAED,iBAAS,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAMnE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAM7E;AAED,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,UAAU,GACX,CAAC;AACF,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FRONTEND_PREFIX } from "../../namespace/index.js";
|
|
2
2
|
const DEFAULT_LOCALE_STORAGE_KEY = `${FRONTEND_PREFIX}.locale`;
|
|
3
|
+
const DEFAULT_LOCALE_COOKIE_NAME = "ui_lang";
|
|
3
4
|
function cleanLocale(value) {
|
|
4
5
|
return String(value ?? "").trim().toLowerCase().replace(/_/gu, "-");
|
|
5
6
|
}
|
|
@@ -8,6 +9,7 @@ function normalizeLocaleRouting(options = {}) {
|
|
|
8
9
|
const fallback = cleanLocale(options.defaultLocale) || declared[0] || "en";
|
|
9
10
|
const locales = declared.includes(fallback) ? declared : [fallback, ...declared];
|
|
10
11
|
return {
|
|
12
|
+
cookieName: String(options.cookieName || DEFAULT_LOCALE_COOKIE_NAME),
|
|
11
13
|
defaultLocale: fallback,
|
|
12
14
|
locales: locales.length ? locales : [fallback],
|
|
13
15
|
storageKey: String(options.storageKey || DEFAULT_LOCALE_STORAGE_KEY),
|
|
@@ -30,5 +32,5 @@ function pickLocale(values, routing) {
|
|
|
30
32
|
}
|
|
31
33
|
return "";
|
|
32
34
|
}
|
|
33
|
-
export { DEFAULT_LOCALE_STORAGE_KEY, cleanLocale, matchLocale, normalizeLocaleRouting, pickLocale };
|
|
35
|
+
export { DEFAULT_LOCALE_COOKIE_NAME, DEFAULT_LOCALE_STORAGE_KEY, cleanLocale, matchLocale, normalizeLocaleRouting, pickLocale, };
|
|
34
36
|
//# sourceMappingURL=options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../src/language/routing/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../src/language/routing/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAkBhD,MAAM,0BAA0B,GAAG,GAAG,eAAe,SAAS,CAAC;AAC/D,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,sBAAsB,CAAC,UAAgC,EAAE;IAChE,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACxF,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC3E,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;IACjF,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,UAAU,IAAI,0BAA0B,CAAC;QACpE,aAAa,EAAE,QAAQ;QACvB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC9C,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,UAAU,IAAI,0BAA0B,CAAC;KACrE,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,OAAsB;IACzD,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IACtD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AACpD,CAAC;AAED,SAAS,UAAU,CAAC,MAAyB,EAAE,OAAsB;IACnE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC5C,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,UAAU,GACX,CAAC"}
|
|
@@ -4,9 +4,8 @@ declare function configureLocaleRouting(options: LocaleRoutingOptions): LocaleRo
|
|
|
4
4
|
declare function getLocaleRouting(): LocaleRouting;
|
|
5
5
|
declare function currentLocale(): string;
|
|
6
6
|
declare function persistLocale(locale: string): void;
|
|
7
|
-
declare function localeHref(locale: string): string;
|
|
8
7
|
declare function setCurrentLocale(locale: unknown): boolean;
|
|
9
8
|
declare function onLocaleChanged(listener: LocaleListener): () => void;
|
|
10
|
-
export { configureLocaleRouting, currentLocale, getLocaleRouting,
|
|
9
|
+
export { configureLocaleRouting, currentLocale, getLocaleRouting, onLocaleChanged, persistLocale, setCurrentLocale, };
|
|
11
10
|
export type { LocaleListener };
|
|
12
11
|
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGxE,KAAK,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGxE,KAAK,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AAQ/C,iBAAS,sBAAsB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAI5E;AAED,iBAAS,gBAAgB,IAAI,aAAa,CAEzC;AAMD,iBAAS,aAAa,IAAI,MAAM,CAG/B;AAED,iBAAS,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAS3C;AAED,iBAAS,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAWlD;AAED,iBAAS,eAAe,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAK7D;AAED,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,CAAC;AACF,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import { matchLocale, normalizeLocaleRouting } from "./options.js";
|
|
2
|
-
import {
|
|
1
|
+
import { cleanLocale, matchLocale, normalizeLocaleRouting } from "./options.js";
|
|
2
|
+
import { LOCALE_RENDERED_ATTR, applyLocaleMeta } from "./view.js";
|
|
3
3
|
const listeners = new Set();
|
|
4
|
+
const COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
|
|
4
5
|
let routing = normalizeLocaleRouting();
|
|
6
|
+
let configured = false;
|
|
5
7
|
function configureLocaleRouting(options) {
|
|
6
8
|
routing = normalizeLocaleRouting(options);
|
|
9
|
+
configured = true;
|
|
7
10
|
return routing;
|
|
8
11
|
}
|
|
9
12
|
function getLocaleRouting() {
|
|
10
13
|
return routing;
|
|
11
14
|
}
|
|
15
|
+
function resolveLocale(value) {
|
|
16
|
+
return configured ? matchLocale(value, routing) : cleanLocale(value);
|
|
17
|
+
}
|
|
12
18
|
function currentLocale() {
|
|
13
|
-
if (typeof
|
|
19
|
+
if (typeof document === "undefined")
|
|
14
20
|
return routing.defaultLocale;
|
|
15
|
-
return
|
|
21
|
+
return resolveLocale(document.documentElement.lang) || routing.defaultLocale;
|
|
16
22
|
}
|
|
17
23
|
function persistLocale(locale) {
|
|
18
|
-
if (typeof
|
|
24
|
+
if (typeof document === "undefined")
|
|
19
25
|
return;
|
|
26
|
+
const name = encodeURIComponent(routing.cookieName);
|
|
27
|
+
document.cookie = `${name}=${encodeURIComponent(locale)}; Path=/; Max-Age=${COOKIE_MAX_AGE}; SameSite=Lax`;
|
|
20
28
|
try {
|
|
21
29
|
window.localStorage.setItem(routing.storageKey, locale);
|
|
22
30
|
}
|
|
@@ -24,21 +32,19 @@ function persistLocale(locale) {
|
|
|
24
32
|
return;
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
|
-
function localeHref(locale) {
|
|
28
|
-
const parsed = parseLocalePathname(window.location.pathname, routing);
|
|
29
|
-
const pathname = buildLocalePathname(parsed.pathname, locale, routing);
|
|
30
|
-
return `${pathname}${window.location.search}${window.location.hash}`;
|
|
31
|
-
}
|
|
32
35
|
function setCurrentLocale(locale) {
|
|
33
|
-
const next =
|
|
34
|
-
if (!next || typeof
|
|
36
|
+
const next = resolveLocale(locale);
|
|
37
|
+
if (!next || typeof document === "undefined")
|
|
35
38
|
return false;
|
|
36
39
|
persistLocale(next);
|
|
37
40
|
if (next === currentLocale())
|
|
38
41
|
return false;
|
|
42
|
+
const root = document.documentElement;
|
|
43
|
+
root.lang = next;
|
|
44
|
+
root.setAttribute(LOCALE_RENDERED_ATTR, next);
|
|
45
|
+
applyLocaleMeta(document, next);
|
|
39
46
|
for (const listener of listeners)
|
|
40
47
|
listener(next);
|
|
41
|
-
window.location.assign(localeHref(next));
|
|
42
48
|
return true;
|
|
43
49
|
}
|
|
44
50
|
function onLocaleChanged(listener) {
|
|
@@ -47,5 +53,5 @@ function onLocaleChanged(listener) {
|
|
|
47
53
|
listeners.delete(listener);
|
|
48
54
|
};
|
|
49
55
|
}
|
|
50
|
-
export { configureLocaleRouting, currentLocale, getLocaleRouting,
|
|
56
|
+
export { configureLocaleRouting, currentLocale, getLocaleRouting, onLocaleChanged, persistLocale, setCurrentLocale, };
|
|
51
57
|
//# sourceMappingURL=runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../../src/language/routing/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../../src/language/routing/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAIlE,MAAM,SAAS,GAAG,IAAI,G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CAAC,CAAC;IACnC,IAAI,CAAC,IAAI,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO,KAAK,CAAC;IAC3D,aAAa,CAAC,IAAI,CAAC,CAAC;IACpB,IAAI,IAAI,KAAK,aAAa,EAAE;QAAE,OAAO,KAAK,CAAC;IAC3C,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC;IACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACjB,IAAI,CAAC,YAAY,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAC9C,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAChC,KAAK,MAAM,QAAQ,IAAI,SAAS;QAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,eAAe,CAAC,QAAwB;IAC/C,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxB,OAAO,GAAG,EAAE;QACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LocaleRouting, LocaleStrategy } from "./options.js";
|
|
2
|
+
import type { LocaleMeta } from "./view.js";
|
|
3
|
+
type LocaleShellRoutesOptions<M extends LocaleMeta> = {
|
|
4
|
+
meta: (path: string, locale: string) => M;
|
|
5
|
+
paths: readonly string[];
|
|
6
|
+
render: (path: string, locale: string) => string;
|
|
7
|
+
routing: LocaleRouting;
|
|
8
|
+
strategy?: LocaleStrategy;
|
|
9
|
+
};
|
|
10
|
+
type LocaleShellRoute<M extends LocaleMeta> = {
|
|
11
|
+
body: string;
|
|
12
|
+
locale: string;
|
|
13
|
+
meta: M & {
|
|
14
|
+
lang: string;
|
|
15
|
+
};
|
|
16
|
+
path: string;
|
|
17
|
+
sourcePath: string;
|
|
18
|
+
};
|
|
19
|
+
declare function createLocaleShellRoutes<M extends LocaleMeta>(options: LocaleShellRoutesOptions<M>): LocaleShellRoute<M>[];
|
|
20
|
+
export { createLocaleShellRoutes };
|
|
21
|
+
export type { LocaleShellRoute, LocaleShellRoutesOptions };
|
|
22
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/shell.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,KAAK,wBAAwB,CAAC,CAAC,SAAS,UAAU,IAAI;IACpD,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,CAAC;IAC1C,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IACjD,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,KAAK,gBAAgB,CAAC,CAAC,SAAS,UAAU,IAAI;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,GAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAiBF,iBAAS,uBAAuB,CAAC,CAAC,SAAS,UAAU,EAAE,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAmBlH;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC;AACnC,YAAY,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createLocaleDocumentBody } from "./document.js";
|
|
2
|
+
function localeRoutePath(sourcePath, locale, routing) {
|
|
3
|
+
if (locale === routing.defaultLocale)
|
|
4
|
+
return sourcePath;
|
|
5
|
+
const trimmed = sourcePath.replace(/\/+$/u, "");
|
|
6
|
+
return trimmed ? `/${locale}${trimmed.startsWith("/") ? trimmed : `/${trimmed}`}` : `/${locale}`;
|
|
7
|
+
}
|
|
8
|
+
function servedLocales(routing, strategy) {
|
|
9
|
+
return strategy === "prefix" ? routing.locales : [routing.defaultLocale];
|
|
10
|
+
}
|
|
11
|
+
function swapMeta(metas) {
|
|
12
|
+
const entries = Object.entries(metas).map(([locale, meta]) => [locale, { description: meta.description, title: meta.title }]);
|
|
13
|
+
return Object.fromEntries(entries);
|
|
14
|
+
}
|
|
15
|
+
function createLocaleShellRoutes(options) {
|
|
16
|
+
const { routing } = options;
|
|
17
|
+
const routes = [];
|
|
18
|
+
for (const sourcePath of options.paths) {
|
|
19
|
+
const bodies = Object.fromEntries(routing.locales.map((locale) => [locale, options.render(sourcePath, locale)]));
|
|
20
|
+
const metas = Object.fromEntries(routing.locales.map((locale) => [locale, options.meta(sourcePath, locale)]));
|
|
21
|
+
for (const locale of servedLocales(routing, options.strategy)) {
|
|
22
|
+
routes.push({
|
|
23
|
+
body: createLocaleDocumentBody({ bodies, defaultLocale: locale, meta: swapMeta(metas) }),
|
|
24
|
+
locale,
|
|
25
|
+
meta: { ...metas[locale], lang: locale },
|
|
26
|
+
path: localeRoutePath(sourcePath, locale, routing),
|
|
27
|
+
sourcePath,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return routes;
|
|
32
|
+
}
|
|
33
|
+
export { createLocaleShellRoutes };
|
|
34
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -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AAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACjH,MAAM,KAAK,GAAsB,MAAM,CAAC,WAAW,CACjD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAC5E,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CAAC;gBACR,IAAI,EAAE,wBAAwB,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxF,MAAM;gBACN,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;gBACxC,IAAI,EAAE,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC;gBAClD,UAAU;aACb,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type LocaleMeta = {
|
|
2
|
+
description?: string;
|
|
3
|
+
title?: string;
|
|
4
|
+
};
|
|
5
|
+
declare const LOCALE_VIEW_ATTR: `data-${string}`;
|
|
6
|
+
declare const LOCALE_META_ATTR: `data-${string}`;
|
|
7
|
+
declare const LOCALE_RENDERED_ATTR: `data-${string}`;
|
|
8
|
+
declare const LOCALE_PENDING_ATTR: `data-${string}`;
|
|
9
|
+
declare const LOCALE_START_MARK = "tbf:locale-start";
|
|
10
|
+
declare const LOCALE_END_MARK = "tbf:locale-end";
|
|
11
|
+
declare function readLocaleMeta(doc: Document): Record<string, LocaleMeta>;
|
|
12
|
+
declare function applyLocaleMeta(doc: Document, locale: string): void;
|
|
13
|
+
declare function applyLocaleView(doc: Document, locale: string): boolean;
|
|
14
|
+
export { LOCALE_END_MARK, LOCALE_META_ATTR, LOCALE_PENDING_ATTR, LOCALE_RENDERED_ATTR, LOCALE_START_MARK, LOCALE_VIEW_ATTR, applyLocaleMeta, applyLocaleView, readLocaleMeta, };
|
|
15
|
+
export type { LocaleMeta };
|
|
16
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../../src/language/routing/view.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAOF,QAAA,MAAM,gBAAgB,kBAAkC,CAAC;AACzD,QAAA,MAAM,gBAAgB,kBAAkC,CAAC;AACzD,QAAA,MAAM,oBAAoB,kBAAsC,CAAC;AACjE,QAAA,MAAM,mBAAmB,kBAAqC,CAAC;AAC/D,QAAA,MAAM,iBAAiB,qBAAoC,CAAC;AAC5D,QAAA,MAAM,eAAe,mBAAkC,CAAC;AAcxD,iBAAS,cAAc,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAQjE;AAED,iBAAS,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAK5D;AAYD,iBAAS,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAa/D;AAED,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,cAAc,GACf,CAAC;AACF,YAAY,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { FRONTEND_PREFIX, frontendDataAttr } from "../../namespace/index.js";
|
|
2
|
+
const LOCALE_VIEW_ATTR = frontendDataAttr("locale-view");
|
|
3
|
+
const LOCALE_META_ATTR = frontendDataAttr("locale-meta");
|
|
4
|
+
const LOCALE_RENDERED_ATTR = frontendDataAttr("locale-rendered");
|
|
5
|
+
const LOCALE_PENDING_ATTR = frontendDataAttr("locale-pending");
|
|
6
|
+
const LOCALE_START_MARK = `${FRONTEND_PREFIX}:locale-start`;
|
|
7
|
+
const LOCALE_END_MARK = `${FRONTEND_PREFIX}:locale-end`;
|
|
8
|
+
const COMMENT_NODE = 8;
|
|
9
|
+
function findLocaleMarkers(body) {
|
|
10
|
+
let start = null;
|
|
11
|
+
let end = null;
|
|
12
|
+
for (const node of Array.from(body.childNodes)) {
|
|
13
|
+
if (node.nodeType !== COMMENT_NODE)
|
|
14
|
+
continue;
|
|
15
|
+
if (node.nodeValue === LOCALE_START_MARK)
|
|
16
|
+
start = node;
|
|
17
|
+
if (node.nodeValue === LOCALE_END_MARK)
|
|
18
|
+
end = node;
|
|
19
|
+
}
|
|
20
|
+
return start && end ? { end, start } : null;
|
|
21
|
+
}
|
|
22
|
+
function readLocaleMeta(doc) {
|
|
23
|
+
const node = doc.querySelector(`script[${LOCALE_META_ATTR}]`);
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(node?.textContent || "{}");
|
|
26
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function applyLocaleMeta(doc, locale) {
|
|
33
|
+
const meta = readLocaleMeta(doc)[locale];
|
|
34
|
+
if (!meta)
|
|
35
|
+
return;
|
|
36
|
+
if (meta.title)
|
|
37
|
+
doc.title = meta.title;
|
|
38
|
+
if (meta.description)
|
|
39
|
+
doc.querySelector('meta[name="description"]')?.setAttribute("content", meta.description);
|
|
40
|
+
}
|
|
41
|
+
function renderedLocale(doc) {
|
|
42
|
+
const root = doc.documentElement;
|
|
43
|
+
return root.getAttribute(LOCALE_RENDERED_ATTR) || root.lang;
|
|
44
|
+
}
|
|
45
|
+
function localeTemplate(doc, locale) {
|
|
46
|
+
const templates = Array.from(doc.querySelectorAll(`template[${LOCALE_VIEW_ATTR}]`));
|
|
47
|
+
return templates.find((template) => template.getAttribute(LOCALE_VIEW_ATTR) === locale) || null;
|
|
48
|
+
}
|
|
49
|
+
function applyLocaleView(doc, locale) {
|
|
50
|
+
if (!locale || !doc.body || renderedLocale(doc) === locale)
|
|
51
|
+
return false;
|
|
52
|
+
const markers = findLocaleMarkers(doc.body);
|
|
53
|
+
const template = localeTemplate(doc, locale);
|
|
54
|
+
if (!markers || !template)
|
|
55
|
+
return false;
|
|
56
|
+
while (markers.start.nextSibling && markers.start.nextSibling !== markers.end) {
|
|
57
|
+
markers.start.nextSibling.remove();
|
|
58
|
+
}
|
|
59
|
+
doc.body.insertBefore(doc.importNode(template.content, true), markers.end);
|
|
60
|
+
doc.documentElement.lang = locale;
|
|
61
|
+
doc.documentElement.setAttribute(LOCALE_RENDERED_ATTR, locale);
|
|
62
|
+
applyLocaleMeta(doc, locale);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
export { LOCALE_END_MARK, LOCALE_META_ATTR, LOCALE_PENDING_ATTR, LOCALE_RENDERED_ATTR, LOCALE_START_MARK, LOCALE_VIEW_ATTR, applyLocaleMeta, applyLocaleView, readLocaleMeta, };
|
|
66
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../../src/language/routing/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AAC;AAEF,QAAA,MAAM,aAAa,iCAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../../../src/react/locale.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,KAAK,mBAAmB,GAAG;IACzB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CACxC,CAAC;AAEF,QAAA,MAAM,aAAa,iCAA4B,CAAC;AAchD,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,mFAGjD;AAED,iBAAS,SAAS,IAAI,WAAW,CAIhC;AAED,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC;AACpD,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,CAAC"}
|