@hamur/i18n 0.0.0-stage → 0.0.1
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/LICENSE +22 -0
- package/README.md +38 -2
- package/dist/chunks/bun-index-1ve1hj66.js +744 -0
- package/dist/chunks/bun-index-8bw4xpv8.js +93 -0
- package/dist/chunks/bun-index-ej6vjnjs.js +297 -0
- package/dist/chunks/bun-index-pdepkyy1.js +474 -0
- package/dist/src/adapters/angular.js +67 -0
- package/dist/src/adapters/html.js +34 -0
- package/dist/src/adapters/preact.js +23 -0
- package/dist/src/adapters/react.js +23 -0
- package/dist/src/adapters/solid.js +48 -0
- package/dist/src/adapters/svelte.js +74 -0
- package/dist/src/adapters/vue.js +48 -0
- package/dist/src/cli.js +1898 -0
- package/dist/src/index.js +2755 -0
- package/dist/src/load.js +35 -0
- package/dist/src/server/index.js +395 -0
- package/dist/types/src/adapters/angular.d.ts +17 -0
- package/dist/types/src/adapters/bind.d.ts +44 -0
- package/dist/types/src/adapters/html.d.ts +5 -0
- package/dist/types/src/adapters/preact.d.ts +6 -0
- package/dist/types/src/adapters/react.d.ts +6 -0
- package/dist/types/src/adapters/solid.d.ts +9 -0
- package/dist/types/src/adapters/svelte.d.ts +12 -0
- package/dist/types/src/adapters/vue.d.ts +8 -0
- package/dist/types/src/build/catalog.d.ts +5 -0
- package/dist/types/src/build/drop.d.ts +12 -0
- package/dist/types/src/build/extract.d.ts +11 -0
- package/dist/types/src/build/head.d.ts +4 -0
- package/dist/types/src/build/messages.d.ts +27 -0
- package/dist/types/src/build/prerender.d.ts +10 -0
- package/dist/types/src/build/routes.d.ts +14 -0
- package/dist/types/src/build/split.d.ts +37 -0
- package/dist/types/src/build/types.d.ts +15 -0
- package/dist/types/src/cli.d.ts +12 -0
- package/dist/types/src/compiler/compile.d.ts +17 -0
- package/dist/types/src/compiler/mf2-parse.d.ts +62 -0
- package/dist/types/src/compiler/mf2.d.ts +3 -0
- package/dist/types/src/compiler/parse.d.ts +58 -0
- package/dist/types/src/compiler/skeleton.d.ts +7 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/load.d.ts +7 -0
- package/dist/types/src/module.d.ts +15 -0
- package/dist/types/src/options.d.ts +7 -0
- package/dist/types/src/runtime/catalog-client.d.ts +3 -0
- package/dist/types/src/runtime/catalog-loader.d.ts +15 -0
- package/dist/types/src/runtime/catalog-server.d.ts +5 -0
- package/dist/types/src/runtime/catalog.d.ts +60 -0
- package/dist/types/src/runtime/chain.d.ts +3 -0
- package/dist/types/src/runtime/format.d.ts +27 -0
- package/dist/types/src/runtime/head.d.ts +9 -0
- package/dist/types/src/runtime/interpret.d.ts +20 -0
- package/dist/types/src/runtime/link.d.ts +8 -0
- package/dist/types/src/runtime/locale.d.ts +73 -0
- package/dist/types/src/runtime/match.d.ts +54 -0
- package/dist/types/src/runtime/messages.d.ts +42 -0
- package/dist/types/src/runtime/middleware.d.ts +2 -0
- package/dist/types/src/runtime/negotiate.d.ts +9 -0
- package/dist/types/src/runtime/plugin.d.ts +4 -0
- package/dist/types/src/runtime/redirect.d.ts +32 -0
- package/dist/types/src/runtime/rich.d.ts +5 -0
- package/dist/types/src/runtime/translate.d.ts +21 -0
- package/dist/types/src/server/catalog.d.ts +2 -0
- package/dist/types/src/server/context.d.ts +48 -0
- package/dist/types/src/server/door-all-catalog.d.ts +3 -0
- package/dist/types/src/server/door-all.d.ts +2 -0
- package/dist/types/src/server/door-catalog.d.ts +3 -0
- package/dist/types/src/server/door-root-catalog.d.ts +3 -0
- package/dist/types/src/server/door-root.d.ts +2 -0
- package/dist/types/src/server/door.d.ts +2 -0
- package/dist/types/src/server/index.d.ts +7 -0
- package/dist/types/src/server/preferred.d.ts +6 -0
- package/dist/types/src/server/redirect.d.ts +3 -0
- package/dist/types/src/server/setup.d.ts +2 -0
- package/dist/types/src/types.d.ts +163 -0
- package/package.json +122 -4
- package/src/adapters/angular.ts +65 -0
- package/src/adapters/bind.ts +144 -0
- package/src/adapters/html.ts +35 -0
- package/src/adapters/preact.ts +18 -0
- package/src/adapters/react.ts +18 -0
- package/src/adapters/solid.ts +44 -0
- package/src/adapters/svelte.ts +75 -0
- package/src/adapters/test/SveltePage.svelte +18 -0
- package/src/adapters/test/SvelteReporting.svelte +20 -0
- package/src/adapters/test/SvelteRich.svelte +11 -0
- package/src/adapters/test/SvelteRichPlain.svelte +11 -0
- package/src/adapters/test/peer.ts +7 -0
- package/src/adapters/test/preact-client.ts +43 -0
- package/src/adapters/test/preact-page.ts +34 -0
- package/src/adapters/test/preact-rich.ts +9 -0
- package/src/adapters/test/react-client.ts +49 -0
- package/src/adapters/test/react-page.ts +34 -0
- package/src/adapters/test/react-rich.ts +15 -0
- package/src/adapters/test/runtime.ts +104 -0
- package/src/adapters/test/solid-client.ts +33 -0
- package/src/adapters/test/solid-page.ts +30 -0
- package/src/adapters/test/solid-rich.ts +5 -0
- package/src/adapters/test/svelte-client.ts +51 -0
- package/src/adapters/test/svelte-log.ts +2 -0
- package/src/adapters/test/svelte-plugin.ts +20 -0
- package/src/adapters/test/vue-page.ts +26 -0
- package/src/adapters/test/vue-rich.ts +16 -0
- package/src/adapters/vue.ts +44 -0
- package/src/build/catalog.ts +44 -0
- package/src/build/drop.ts +36 -0
- package/src/build/extract.ts +207 -0
- package/src/build/head.ts +10 -0
- package/src/build/messages.ts +347 -0
- package/src/build/prerender.ts +48 -0
- package/src/build/routes.ts +269 -0
- package/src/build/split.ts +240 -0
- package/src/build/types.ts +156 -0
- package/src/cli.ts +25 -0
- package/src/compiler/compile.ts +190 -0
- package/src/compiler/mf2-parse.ts +469 -0
- package/src/compiler/mf2.ts +393 -0
- package/src/compiler/parse.ts +265 -0
- package/src/compiler/skeleton.ts +85 -0
- package/src/env.d.ts +55 -0
- package/src/index.ts +24 -0
- package/src/load.ts +41 -0
- package/src/module.ts +66 -0
- package/src/options.ts +198 -0
- package/src/runtime/catalog-client.ts +28 -0
- package/src/runtime/catalog-loader.ts +28 -0
- package/src/runtime/catalog-server.ts +36 -0
- package/src/runtime/catalog.ts +190 -0
- package/src/runtime/chain.ts +9 -0
- package/src/runtime/format.ts +102 -0
- package/src/runtime/head.ts +57 -0
- package/src/runtime/interpret.ts +504 -0
- package/src/runtime/link.ts +36 -0
- package/src/runtime/locale.ts +392 -0
- package/src/runtime/match.ts +334 -0
- package/src/runtime/messages.ts +129 -0
- package/src/runtime/middleware.ts +32 -0
- package/src/runtime/negotiate.ts +61 -0
- package/src/runtime/plugin.ts +69 -0
- package/src/runtime/redirect.ts +191 -0
- package/src/runtime/rich.ts +21 -0
- package/src/runtime/translate.ts +131 -0
- package/src/server/catalog.ts +11 -0
- package/src/server/context.ts +191 -0
- package/src/server/door-all-catalog.ts +7 -0
- package/src/server/door-all.ts +5 -0
- package/src/server/door-catalog.ts +6 -0
- package/src/server/door-root-catalog.ts +7 -0
- package/src/server/door-root.ts +5 -0
- package/src/server/door.ts +4 -0
- package/src/server/index.ts +11 -0
- package/src/server/preferred.ts +12 -0
- package/src/server/redirect.ts +26 -0
- package/src/server/setup.ts +14 -0
- package/src/types.ts +182 -0
package/dist/src/load.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
serverCatalog,
|
|
4
|
+
configOf,
|
|
5
|
+
routeLoadOf,
|
|
6
|
+
contextLocale,
|
|
7
|
+
readsRequestLocale,
|
|
8
|
+
routeBaseName,
|
|
9
|
+
loadRuntime
|
|
10
|
+
} from "../chunks/bun-index-pdepkyy1.js";
|
|
11
|
+
|
|
12
|
+
// packages/i18n/src/load.ts
|
|
13
|
+
async function useTranslation(ctx) {
|
|
14
|
+
const i18n = loadRuntime.current;
|
|
15
|
+
if (!i18n)
|
|
16
|
+
throw new Error('useTranslation(ctx) needs the "@hamur/i18n" module: its app plugin has not run');
|
|
17
|
+
const { event, route } = ctx;
|
|
18
|
+
const { code } = contextLocale(i18n, event?.context) ?? (readsRequestLocale(i18n) ? i18n.locale : i18n.localeOf(route.path));
|
|
19
|
+
const loadRoute = routeLoadOf(i18n);
|
|
20
|
+
const catalog = event ? serverCatalog() : undefined;
|
|
21
|
+
await Promise.all([
|
|
22
|
+
loadRoute ? loadRoute(code, route.name ? routeBaseName(route.name) : undefined) : i18n.load(code),
|
|
23
|
+
catalog?.(code, { event, baseURL: configOf(i18n).baseURL ?? "/" })
|
|
24
|
+
]);
|
|
25
|
+
const { locale, t, n, d, dynamic } = i18n.translator(code);
|
|
26
|
+
return {
|
|
27
|
+
locale,
|
|
28
|
+
t: Object.assign((key, ...args) => t(key, ...args), { dynamic }),
|
|
29
|
+
n,
|
|
30
|
+
d
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
useTranslation
|
|
35
|
+
};
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
serverCatalog,
|
|
4
|
+
installServerCatalog,
|
|
5
|
+
negotiateAll,
|
|
6
|
+
negotiate,
|
|
7
|
+
messageStore,
|
|
8
|
+
LOCALE_VARIANT,
|
|
9
|
+
contextLocale,
|
|
10
|
+
missingCopyOf,
|
|
11
|
+
copyMissing,
|
|
12
|
+
createI18nRuntime
|
|
13
|
+
} from "../../chunks/bun-index-pdepkyy1.js";
|
|
14
|
+
import {
|
|
15
|
+
fallbackChain,
|
|
16
|
+
createMatcher
|
|
17
|
+
} from "../../chunks/bun-index-ej6vjnjs.js";
|
|
18
|
+
|
|
19
|
+
// packages/i18n/src/server/context.ts
|
|
20
|
+
import { rewrite } from "hamur/app";
|
|
21
|
+
import { defineMiddleware, getCookie, getRequestURL } from "hamur/server";
|
|
22
|
+
function firstSegment(pathname, baseURL) {
|
|
23
|
+
const base = baseURL.replace(/\/$/, "");
|
|
24
|
+
let path = pathname;
|
|
25
|
+
if (base && (path === base || path.startsWith(`${base}/`)))
|
|
26
|
+
path = path.slice(base.length);
|
|
27
|
+
return /^\/([^/]*)/.exec(path)?.[1];
|
|
28
|
+
}
|
|
29
|
+
function createServerI18n(config) {
|
|
30
|
+
const runtime = createI18nRuntime(config);
|
|
31
|
+
const byCode = new Map(config.locales.map((locale) => [locale.code, locale]));
|
|
32
|
+
const copies = new Set(config.copies);
|
|
33
|
+
const single = config.strategy === "no_prefix";
|
|
34
|
+
const hosts = config.domains ? new Map(Object.entries(config.domains).map(([code, origin]) => [new URL(origin).host, byCode.get(code)])) : undefined;
|
|
35
|
+
const byRequest = (event) => {
|
|
36
|
+
if (single || hosts) {
|
|
37
|
+
const fromVariant = contextLocale(runtime, { cacheVariant: event.context.cacheVariant });
|
|
38
|
+
if (fromVariant)
|
|
39
|
+
return { locale: fromVariant, byHost: false };
|
|
40
|
+
}
|
|
41
|
+
if (hosts) {
|
|
42
|
+
const url = getRequestURL(event);
|
|
43
|
+
const fromHost = hosts.get(url.host) ?? (url.port === "80" || url.port === "443" ? hosts.get(url.hostname) : undefined);
|
|
44
|
+
if (fromHost)
|
|
45
|
+
return { locale: fromHost, byHost: true };
|
|
46
|
+
if (!config.dev)
|
|
47
|
+
return { locale: runtime.defaultLocale, byHost: true };
|
|
48
|
+
}
|
|
49
|
+
return { locale: ordered(event), byHost: false };
|
|
50
|
+
};
|
|
51
|
+
const ordered = (event) => {
|
|
52
|
+
const segment = firstSegment(event.url.pathname, config.baseURL);
|
|
53
|
+
if (segment !== undefined && copies.has(segment))
|
|
54
|
+
return byCode.get(segment);
|
|
55
|
+
const query = event.url.searchParams.get("locale");
|
|
56
|
+
const fromQuery = query === null ? undefined : byCode.get(query);
|
|
57
|
+
if (fromQuery)
|
|
58
|
+
return fromQuery;
|
|
59
|
+
const cookie = config.cookie ? getCookie(event, config.cookie) : undefined;
|
|
60
|
+
const fromCookie = cookie === undefined ? undefined : byCode.get(cookie);
|
|
61
|
+
if (fromCookie)
|
|
62
|
+
return fromCookie;
|
|
63
|
+
return negotiate(event.request.headers.get("accept-language"), config.locales) ?? runtime.defaultLocale;
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
runtime,
|
|
67
|
+
baseURL: config.baseURL,
|
|
68
|
+
resolve: (event) => byRequest(event).locale,
|
|
69
|
+
enter(event) {
|
|
70
|
+
const { locale, byHost } = byRequest(event);
|
|
71
|
+
const { code } = locale;
|
|
72
|
+
event.context.locale = code;
|
|
73
|
+
if (!single && !hosts)
|
|
74
|
+
return;
|
|
75
|
+
event.context.cacheVariant = LOCALE_VARIANT + code;
|
|
76
|
+
if (!byHost)
|
|
77
|
+
event.response.headers.append("vary", "Cookie, Accept-Language");
|
|
78
|
+
},
|
|
79
|
+
missing(event) {
|
|
80
|
+
const mode = config.missingPage ?? "404";
|
|
81
|
+
if (mode === "404" || event.method !== "GET" && event.method !== "HEAD")
|
|
82
|
+
return;
|
|
83
|
+
const base = config.baseURL.replace(/\/$/, "");
|
|
84
|
+
const { pathname } = event.url;
|
|
85
|
+
if (base && pathname !== base && !pathname.startsWith(base + "/"))
|
|
86
|
+
return;
|
|
87
|
+
const match = missingCopyOf(runtime, pathname.slice(base.length) || "/");
|
|
88
|
+
if (!match)
|
|
89
|
+
return;
|
|
90
|
+
const holder = byCode.get(fallbackChain(config.fallback, config.defaultLocale, match.code).find((code) => !copyMissing(runtime, match.name, code)) ?? config.defaultLocale);
|
|
91
|
+
const target = runtime.localePath({ name: match.name, params: match.params }, holder.code);
|
|
92
|
+
if (mode === "rewrite")
|
|
93
|
+
return rewrite(target);
|
|
94
|
+
const headers = new Headers(event.response.headers);
|
|
95
|
+
headers.set("location", base + target + event.url.search);
|
|
96
|
+
return new Response(null, { status: 302, headers });
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function translationOf(server, event) {
|
|
101
|
+
const { runtime } = server;
|
|
102
|
+
const known = runtime.locales.find((locale) => locale.code === event.context.locale);
|
|
103
|
+
const { code } = known ?? server.resolve(event);
|
|
104
|
+
const catalog = serverCatalog();
|
|
105
|
+
await Promise.all([runtime.load(code), catalog?.(code, { event, baseURL: server.baseURL })]);
|
|
106
|
+
const { locale, t, n, d, dynamic } = runtime.translator(code);
|
|
107
|
+
return {
|
|
108
|
+
locale,
|
|
109
|
+
t: Object.assign((key, ...args) => t(key, ...args), { dynamic }),
|
|
110
|
+
n,
|
|
111
|
+
d
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
var server;
|
|
115
|
+
async function loadServer() {
|
|
116
|
+
const [options, table, loaders, chunks, catalog] = await Promise.all([
|
|
117
|
+
import("#hamur/i18n/options"),
|
|
118
|
+
import("#hamur/i18n/routes"),
|
|
119
|
+
import("#hamur/i18n/loaders"),
|
|
120
|
+
import("#hamur/i18n/chunks"),
|
|
121
|
+
import("#hamur/i18n/catalog-server")
|
|
122
|
+
]);
|
|
123
|
+
messageStore.install(loaders.default, chunks.default);
|
|
124
|
+
const loader = catalog.default;
|
|
125
|
+
if (loader)
|
|
126
|
+
installServerCatalog(loader);
|
|
127
|
+
return createServerI18n({
|
|
128
|
+
locales: options.locales,
|
|
129
|
+
defaultLocale: options.defaultLocale,
|
|
130
|
+
strategy: options.strategy,
|
|
131
|
+
cookie: options.cookie,
|
|
132
|
+
timeZone: options.timeZone,
|
|
133
|
+
fallback: options.fallback,
|
|
134
|
+
missingPage: options.missingPage,
|
|
135
|
+
baseURL: options.baseURL,
|
|
136
|
+
copies: table.copies,
|
|
137
|
+
routes: table.routes,
|
|
138
|
+
aliases: table.aliases,
|
|
139
|
+
missing: table.missing,
|
|
140
|
+
...table.domains ? { domains: table.domains } : {},
|
|
141
|
+
dev: import.meta.dev === true
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
var serverI18n = () => server ??= loadServer();
|
|
145
|
+
var localeStep = defineMiddleware(async ({ event }) => {
|
|
146
|
+
const i18n = await serverI18n();
|
|
147
|
+
i18n.enter(event);
|
|
148
|
+
return i18n.missing(event);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// packages/i18n/src/server/preferred.ts
|
|
152
|
+
import { locales } from "#hamur/i18n/options";
|
|
153
|
+
var preferredLocaleList = (event) => negotiateAll(event.request.headers.get("accept-language"), locales);
|
|
154
|
+
var preferredLocale = (event) => preferredLocaleList(event)[0];
|
|
155
|
+
// packages/i18n/src/server/redirect.ts
|
|
156
|
+
import * as options from "#hamur/i18n/options";
|
|
157
|
+
import { aliases, copies, missing, routes } from "#hamur/i18n/routes";
|
|
158
|
+
|
|
159
|
+
// packages/i18n/src/runtime/redirect.ts
|
|
160
|
+
import { defineMiddleware as defineMiddleware2, getCookie as getCookie2, useSiteConfig } from "hamur/server";
|
|
161
|
+
var escapeHtml = (text) => text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
162
|
+
var scriptJson = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
163
|
+
var PICK_SCRIPT = `(function(c){var s=function(t){try{return new Intl.Locale(t).language}catch(e){return""}};var l=c.locales,p=null,i,j,k;if(c.cookie){var a=document.cookie.split(";");for(i=0;i<a.length;i++){var e=a[i].indexOf("=");if(e>0&&a[i].slice(0,e).trim()===c.cookie){var v=a[i].slice(e+1).trim();try{v=decodeURIComponent(v)}catch(x){}for(j=0;j<l.length;j++)if(l[j].code===v)p=l[j].code;break}}}var n=navigator.languages||[navigator.language];for(i=0;!p&&i<n.length;i++){var r=String(n[i]).toLowerCase();for(j=0;j<l.length;j++)if(l[j].language.toLowerCase()===r||l[j].code===r){p=l[j].code;break}if(!p){k=s(r);for(j=0;k&&j<l.length;j++)if(s(l[j].language)===k){p=l[j].code;break}}}location.replace(c.base+(p||c.fallback))})`;
|
|
164
|
+
function localeRootPage(event, config, origin = useSiteConfig(event).url) {
|
|
165
|
+
const { baseURL, locales } = config;
|
|
166
|
+
const fallback = locales.find((locale) => locale.code === config.defaultLocale);
|
|
167
|
+
const target = `${baseURL}${fallback.code}`;
|
|
168
|
+
const nonce = typeof event.context.nonce === "string" ? ` nonce="${escapeHtml(event.context.nonce)}"` : "";
|
|
169
|
+
const data = {
|
|
170
|
+
locales: locales.map(({ code, language }) => ({ code, language })),
|
|
171
|
+
cookie: config.cookie,
|
|
172
|
+
base: baseURL,
|
|
173
|
+
fallback: fallback.code
|
|
174
|
+
};
|
|
175
|
+
return [
|
|
176
|
+
"<!DOCTYPE html>",
|
|
177
|
+
`<html lang="${escapeHtml(fallback.language)}">`,
|
|
178
|
+
"<head>",
|
|
179
|
+
'<meta charset="utf-8">',
|
|
180
|
+
`<meta http-equiv="refresh" content="0; url=${escapeHtml(target)}">`,
|
|
181
|
+
...origin ? [`<link rel="canonical" href="${escapeHtml(origin + target)}">`] : [],
|
|
182
|
+
`<script${nonce}>${PICK_SCRIPT}(${scriptJson(data)})</script>`,
|
|
183
|
+
"</head>",
|
|
184
|
+
"<body>",
|
|
185
|
+
"<ul>",
|
|
186
|
+
...locales.map((locale) => `<li><a href="${escapeHtml(baseURL + locale.code)}" hreflang="${escapeHtml(locale.language)}" lang="${escapeHtml(locale.language)}">${escapeHtml(locale.name)}</a></li>`),
|
|
187
|
+
"</ul>",
|
|
188
|
+
"</body>",
|
|
189
|
+
"</html>",
|
|
190
|
+
""
|
|
191
|
+
].join(`
|
|
192
|
+
`);
|
|
193
|
+
}
|
|
194
|
+
function targetOf(event, config) {
|
|
195
|
+
const fromCookie = config.cookie ? getCookie2(event, config.cookie) : undefined;
|
|
196
|
+
return config.locales.find((locale) => locale.code === fromCookie) ?? negotiate(event.request.headers.get("accept-language"), config.locales);
|
|
197
|
+
}
|
|
198
|
+
function privateAnswer(event) {
|
|
199
|
+
const headers = event.response.headers;
|
|
200
|
+
headers.append("vary", "Cookie, Accept-Language");
|
|
201
|
+
headers.set("cache-control", "private, no-store");
|
|
202
|
+
return headers;
|
|
203
|
+
}
|
|
204
|
+
function rootRedirect(event, config, origin) {
|
|
205
|
+
if (config.strategy === "no_prefix")
|
|
206
|
+
return;
|
|
207
|
+
const headers = privateAnswer(event);
|
|
208
|
+
const target = targetOf(event, config);
|
|
209
|
+
const redirect = (code) => {
|
|
210
|
+
const answer = new Headers(headers);
|
|
211
|
+
answer.set("location", `${config.baseURL}${code}${event.url.search}`);
|
|
212
|
+
return new Response(null, { status: 302, headers: answer });
|
|
213
|
+
};
|
|
214
|
+
if (config.strategy === "prefix_except_default" || config.strategy === "prefix_and_default")
|
|
215
|
+
return target && target.code !== config.defaultLocale ? redirect(target.code) : undefined;
|
|
216
|
+
if (target)
|
|
217
|
+
return redirect(target.code);
|
|
218
|
+
if (config.redirectToDefaultLocale)
|
|
219
|
+
return redirect(config.defaultLocale);
|
|
220
|
+
const answer = new Headers(headers);
|
|
221
|
+
answer.set("content-type", "text/html; charset=utf-8");
|
|
222
|
+
return new Response(event.method === "HEAD" ? null : localeRootPage(event, config, origin), {
|
|
223
|
+
status: 200,
|
|
224
|
+
headers: answer
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
var UNTOUCHED = /^\/(?:api|_hamur)(?:\/|$)/;
|
|
228
|
+
var FILE = /\.[A-Za-z0-9]+$/;
|
|
229
|
+
var namesHtml = (accept) => (accept ?? "").split(",").some((entry) => entry.split(";")[0].trim().toLowerCase() === "text/html");
|
|
230
|
+
function allRedirect(event, config, origin) {
|
|
231
|
+
if (config.strategy === "no_prefix")
|
|
232
|
+
return;
|
|
233
|
+
const base = config.baseURL.replace(/\/$/, "");
|
|
234
|
+
let path = event.url.pathname;
|
|
235
|
+
if (base) {
|
|
236
|
+
if (path !== base && !path.startsWith(base + "/"))
|
|
237
|
+
return;
|
|
238
|
+
path = path.slice(base.length) || "/";
|
|
239
|
+
}
|
|
240
|
+
if (path === "/")
|
|
241
|
+
return rootRedirect(event, config, origin);
|
|
242
|
+
if (!namesHtml(event.request.headers.get("accept")) || UNTOUCHED.test(path) || FILE.test(path))
|
|
243
|
+
return;
|
|
244
|
+
if (config.copies.includes(path.split("/")[1]))
|
|
245
|
+
return;
|
|
246
|
+
const prefix = config.strategy === "prefix";
|
|
247
|
+
const ordered = [
|
|
248
|
+
config.defaultLocale,
|
|
249
|
+
...config.locales.map((locale) => locale.code).filter((code) => code !== config.defaultLocale)
|
|
250
|
+
];
|
|
251
|
+
const match = prefix ? ordered.map((code) => config.matcher.matchPath("/" + code + path)).find((found) => found !== undefined) : config.matcher.matchPath(path);
|
|
252
|
+
if (!match || !prefix && match.code !== config.defaultLocale)
|
|
253
|
+
return;
|
|
254
|
+
const headers = privateAnswer(event);
|
|
255
|
+
const target = targetOf(event, config);
|
|
256
|
+
const code = target?.code ?? (prefix ? config.defaultLocale : undefined);
|
|
257
|
+
if (code === undefined || !prefix && code === config.defaultLocale)
|
|
258
|
+
return;
|
|
259
|
+
let copy;
|
|
260
|
+
try {
|
|
261
|
+
copy = config.matcher.buildPath(match.name, code, match.params);
|
|
262
|
+
} catch {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (config.missing?.[match.name]?.includes(code))
|
|
266
|
+
return;
|
|
267
|
+
const answer = new Headers(headers);
|
|
268
|
+
answer.set("location", base + copy + event.url.search);
|
|
269
|
+
return new Response(null, { status: 302, headers: answer });
|
|
270
|
+
}
|
|
271
|
+
var config;
|
|
272
|
+
var allConfig;
|
|
273
|
+
async function loadConfig() {
|
|
274
|
+
const options = await import("#hamur/i18n/options");
|
|
275
|
+
return {
|
|
276
|
+
locales: options.locales,
|
|
277
|
+
defaultLocale: options.defaultLocale,
|
|
278
|
+
strategy: options.strategy,
|
|
279
|
+
redirectToDefaultLocale: options.redirectToDefaultLocale,
|
|
280
|
+
cookie: options.cookie,
|
|
281
|
+
baseURL: options.baseURL
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
async function loadAllConfig() {
|
|
285
|
+
const [base, table] = await Promise.all([loadConfig(), import("#hamur/i18n/routes")]);
|
|
286
|
+
return {
|
|
287
|
+
...base,
|
|
288
|
+
copies: table.copies,
|
|
289
|
+
matcher: createMatcher({ copies: table.copies, routes: table.routes, aliases: table.aliases }),
|
|
290
|
+
missing: table.missing
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function redirectAnswer(event, config, origin) {
|
|
294
|
+
if (event.request.method !== "GET" && event.request.method !== "HEAD")
|
|
295
|
+
return;
|
|
296
|
+
return "matcher" in config ? allRedirect(event, config, origin) : rootRedirect(event, config, origin);
|
|
297
|
+
}
|
|
298
|
+
var rootStep = defineMiddleware2(async ({ event }) => redirectAnswer(event, await (config ??= loadConfig())));
|
|
299
|
+
var allStep = defineMiddleware2(async ({ event }) => redirectAnswer(event, await (allConfig ??= loadAllConfig())));
|
|
300
|
+
|
|
301
|
+
// packages/i18n/src/server/redirect.ts
|
|
302
|
+
var root;
|
|
303
|
+
var all;
|
|
304
|
+
var rootConfig = () => root ??= {
|
|
305
|
+
locales: options.locales,
|
|
306
|
+
defaultLocale: options.defaultLocale,
|
|
307
|
+
strategy: options.strategy,
|
|
308
|
+
redirectToDefaultLocale: options.redirectToDefaultLocale,
|
|
309
|
+
cookie: options.cookie,
|
|
310
|
+
baseURL: options.baseURL
|
|
311
|
+
};
|
|
312
|
+
var allConfig2 = () => all ??= { ...rootConfig(), copies, matcher: createMatcher({ copies, routes, aliases }), missing };
|
|
313
|
+
var i18nRedirect = (event, mode = "root") => redirectAnswer(event, mode === "all" ? allConfig2() : rootConfig());
|
|
314
|
+
// packages/i18n/src/runtime/interpret.ts
|
|
315
|
+
var among = (list) => (value) => list.includes(String(value)) ? String(value) : undefined;
|
|
316
|
+
function digits(value, low, high) {
|
|
317
|
+
const given = String(value);
|
|
318
|
+
if (!/^(0|[1-9][0-9]?)$/.test(given))
|
|
319
|
+
return;
|
|
320
|
+
const number = Number(given);
|
|
321
|
+
return number >= low && number <= high ? number : undefined;
|
|
322
|
+
}
|
|
323
|
+
var NUMBER_OPTIONS = {
|
|
324
|
+
select: among(["plural", "ordinal", "exact"]),
|
|
325
|
+
signDisplay: among(["auto", "always", "exceptZero", "negative", "never"]),
|
|
326
|
+
useGrouping: among(["auto", "always", "never", "min2"]),
|
|
327
|
+
minimumIntegerDigits: (value) => digits(value, 1, 21),
|
|
328
|
+
minimumFractionDigits: (value) => digits(value, 0, 99),
|
|
329
|
+
maximumFractionDigits: (value) => digits(value, 0, 99),
|
|
330
|
+
minimumSignificantDigits: (value) => digits(value, 1, 21),
|
|
331
|
+
maximumSignificantDigits: (value) => digits(value, 1, 21),
|
|
332
|
+
trailingZeroDisplay: among(["auto", "stripIfInteger"]),
|
|
333
|
+
roundingPriority: among(["auto", "morePrecision", "lessPrecision"]),
|
|
334
|
+
roundingIncrement: (value) => [1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].includes(Number(value)) ? Number(value) : undefined,
|
|
335
|
+
roundingMode: among([
|
|
336
|
+
"ceil",
|
|
337
|
+
"floor",
|
|
338
|
+
"expand",
|
|
339
|
+
"trunc",
|
|
340
|
+
"halfCeil",
|
|
341
|
+
"halfFloor",
|
|
342
|
+
"halfExpand",
|
|
343
|
+
"halfTrunc",
|
|
344
|
+
"halfEven"
|
|
345
|
+
])
|
|
346
|
+
};
|
|
347
|
+
function knownTo(make) {
|
|
348
|
+
return (value) => {
|
|
349
|
+
const given = String(value);
|
|
350
|
+
try {
|
|
351
|
+
make(given);
|
|
352
|
+
return given;
|
|
353
|
+
} catch {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
var DATE_OPTIONS = {
|
|
359
|
+
fields: among([
|
|
360
|
+
"weekday",
|
|
361
|
+
"day-weekday",
|
|
362
|
+
"month-day",
|
|
363
|
+
"month-day-weekday",
|
|
364
|
+
"year-month-day",
|
|
365
|
+
"year-month-day-weekday"
|
|
366
|
+
]),
|
|
367
|
+
length: among(["long", "medium", "short"]),
|
|
368
|
+
precision: among(["hour", "minute", "second"]),
|
|
369
|
+
timeZoneStyle: among(["long", "short"]),
|
|
370
|
+
timeZone: (value) => String(value) === "input" || String(value) === "UTC" ? String(value) : knownTo((zone) => new Intl.DateTimeFormat("en", { timeZone: zone }))(value),
|
|
371
|
+
hour12: among(["true", "false"]),
|
|
372
|
+
calendar: knownTo((calendar) => new Intl.DateTimeFormat("en", { calendar }))
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// packages/i18n/src/runtime/catalog.ts
|
|
376
|
+
function defineCatalog(definition) {
|
|
377
|
+
if (typeof definition?.load !== "function")
|
|
378
|
+
throw new TypeError("defineCatalog needs load(code, event)");
|
|
379
|
+
const { ttl } = definition;
|
|
380
|
+
if (ttl !== undefined && (typeof ttl !== "number" || !(ttl > 0) || !Number.isFinite(ttl)))
|
|
381
|
+
throw new TypeError("defineCatalog: ttl must be a positive number of seconds (got " + String(ttl) + ")");
|
|
382
|
+
return definition;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// packages/i18n/src/server/index.ts
|
|
386
|
+
async function useTranslation(event) {
|
|
387
|
+
return translationOf(await serverI18n(), event);
|
|
388
|
+
}
|
|
389
|
+
export {
|
|
390
|
+
defineCatalog,
|
|
391
|
+
i18nRedirect,
|
|
392
|
+
preferredLocale,
|
|
393
|
+
preferredLocaleList,
|
|
394
|
+
useTranslation
|
|
395
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PipeTransform } from "@angular/core";
|
|
2
|
+
import type { Signal } from "@angular/core";
|
|
3
|
+
import type { CurrentLocale, I18nArgsTuple, I18nKey } from "../types.ts";
|
|
4
|
+
import { type I18nFunctions } from "./bind.ts";
|
|
5
|
+
export type { CurrentLocale };
|
|
6
|
+
export declare function injectLocale(): Signal<CurrentLocale>;
|
|
7
|
+
export declare function injectI18n(): I18nFunctions<string> & {
|
|
8
|
+
locale: Signal<CurrentLocale>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* `{{ "home.title" | t: { name } }}`. Not `pure`: Angular would call a pure pipe again only when the key or the arguments
|
|
12
|
+
* object change, never when the locale does or a field of the arguments changes in place; the pipe translates on every check.
|
|
13
|
+
*/
|
|
14
|
+
export declare class TPipe implements PipeTransform {
|
|
15
|
+
private readonly translate;
|
|
16
|
+
transform<K extends I18nKey>(key: K, ...args: I18nArgsTuple<K>): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AppContext } from "hamur/app";
|
|
2
|
+
import type { CurrentLocale, I18nRich, I18nRouteLocation, I18nRuntime, HamurLocale, LocaleInfo, RichJoin, Translator } from "../types.ts";
|
|
3
|
+
export interface I18nRoute {
|
|
4
|
+
path: string;
|
|
5
|
+
name?: string | null;
|
|
6
|
+
params: Record<string, string | string[]>;
|
|
7
|
+
query: Record<string, string | string[]>;
|
|
8
|
+
hash: string;
|
|
9
|
+
}
|
|
10
|
+
export interface I18nFunctions<N> {
|
|
11
|
+
/** `t.dynamic(key, args?)`: a run-time key, untyped. */
|
|
12
|
+
t: Translator["t"] & {
|
|
13
|
+
rich: I18nRich<N>;
|
|
14
|
+
dynamic: Translator["dynamic"];
|
|
15
|
+
};
|
|
16
|
+
n: Translator["n"];
|
|
17
|
+
d: Translator["d"];
|
|
18
|
+
localePath(to: string | I18nRouteLocation): string;
|
|
19
|
+
switchLocalePath(code: HamurLocale): string;
|
|
20
|
+
absoluteLocalePath(to: string | I18nRouteLocation, code?: HamurLocale): string;
|
|
21
|
+
allLocalePaths(to: string | I18nRouteLocation): {
|
|
22
|
+
code: string;
|
|
23
|
+
language: string;
|
|
24
|
+
url: string;
|
|
25
|
+
}[];
|
|
26
|
+
routeBaseName(name: string): string;
|
|
27
|
+
}
|
|
28
|
+
/** The locale of the page at `path`; under `no_prefix` and with domains the path holds none, so it is `app.i18n.locale`. */
|
|
29
|
+
export declare function localeAt(i18n: I18nRuntime, path: string): LocaleInfo;
|
|
30
|
+
/** For libraries that hold the locale in a reactive holder: runs `listener` after every `setLocale` of `i18n` settles. */
|
|
31
|
+
export declare function onSetLocale(i18n: I18nRuntime, listener: () => void): void;
|
|
32
|
+
export declare function currentLocale(i18n: I18nRuntime, path: string): CurrentLocale;
|
|
33
|
+
export declare function i18nOf(app: AppContext): I18nRuntime;
|
|
34
|
+
export declare function bindFunctions<N>(read: () => {
|
|
35
|
+
i18n: I18nRuntime;
|
|
36
|
+
route: I18nRoute;
|
|
37
|
+
}, join: RichJoin<N>): I18nFunctions<N>;
|
|
38
|
+
/** `t.rich` of an adapter, reading the page locale like `t` does; `join` makes the adapter's node type. */
|
|
39
|
+
export declare function bindRich<N>(read: () => {
|
|
40
|
+
i18n: I18nRuntime;
|
|
41
|
+
route: I18nRoute;
|
|
42
|
+
}, join: RichJoin<N>): I18nRich<N>;
|
|
43
|
+
/** For libraries whose entry may not import a hook: one object per app and locale code, reading the route of the latest render. */
|
|
44
|
+
export declare function sharedFunctions<N>(app: AppContext, i18n: I18nRuntime, route: I18nRoute, join: RichJoin<N>): I18nFunctions<N>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ComponentChildren } from "preact";
|
|
2
|
+
import type { CurrentLocale } from "../types.ts";
|
|
3
|
+
import { type I18nFunctions } from "./bind.ts";
|
|
4
|
+
export type { CurrentLocale };
|
|
5
|
+
export declare function useLocale(): CurrentLocale;
|
|
6
|
+
export declare function useI18n(): I18nFunctions<ComponentChildren>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { CurrentLocale } from "../types.ts";
|
|
3
|
+
import { type I18nFunctions } from "./bind.ts";
|
|
4
|
+
export type { CurrentLocale };
|
|
5
|
+
export declare function useLocale(): CurrentLocale;
|
|
6
|
+
export declare function useI18n(): I18nFunctions<ReactNode>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Accessor } from "solid-js";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
3
|
+
import type { CurrentLocale } from "../types.ts";
|
|
4
|
+
import { type I18nFunctions } from "./bind.ts";
|
|
5
|
+
export type { CurrentLocale };
|
|
6
|
+
export declare function useLocale(): Accessor<CurrentLocale>;
|
|
7
|
+
export declare function useI18n(): I18nFunctions<JSX.Element> & {
|
|
8
|
+
locale: Accessor<CurrentLocale>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CurrentLocale } from "../types.ts";
|
|
2
|
+
import { type I18nFunctions } from "./bind.ts";
|
|
3
|
+
export type { CurrentLocale };
|
|
4
|
+
/** What `t.rich` returns in svelte: text and elements for a snippet to render with `{#each}`; a handler returns `[{ tag: "b", children: chunks }]`. */
|
|
5
|
+
export type SvelteRich = readonly (string | {
|
|
6
|
+
readonly tag: string;
|
|
7
|
+
readonly children: SvelteRich;
|
|
8
|
+
})[];
|
|
9
|
+
export declare function useLocale(): CurrentLocale;
|
|
10
|
+
export declare function useI18n(): I18nFunctions<SvelteRich> & {
|
|
11
|
+
readonly locale: CurrentLocale;
|
|
12
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ComputedRef, type VNode } from "vue";
|
|
2
|
+
import type { CurrentLocale } from "../types.ts";
|
|
3
|
+
import { type I18nFunctions } from "./bind.ts";
|
|
4
|
+
export type { CurrentLocale };
|
|
5
|
+
export declare function useLocale(): ComputedRef<CurrentLocale>;
|
|
6
|
+
export declare function useI18n(): I18nFunctions<VNode[]> & {
|
|
7
|
+
locale: ComputedRef<CurrentLocale>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { I18nSetup } from "../types.ts";
|
|
2
|
+
/** `i18n.catalog`, read without running it; the build error when it names no file or its default export is not `defineCatalog({ … })`. */
|
|
3
|
+
export declare function readCatalogFile(rootDir: string, catalog: string): Promise<string>;
|
|
4
|
+
/** The loaders `#hamur/i18n/catalog` (browser) and `#hamur/i18n/catalog-server`, or `undefined`, and the server's `#hamur/i18n/catalog-source`. */
|
|
5
|
+
export declare const setupCatalog: I18nSetup;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** A `keepKeys` glob as a matcher over a whole key; `*` is one segment, `**` any run of characters. */
|
|
2
|
+
export declare function keepMatcher(glob: string): RegExp;
|
|
3
|
+
export interface ClientRead {
|
|
4
|
+
keys: Set<string>;
|
|
5
|
+
/** The first file and line of a call whose key is not a literal. */
|
|
6
|
+
dynamic?: {
|
|
7
|
+
file: string;
|
|
8
|
+
line: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** The literal keys of every source file among the client build's metafile inputs, outside `node_modules`. */
|
|
12
|
+
export declare function readClientInputs(inputs: Iterable<string>, rootDir: string): Promise<ClientRead>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HamurContext } from "hamur/kit";
|
|
2
|
+
import type { ResolvedI18nOptions } from "../types.ts";
|
|
3
|
+
export interface ExtractFlags {
|
|
4
|
+
check: boolean;
|
|
5
|
+
prune: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Prints the findings of `hamur i18n extract` to `out`, writes the catalogs and resolves to the exit code. `--check` with
|
|
9
|
+
* `--prune`, and `--prune` with a dynamic key, reject.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extract(hamur: HamurContext, options: ResolvedI18nOptions, flags: ExtractFlags, out: (line: string) => void): Promise<number>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { I18nSetup } from "../types.ts";
|
|
2
|
+
/** The build's `site.url` or the variable that sets it at run time; without either the head writes no hreflang or canonical. */
|
|
3
|
+
export declare const SITE_URL_WARNING = "[hamur] site.url is not set; hreflang and canonical links are not written";
|
|
4
|
+
export declare const setupHead: I18nSetup;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { I18nSetup } from "../types.ts";
|
|
2
|
+
export interface LocaleFiles {
|
|
3
|
+
/** Locale code to its files, the highest priority first. */
|
|
4
|
+
byCode: Map<string, string[]>;
|
|
5
|
+
/** Files in a `locales/` whose name is not a locale code. */
|
|
6
|
+
ignored: string[];
|
|
7
|
+
}
|
|
8
|
+
/** The `locales/<code>.json` of each root (the app, then its layers), for the configured codes. */
|
|
9
|
+
export declare function scanLocaleFiles(roots: string[], codes: string[]): Promise<LocaleFiles>;
|
|
10
|
+
/** The first key defined twice in one JSON object, as a dotted path; `JSON.parse` keeps the last one silently. */
|
|
11
|
+
export declare function duplicateKey(text: string): string | undefined;
|
|
12
|
+
/** `{ "home": { "title": "x" } }` as `{ "home.title": "x" }`; its JSON errors name `file` and the key. */
|
|
13
|
+
export declare function flattenMessages(value: unknown, file: string): Record<string, string>;
|
|
14
|
+
export interface MergedMessages {
|
|
15
|
+
messages: Record<string, string>;
|
|
16
|
+
/** The file each key came from. */
|
|
17
|
+
origin: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/** The flattened messages of `files` (the highest priority first); a key in an earlier file wins. */
|
|
20
|
+
export declare function mergeLocaleFiles(files: string[], rootDir: string): Promise<MergedMessages>;
|
|
21
|
+
/** `own` plus every key a locale of `chain` has, the first of the chain winning; the added keys are listed in `filled`. */
|
|
22
|
+
export declare function fillFromChain(own: MergedMessages, chain: MergedMessages[]): {
|
|
23
|
+
merged: MergedMessages;
|
|
24
|
+
filled: string[];
|
|
25
|
+
};
|
|
26
|
+
/** The per-locale modules `#hamur/i18n/<code>`, the loaders and the server's chunk table. */
|
|
27
|
+
export declare const setupMessages: I18nSetup;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { I18nSetup } from "../types.ts";
|
|
2
|
+
/** On a static preset the one URL of a page under `no_prefix` is written in the default locale only. */
|
|
3
|
+
export declare const noPrefixPrerenderWarning: (defaultLocale: string) => string;
|
|
4
|
+
export declare const isStaticPreset: (preset: string) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Every seeded page is also seeded in every other locale. Under `no_prefix` a page has one URL: a server
|
|
7
|
+
* preset prerenders no page (a `prerender.ignore` entry), so each renders in the request's locale; a static preset writes it in
|
|
8
|
+
* the default locale and the build warns once. With domains the host picks the locale, so no page is prerendered either.
|
|
9
|
+
*/
|
|
10
|
+
export declare const setupPrerender: I18nSetup;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RouteRecord, type HamurContext } from "hamur/kit";
|
|
2
|
+
import { type RouteTable } from "../runtime/match.ts";
|
|
3
|
+
import type { ResolvedI18nOptions } from "../types.ts";
|
|
4
|
+
export interface LocalizedRoutes {
|
|
5
|
+
routes: RouteRecord[];
|
|
6
|
+
table: RouteTable;
|
|
7
|
+
}
|
|
8
|
+
/** The page records with their per-locale copies, and the route table of `#hamur/i18n/routes`; `routes` is not changed. */
|
|
9
|
+
export declare function localizeRoutes(routes: RouteRecord[], options: ResolvedI18nOptions, rootDir?: string): LocalizedRoutes;
|
|
10
|
+
/** The route table `setupRoutes` built for `hamur`; empty before `extendPages` ran. */
|
|
11
|
+
export declare const routeTableOf: (hamur: HamurContext) => RouteTable;
|
|
12
|
+
export declare const rememberRouteTable: (hamur: HamurContext, table: RouteTable) => void;
|
|
13
|
+
/** Route copies, the route table and options templates, the app plugin, the route middleware and the root redirect. */
|
|
14
|
+
export declare function setupRoutes(options: ResolvedI18nOptions, hamur: HamurContext): void;
|