@kamod-ch/otok-i18n 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/catalog.d.ts +17 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +39 -0
- package/dist/catalog.js.map +1 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +67 -0
- package/dist/client.js.map +1 -0
- package/dist/format.d.ts +5 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +39 -0
- package/dist/format.js.map +1 -0
- package/dist/head.d.ts +18 -0
- package/dist/head.d.ts.map +1 -0
- package/dist/head.js +33 -0
- package/dist/head.js.map +1 -0
- package/dist/i18n.d.ts +24 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +76 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/interpolate.d.ts +7 -0
- package/dist/interpolate.d.ts.map +1 -0
- package/dist/interpolate.js +28 -0
- package/dist/interpolate.js.map +1 -0
- package/dist/loader.d.ts +23 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +31 -0
- package/dist/loader.js.map +1 -0
- package/dist/locale-core.d.ts +19 -0
- package/dist/locale-core.d.ts.map +1 -0
- package/dist/locale-core.js +55 -0
- package/dist/locale-core.js.map +1 -0
- package/dist/locale.d.ts +33 -0
- package/dist/locale.d.ts.map +1 -0
- package/dist/locale.js +110 -0
- package/dist/locale.js.map +1 -0
- package/dist/messages.d.ts +9 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +52 -0
- package/dist/messages.js.map +1 -0
- package/dist/middleware.d.ts +17 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +121 -0
- package/dist/middleware.js.map +1 -0
- package/dist/plugin.d.ts +16 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +55 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plural.d.ts +5 -0
- package/dist/plural.d.ts.map +1 -0
- package/dist/plural.js +42 -0
- package/dist/plural.js.map +1 -0
- package/dist/registry.d.ts +27 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +34 -0
- package/dist/registry.js.map +1 -0
- package/dist/routes.d.ts +26 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +69 -0
- package/dist/routes.js.map +1 -0
- package/dist/sitemap.d.ts +25 -0
- package/dist/sitemap.d.ts.map +1 -0
- package/dist/sitemap.js +55 -0
- package/dist/sitemap.js.map +1 -0
- package/dist/switcher.d.ts +12 -0
- package/dist/switcher.d.ts.map +1 -0
- package/dist/switcher.js +17 -0
- package/dist/switcher.js.map +1 -0
- package/dist/types.d.ts +96 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kamod
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# @kamod-ch/otok-i18n
|
|
2
|
+
|
|
3
|
+
Full i18n integration for [Otok](https://github.com/kamod-ch/otok): routing, SSR, islands, metadata, and the plugin API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @kamod-ch/otok-i18n hono @kamod-ch/otok
|
|
9
|
+
pnpm add preact # for islands / client hooks
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quick start (plugin API)
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
// otok.config.ts
|
|
16
|
+
import { defineConfig } from "@kamod-ch/otok";
|
|
17
|
+
import i18n from "@kamod-ch/otok-i18n";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [
|
|
21
|
+
i18n({
|
|
22
|
+
locales: ["de", "en", "fr"],
|
|
23
|
+
defaultLocale: "de",
|
|
24
|
+
routing: "prefix-except-default",
|
|
25
|
+
fallbackLocale: "en",
|
|
26
|
+
messages: {
|
|
27
|
+
de: () => import("./locales/de.json"),
|
|
28
|
+
en: () => import("./locales/en.json"),
|
|
29
|
+
fr: () => import("./locales/fr.json"),
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The plugin registers app-level middleware automatically (`configureApp`). No manual `_middleware.ts` required unless you need custom ordering.
|
|
37
|
+
|
|
38
|
+
## Routing modes
|
|
39
|
+
|
|
40
|
+
| Mode | Example URLs |
|
|
41
|
+
|------|----------------|
|
|
42
|
+
| `prefix` | `/de/products`, `/en/products` |
|
|
43
|
+
| `prefix-except-default` | `/products` (de), `/en/products` |
|
|
44
|
+
| `domain` | `example.ch`, `example.fr` (via `domains` map) |
|
|
45
|
+
| `none` | No locale in URL — cookie / `Accept-Language` only |
|
|
46
|
+
|
|
47
|
+
## Locale resolution priority
|
|
48
|
+
|
|
49
|
+
1. **URL** — path prefix or domain (depending on `routing`)
|
|
50
|
+
2. **Cookie** — `locale` (configurable via `cookieName`)
|
|
51
|
+
3. **`Accept-Language`**
|
|
52
|
+
4. **`defaultLocale`**
|
|
53
|
+
|
|
54
|
+
Unknown locale prefixes (e.g. `/xx/about`) redirect once to the canonical path when `redirectUnknownLocale` is true (default).
|
|
55
|
+
|
|
56
|
+
## Server: loaders and `t()`
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { defineLoader, serializeI18n } from "@kamod-ch/otok-i18n/loader";
|
|
60
|
+
import { i18nHead } from "@kamod-ch/otok-i18n";
|
|
61
|
+
|
|
62
|
+
export const loader = defineLoader(({ i18n, hono }) => ({
|
|
63
|
+
title: i18n.t("dashboard.welcome"),
|
|
64
|
+
i18n: serializeI18n(hono), // active locale only — safe for hydration
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
export const head = ({ data }) =>
|
|
68
|
+
i18nHead({
|
|
69
|
+
locale: data.i18n.locale,
|
|
70
|
+
locales: ["de", "en", "fr"],
|
|
71
|
+
defaultLocale: "de",
|
|
72
|
+
origin: "https://example.com",
|
|
73
|
+
pathname: "/dashboard",
|
|
74
|
+
extra: { title: data.title },
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Islands: `useI18n()` / `useTranslation()`
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import { I18nProvider, useI18n } from "@kamod-ch/otok-i18n/client";
|
|
82
|
+
|
|
83
|
+
export function Welcome({ itemCount }: { itemCount: number }) {
|
|
84
|
+
const { t, locale, formatCurrency } = useI18n();
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
<h1>{t("dashboard.welcome")}</h1>
|
|
88
|
+
<p>{t("items", { count: itemCount })}</p>
|
|
89
|
+
<p>{formatCurrency(29, "CHF")}</p>
|
|
90
|
+
</>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// In route: pass loader payload
|
|
95
|
+
<I18nProvider {...data.i18n}>
|
|
96
|
+
<Welcome itemCount={3} />
|
|
97
|
+
</I18nProvider>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
SSR and hydration use the same `serializeI18n()` payload — only the active locale messages are sent to the client.
|
|
101
|
+
|
|
102
|
+
## Features
|
|
103
|
+
|
|
104
|
+
- Lazy message loading per locale (dynamic `import()`)
|
|
105
|
+
- Fallback locale for missing keys
|
|
106
|
+
- Pluralization via `Intl.PluralRules` (`items.one`, `items.other`, + `{count}`)
|
|
107
|
+
- Safe `{variable}` interpolation (HTML-escaped)
|
|
108
|
+
- `formatDate`, `formatTime`, `formatNumber`, `formatPercent`, `formatCurrency` via `Intl`
|
|
109
|
+
- Dev warnings for missing keys; production-safe fallbacks
|
|
110
|
+
- `LocaleSwitcher` component (`@kamod-ch/otok-i18n/switcher`)
|
|
111
|
+
- Localized sitemap helpers (`@kamod-ch/otok-i18n/sitemap`)
|
|
112
|
+
- RTL direction hint via `useI18n().direction`
|
|
113
|
+
- Typed keys: `TranslationKey<typeof messages>`, `FlattenKeys<…>`
|
|
114
|
+
|
|
115
|
+
## Route helpers
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { localizePath, switchLocalePath, createLinkHelper } from "@kamod-ch/otok-i18n/routes";
|
|
119
|
+
|
|
120
|
+
localizePath("/products", "en", { defaultLocale: "de", routing: "prefix-except-default" });
|
|
121
|
+
// → "/en/products"
|
|
122
|
+
|
|
123
|
+
switchLocalePath("/en/products", "fr", ["de", "en", "fr"], { defaultLocale: "de" });
|
|
124
|
+
// → "/fr/products"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Legacy flat-catalog API
|
|
128
|
+
|
|
129
|
+
Still supported for apps without the plugin:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { createI18nMiddleware, toRouteMiddleware } from "@kamod-ch/otok-i18n/middleware";
|
|
133
|
+
|
|
134
|
+
// File-based _middleware.ts — export default:
|
|
135
|
+
export default createI18nMiddleware(i18nConfig);
|
|
136
|
+
|
|
137
|
+
// Programmatic route middleware arrays:
|
|
138
|
+
middleware: [toRouteMiddleware(createI18nMiddleware(i18nConfig))];
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Exports
|
|
142
|
+
|
|
143
|
+
| Subpath | Purpose |
|
|
144
|
+
|---------|---------|
|
|
145
|
+
| `@kamod-ch/otok-i18n` | Plugin factory + core API |
|
|
146
|
+
| `@kamod-ch/otok-i18n/middleware` | Middleware, `readI18n`, `toRouteMiddleware` |
|
|
147
|
+
| `@kamod-ch/otok-i18n/loader` | `defineLoader`, `serializeI18n` |
|
|
148
|
+
| `@kamod-ch/otok-i18n/client` | `I18nProvider`, `useI18n`, `useTranslation` |
|
|
149
|
+
| `@kamod-ch/otok-i18n/routes` | Path / link helpers |
|
|
150
|
+
| `@kamod-ch/otok-i18n/sitemap` | Localized sitemap XML |
|
|
151
|
+
| `@kamod-ch/otok-i18n/switcher` | `LocaleSwitcher` component |
|
|
152
|
+
|
|
153
|
+
## Example
|
|
154
|
+
|
|
155
|
+
See [`examples/i18n-trilingual`](../../examples/i18n-trilingual) for a complete DE / EN / FR app.
|
|
156
|
+
|
|
157
|
+
## Related packages
|
|
158
|
+
|
|
159
|
+
| Package | Purpose |
|
|
160
|
+
|---------|---------|
|
|
161
|
+
| `@kamod-ch/otok-auth` | Sessions, CSRF |
|
|
162
|
+
| `@kamod-ch/otok-validation` | Standard Schema validation |
|
|
163
|
+
| `@kamod-ch/otok-flash` | Flash messages |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FlatMessages, TranslateValues, Translator } from "./types.js";
|
|
2
|
+
export type { FlatMessages, TranslateValues, Translator } from "./types.js";
|
|
3
|
+
export type MessageCatalog<Locales extends string = string> = Record<Locales, FlatMessages>;
|
|
4
|
+
export interface CreateTranslatorOptions {
|
|
5
|
+
warnMissingKeys?: boolean;
|
|
6
|
+
onMissingKey?: (key: string, locale: string) => void;
|
|
7
|
+
}
|
|
8
|
+
declare function resolveMessage(messages: FlatMessages, fallbackMessages: FlatMessages, locale: string, key: string, values?: TranslateValues, explicitFallback?: string): string | undefined;
|
|
9
|
+
export declare function createTranslator(messages: FlatMessages, locale: string, fallbackLocale: string, fallbackMessages?: FlatMessages, options?: CreateTranslatorOptions): Translator;
|
|
10
|
+
/** Extract typed keys from a flat message object. */
|
|
11
|
+
export type TranslationKey<M extends FlatMessages> = Extract<keyof M, string>;
|
|
12
|
+
/** Flatten nested object keys into dot notation for typed catalogs. */
|
|
13
|
+
export type FlattenKeys<T, Prefix extends string = ""> = T extends string ? Prefix extends "" ? never : Prefix : {
|
|
14
|
+
[K in keyof T & string]: T[K] extends string ? Prefix extends "" ? K : `${Prefix}.${K}` : FlattenKeys<T[K], Prefix extends "" ? K : `${Prefix}.${K}`>;
|
|
15
|
+
}[keyof T & string];
|
|
16
|
+
export { resolveMessage };
|
|
17
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE5E,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE5E,MAAM,MAAM,cAAc,CAAC,OA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,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { interpolate } from "./interpolate.js";
|
|
2
|
+
import { extractCount, pickPluralMessage } from "./plural.js";
|
|
3
|
+
function resolveMessage(messages, fallbackMessages, locale, key, values, explicitFallback) {
|
|
4
|
+
const count = extractCount(values);
|
|
5
|
+
if (count != null) {
|
|
6
|
+
const plural = pickPluralMessage(messages, key, locale, count) ??
|
|
7
|
+
pickPluralMessage(fallbackMessages, key, locale, count);
|
|
8
|
+
if (plural != null)
|
|
9
|
+
return interpolate(plural, { ...values, count });
|
|
10
|
+
}
|
|
11
|
+
const primary = messages[key];
|
|
12
|
+
if (primary != null && primary !== "")
|
|
13
|
+
return interpolate(primary, values);
|
|
14
|
+
const secondary = fallbackMessages[key];
|
|
15
|
+
if (secondary != null && secondary !== "")
|
|
16
|
+
return interpolate(secondary, values);
|
|
17
|
+
if (explicitFallback != null && explicitFallback !== "")
|
|
18
|
+
return explicitFallback;
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
export function createTranslator(messages, locale, fallbackLocale, fallbackMessages = {}, options = {}) {
|
|
22
|
+
const warn = options.warnMissingKeys ?? process.env.NODE_ENV !== "production";
|
|
23
|
+
const warned = new Set();
|
|
24
|
+
return (key, values, explicitFallback) => {
|
|
25
|
+
const resolved = resolveMessage(messages, fallbackMessages, locale, key, values, explicitFallback);
|
|
26
|
+
if (resolved != null)
|
|
27
|
+
return resolved;
|
|
28
|
+
if (warn && !warned.has(key)) {
|
|
29
|
+
warned.add(key);
|
|
30
|
+
options.onMissingKey?.(key, locale);
|
|
31
|
+
if (process.env.NODE_ENV !== "production") {
|
|
32
|
+
console.warn(`[otok-i18n] missing key "${key}" for locale "${locale}"`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return explicitFallback ?? key;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export { resolveMessage };
|
|
39
|
+
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cAAsB,EACtB,mBAAiC,EAAE,EACnC,UAAmC,EAAE;IAErC,MAAM,IAAI,GAAG,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAC9E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IAEjC,OAAO,CAAC,GAAW,EAAE,MAAwB,EAAE,gBAAyB,EAAE,EAAE;QAC1E,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACnG,IAAI,QAAQ,IAAI,IAAI;YAAE,OAAO,QAAQ,CAAC;QAEtC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChB,OAAO,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACpC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;gBAC1C,OAAO,CAAC,IAAI,CAAC,4BAA4B,GAAG,iBAAiB,MAAM,GAAG,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;QAED,OAAO,gBAAgB,IAAI,GAAG,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAgBD,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ComponentChildren } from "preact";
|
|
2
|
+
import { type FlatMessages, type Translator } from "./catalog.js";
|
|
3
|
+
import type { Formatters } from "./types.js";
|
|
4
|
+
import type { I18nClientPayload, RoutingMode } from "./types.js";
|
|
5
|
+
export type I18nProviderProps = I18nClientPayload & {
|
|
6
|
+
children?: ComponentChildren;
|
|
7
|
+
};
|
|
8
|
+
export interface I18nHookValue {
|
|
9
|
+
locale: string;
|
|
10
|
+
defaultLocale: string;
|
|
11
|
+
fallbackLocale: string;
|
|
12
|
+
routing: RoutingMode;
|
|
13
|
+
t: Translator;
|
|
14
|
+
formatters: Formatters;
|
|
15
|
+
formatDate: Formatters["formatDate"];
|
|
16
|
+
formatTime: Formatters["formatTime"];
|
|
17
|
+
formatNumber: Formatters["formatNumber"];
|
|
18
|
+
formatPercent: Formatters["formatPercent"];
|
|
19
|
+
formatCurrency: Formatters["formatCurrency"];
|
|
20
|
+
direction: "ltr" | "rtl";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Provides `t()`, formatters, and locale for island / client trees.
|
|
24
|
+
* Pass `i18n.toClientPayload()` from the loader — only the active locale is serialized.
|
|
25
|
+
*/
|
|
26
|
+
export declare function I18nProvider({ locale, defaultLocale, fallbackLocale, messages, routing, children, }: I18nProviderProps): import("preact").JSX.Element;
|
|
27
|
+
/** Legacy alias — accepts flat catalog shape. */
|
|
28
|
+
export declare function I18nProviderFromCatalog({ locale, defaultLocale, catalog, children, }: {
|
|
29
|
+
locale: string;
|
|
30
|
+
defaultLocale: string;
|
|
31
|
+
catalog: Record<string, FlatMessages>;
|
|
32
|
+
children: ComponentChildren;
|
|
33
|
+
}): import("preact").JSX.Element;
|
|
34
|
+
export declare function useI18n(): I18nHookValue;
|
|
35
|
+
/** Alias for `useI18n`. */
|
|
36
|
+
export declare const useTranslation: typeof useI18n;
|
|
37
|
+
/** Returns the translation function; outside a provider, returns `fallback ?? key`. */
|
|
38
|
+
export declare function useT(): Translator;
|
|
39
|
+
export declare function useLocale(): string | null;
|
|
40
|
+
export type { FlatMessages, I18nClientPayload, Translator } from "./types.js";
|
|
41
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAChD,OAA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vC;AAED,2BAA2B;AAC3B,eAAO,MAAM,cAAc,gBAAU,CAAC;AAEtC,uFAAuF;AACvF,wBAAgB,IAAI,IAAI,UAAU,CAEjC;AAED,wBAAgB,SAAS,IAAI,MAAM,GAAG,IAAI,CAEzC;AAED,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { createContext } from "preact";
|
|
3
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
4
|
+
import { createTranslator } from "./catalog.js";
|
|
5
|
+
import { createFormatters, localeDirection } from "./format.js";
|
|
6
|
+
const I18nContext = createContext(null);
|
|
7
|
+
/**
|
|
8
|
+
* Provides `t()`, formatters, and locale for island / client trees.
|
|
9
|
+
* Pass `i18n.toClientPayload()` from the loader — only the active locale is serialized.
|
|
10
|
+
*/
|
|
11
|
+
export function I18nProvider({ locale, defaultLocale, fallbackLocale = defaultLocale, messages, routing = "prefix-except-default", children, }) {
|
|
12
|
+
const value = useMemo(() => {
|
|
13
|
+
const formatters = createFormatters(locale);
|
|
14
|
+
return {
|
|
15
|
+
locale,
|
|
16
|
+
defaultLocale,
|
|
17
|
+
fallbackLocale,
|
|
18
|
+
routing,
|
|
19
|
+
t: createTranslator(messages, locale, fallbackLocale, {}, { warnMissingKeys: false }),
|
|
20
|
+
formatters,
|
|
21
|
+
formatDate: formatters.formatDate,
|
|
22
|
+
formatTime: formatters.formatTime,
|
|
23
|
+
formatNumber: formatters.formatNumber,
|
|
24
|
+
formatPercent: formatters.formatPercent,
|
|
25
|
+
formatCurrency: formatters.formatCurrency,
|
|
26
|
+
direction: localeDirection(locale),
|
|
27
|
+
};
|
|
28
|
+
}, [locale, defaultLocale, fallbackLocale, messages, routing]);
|
|
29
|
+
return _jsx(I18nContext.Provider, { value: value, children: children });
|
|
30
|
+
}
|
|
31
|
+
/** Legacy alias — accepts flat catalog shape. */
|
|
32
|
+
export function I18nProviderFromCatalog({ locale, defaultLocale, catalog, children, }) {
|
|
33
|
+
const messages = catalog[locale] ?? {};
|
|
34
|
+
return (_jsx(I18nProvider, { locale: locale, defaultLocale: defaultLocale, fallbackLocale: defaultLocale, messages: messages, routing: "prefix-except-default", children: children }));
|
|
35
|
+
}
|
|
36
|
+
export function useI18n() {
|
|
37
|
+
const ctx = useContext(I18nContext);
|
|
38
|
+
if (!ctx) {
|
|
39
|
+
const noop = (key, _values, fallback) => fallback ?? key;
|
|
40
|
+
const formatters = createFormatters("en");
|
|
41
|
+
return {
|
|
42
|
+
locale: "en",
|
|
43
|
+
defaultLocale: "en",
|
|
44
|
+
fallbackLocale: "en",
|
|
45
|
+
routing: "none",
|
|
46
|
+
t: noop,
|
|
47
|
+
formatters,
|
|
48
|
+
formatDate: formatters.formatDate,
|
|
49
|
+
formatTime: formatters.formatTime,
|
|
50
|
+
formatNumber: formatters.formatNumber,
|
|
51
|
+
formatPercent: formatters.formatPercent,
|
|
52
|
+
formatCurrency: formatters.formatCurrency,
|
|
53
|
+
direction: "ltr",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return ctx;
|
|
57
|
+
}
|
|
58
|
+
/** Alias for `useI18n`. */
|
|
59
|
+
export const useTranslation = useI18n;
|
|
60
|
+
/** Returns the translation function; outside a provider, returns `fallback ?? key`. */
|
|
61
|
+
export function useT() {
|
|
62
|
+
return useI18n().t;
|
|
63
|
+
}
|
|
64
|
+
export function useLocale() {
|
|
65
|
+
return useContext(I18nContext)?.locale ?? null;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MA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OAAO,CACL,KAAC,YAAY,IACX,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,EAC5B,cAAc,EAAE,aAAa,EAC7B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAC,uBAAuB,YAE9B,QAAQ,GACI,CAChB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,MAAM,GAAG,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACpC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,OAAiB,EAAE,QAAiB,EAAE,EAAE,CAAC,QAAQ,IAAI,GAAG,CAAC;QACpF,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,aAAa,EAAE,IAAI;YACnB,cAAc,EAAE,IAAI;YACpB,OAAO,EAAE,MAAM;YACf,CAAC,EAAE,IAAI;YACP,UAAU;YACV,UAAU,EAAE,UAAU,CAAC,UAAU;YACjC,UAAU,EAAE,UAAU,CAAC,UAAU;YACjC,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,aAAa,EAAE,UAAU,CAAC,aAAa;YACvC,cAAc,EAAE,UAAU,CAAC,cAAc;YACzC,SAAS,EAAE,KAAK;SACjB,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,2BAA2B;AAC3B,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,uFAAuF;AACvF,MAAM,UAAU,IAAI;IAClB,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,IAAI,IAAI,CAAC;AACjD,CAAC"}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Formatters } from "./types.js";
|
|
2
|
+
export declare function createFormatters(locale: string): Formatters;
|
|
3
|
+
/** BCP 47 direction hint for RTL preparation. */
|
|
4
|
+
export declare function localeDirection(locale: string): "ltr" | "rtl";
|
|
5
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAoB3D;AAED,iDAAiD;AACjD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,CAa7D"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function createFormatters(locale) {
|
|
2
|
+
return {
|
|
3
|
+
formatDate(value, options) {
|
|
4
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
5
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
6
|
+
},
|
|
7
|
+
formatTime(value, options) {
|
|
8
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
9
|
+
return new Intl.DateTimeFormat(locale, { ...options, timeStyle: options?.timeStyle ?? "medium" }).format(date);
|
|
10
|
+
},
|
|
11
|
+
formatNumber(value, options) {
|
|
12
|
+
return new Intl.NumberFormat(locale, options).format(value);
|
|
13
|
+
},
|
|
14
|
+
formatPercent(value, options) {
|
|
15
|
+
return new Intl.NumberFormat(locale, { ...options, style: "percent" }).format(value);
|
|
16
|
+
},
|
|
17
|
+
formatCurrency(value, currency, options) {
|
|
18
|
+
return new Intl.NumberFormat(locale, { ...options, style: "currency", currency }).format(value);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** BCP 47 direction hint for RTL preparation. */
|
|
23
|
+
export function localeDirection(locale) {
|
|
24
|
+
try {
|
|
25
|
+
const localeObj = new Intl.Locale(locale);
|
|
26
|
+
if ("textInfo" in localeObj && localeObj.textInfo && typeof localeObj.textInfo === "object") {
|
|
27
|
+
const direction = localeObj.textInfo.direction;
|
|
28
|
+
if (direction === "rtl")
|
|
29
|
+
return "rtl";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Intl.Locale may not support textInfo in all runtimes
|
|
34
|
+
}
|
|
35
|
+
const rtlPrefixes = ["ar", "he", "fa", "ur", "yi"];
|
|
36
|
+
const primary = locale.split("-")[0]?.toLowerCase();
|
|
37
|
+
return rtlPrefixes.includes(primary ?? "") ? "rtl" : "ltr";
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO;QACL,UAAU,CAAC,KAAK,EAAE,OAAO;YACvB,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;YAC7D,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/D,CAAC;QACD,UAAU,CAAC,KAAK,EAAE,OAAO;YACvB,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;YAC7D,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjH,CAAC;QACD,YAAY,CAAC,KAAK,EAAE,OAAO;YACzB,OAAO,IAAI,IAAI,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,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AAC7D,CAAC"}
|
package/dist/head.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OtokHead } from "@kamod-ch/otok/server";
|
|
2
|
+
import type { RoutingMode } from "./types.js";
|
|
3
|
+
export interface I18nHeadOptions {
|
|
4
|
+
locale: string;
|
|
5
|
+
locales: readonly string[];
|
|
6
|
+
defaultLocale: string;
|
|
7
|
+
routing?: RoutingMode;
|
|
8
|
+
/** Absolute site origin, e.g. `https://example.com` */
|
|
9
|
+
origin?: string;
|
|
10
|
+
/** Canonical pathname without locale prefix */
|
|
11
|
+
pathname?: string;
|
|
12
|
+
extra?: OtokHead;
|
|
13
|
+
}
|
|
14
|
+
/** Merge `lang` and optional hreflang / canonical links into an Otok head result. */
|
|
15
|
+
export declare function i18nHead(options: I18nHeadOptions): OtokHead;
|
|
16
|
+
/** @deprecated Pass an options object for hreflang support. */
|
|
17
|
+
export declare function i18nHead(locale: string, extra?: OtokHead): OtokHead;
|
|
18
|
+
//# sourceMappingURL=head.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"head.d.ts","sourceRoot":"","sources":["../src/head.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAgB,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,QAAQ,CAAC;AAC7D,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC"}
|
package/dist/head.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { localizePath } from "./routes.js";
|
|
2
|
+
export function i18nHead(localeOrOptions, extra = {}) {
|
|
3
|
+
if (typeof localeOrOptions === "string") {
|
|
4
|
+
return { ...extra, lang: localeOrOptions };
|
|
5
|
+
}
|
|
6
|
+
const { locale, locales, defaultLocale, routing = "prefix-except-default", origin, pathname = "/", extra: headExtra = {}, } = localeOrOptions;
|
|
7
|
+
const links = [...(headExtra.links ?? [])];
|
|
8
|
+
if (origin) {
|
|
9
|
+
const canonicalHref = `${origin.replace(/\/$/, "")}${localizePath(pathname, locale, { defaultLocale, routing })}`;
|
|
10
|
+
if (!links.some((l) => l.rel === "canonical")) {
|
|
11
|
+
links.push({ rel: "canonical", href: canonicalHref });
|
|
12
|
+
}
|
|
13
|
+
for (const altLocale of locales) {
|
|
14
|
+
const href = `${origin.replace(/\/$/, "")}${localizePath(pathname, altLocale, { defaultLocale, routing })}`;
|
|
15
|
+
links.push({
|
|
16
|
+
rel: "alternate",
|
|
17
|
+
href,
|
|
18
|
+
hreflang: altLocale,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
links.push({
|
|
22
|
+
rel: "alternate",
|
|
23
|
+
href: `${origin.replace(/\/$/, "")}${localizePath(pathname, defaultLocale, { defaultLocale, routing })}`,
|
|
24
|
+
hreflang: "x-default",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...headExtra,
|
|
29
|
+
lang: locale,
|
|
30
|
+
links,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=head.js.map
|
package/dist/head.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1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C;gBACT,GAAG,EAAE,WAAW;gBAChB,IAAI;gBACJ,QAAQ,EAAE,SAAS;aACpB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,IAAI,CAAC;YACT,GAAG,EAAE,WAAW;YAChB,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,YAAY,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,EAAE;YACxG,QAAQ,EAAE,WAAW;SACtB,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,GAAG,SAAS;QACZ,IAAI,EAAE,MAAM;QACZ,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type MessageCatalog } from "./catalog.js";
|
|
2
|
+
import type { FlatMessages, I18nConfig, I18nContext, I18nPluginOptions, ResolveLocaleInput, RoutingMode } from "./types.js";
|
|
3
|
+
import { type ResolveLocaleOptions } from "./locale.js";
|
|
4
|
+
export interface CreateI18nOptions {
|
|
5
|
+
locale: string;
|
|
6
|
+
source: import("./types.js").LocaleSource;
|
|
7
|
+
routing: RoutingMode;
|
|
8
|
+
defaultLocale: string;
|
|
9
|
+
fallbackLocale: string;
|
|
10
|
+
messages: FlatMessages;
|
|
11
|
+
fallbackMessages?: FlatMessages;
|
|
12
|
+
warnMissingKeys?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function buildI18nContext(options: CreateI18nOptions): I18nContext;
|
|
15
|
+
/** Create i18n context from a static catalog (legacy API). */
|
|
16
|
+
export declare function createI18n<Catalog extends MessageCatalog>(config: I18nConfig<Catalog>, input?: Pick<ResolveLocaleOptions, "param" | "cookie" | "acceptLanguage"> & {
|
|
17
|
+
domain?: string;
|
|
18
|
+
}): I18nContext;
|
|
19
|
+
/** Create i18n context with lazy-loaded messages (plugin API). */
|
|
20
|
+
export declare function createI18nAsync(config: Pick<I18nPluginOptions, "locales" | "defaultLocale" | "fallbackLocale" | "messages" | "routing" | "domains"> & {
|
|
21
|
+
warnMissingKeys?: boolean;
|
|
22
|
+
}, input: ResolveLocaleInput, namespaces?: string[]): Promise<I18nContext>;
|
|
23
|
+
export type { I18nConfig, I18nContext };
|
|
24
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAIrE,OAAO,KAAK,EACV,YAAY,EAEZ,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAoC,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1F,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC;IAC1C,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,YAAY,CAAC;IACvB,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,WAAW,CAgCxE;AAED,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,OAAO,SAAS,cAAc,EACvD,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,EAC3B,KAAK,GAAE,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,QAAQ,GAAG,gBAAgB,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAClG,WAAW,CA6Bb;AAED,kEAAkE;AAClE,wBAAsB,eAAe,CACnC,MAAM,EAAE,IAAI,CACV,iBAAiB,EACjB,SAAS,GAAG,eAAe,GAAG,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CACpF,GAAG;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,EACjC,KAAK,EAAE,kBAAkB,EACzB,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,WAAW,CAAC,CAyBtB;AAED,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createTranslator } from "./catalog.js";
|
|
2
|
+
import { createFormatters } from "./format.js";
|
|
3
|
+
import { getCachedMessages } from "./messages.js";
|
|
4
|
+
import { resolveLocale, resolveLocaleFull } from "./locale.js";
|
|
5
|
+
export function buildI18nContext(options) {
|
|
6
|
+
const { locale, source, routing, defaultLocale, fallbackLocale, messages, fallbackMessages = {}, warnMissingKeys, } = options;
|
|
7
|
+
const formatters = createFormatters(locale);
|
|
8
|
+
const toClientPayload = () => ({
|
|
9
|
+
locale,
|
|
10
|
+
defaultLocale,
|
|
11
|
+
fallbackLocale,
|
|
12
|
+
messages,
|
|
13
|
+
routing,
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
locale,
|
|
17
|
+
defaultLocale,
|
|
18
|
+
fallbackLocale,
|
|
19
|
+
source,
|
|
20
|
+
routing,
|
|
21
|
+
t: createTranslator(messages, locale, fallbackLocale, fallbackMessages, { warnMissingKeys }),
|
|
22
|
+
formatters,
|
|
23
|
+
toClientPayload,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Create i18n context from a static catalog (legacy API). */
|
|
27
|
+
export function createI18n(config, input = {}) {
|
|
28
|
+
const routing = config.routing ?? "prefix-except-default";
|
|
29
|
+
const fallbackLocale = (config.fallbackLocale ?? config.defaultLocale);
|
|
30
|
+
const { locale, source } = resolveLocale({
|
|
31
|
+
param: input.param,
|
|
32
|
+
domain: input.domain,
|
|
33
|
+
cookie: input.cookie,
|
|
34
|
+
acceptLanguage: input.acceptLanguage,
|
|
35
|
+
locales: config.locales,
|
|
36
|
+
defaultLocale: config.defaultLocale,
|
|
37
|
+
});
|
|
38
|
+
const resolvedLocale = (config.locales.includes(locale)
|
|
39
|
+
? locale
|
|
40
|
+
: config.defaultLocale);
|
|
41
|
+
const messages = config.catalog[resolvedLocale] ?? {};
|
|
42
|
+
const fallbackMessages = config.catalog[fallbackLocale] ?? {};
|
|
43
|
+
return buildI18nContext({
|
|
44
|
+
locale: resolvedLocale,
|
|
45
|
+
source,
|
|
46
|
+
routing,
|
|
47
|
+
defaultLocale: config.defaultLocale,
|
|
48
|
+
fallbackLocale,
|
|
49
|
+
messages,
|
|
50
|
+
fallbackMessages,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Create i18n context with lazy-loaded messages (plugin API). */
|
|
54
|
+
export async function createI18nAsync(config, input, namespaces) {
|
|
55
|
+
const routing = config.routing ?? "prefix-except-default";
|
|
56
|
+
const fallbackLocale = config.fallbackLocale ?? config.defaultLocale;
|
|
57
|
+
const resolved = resolveLocaleFull(input);
|
|
58
|
+
const locale = config.locales.includes(resolved.locale) ? resolved.locale : config.defaultLocale;
|
|
59
|
+
const loader = config.messages[locale];
|
|
60
|
+
const fallbackLoader = config.messages[fallbackLocale];
|
|
61
|
+
const messages = loader ? await getCachedMessages(locale, loader, namespaces) : {};
|
|
62
|
+
const fallbackMessages = fallbackLoader
|
|
63
|
+
? await getCachedMessages(fallbackLocale, fallbackLoader, namespaces)
|
|
64
|
+
: {};
|
|
65
|
+
return buildI18nContext({
|
|
66
|
+
locale,
|
|
67
|
+
source: resolved.source,
|
|
68
|
+
routing,
|
|
69
|
+
defaultLocale: config.defaultLocale,
|
|
70
|
+
fallbackLocale,
|
|
71
|
+
messages,
|
|
72
|
+
fallbackMessages,
|
|
73
|
+
warnMissingKeys: config.warnMissingKeys,
|
|
74
|
+
});
|
|
75
|
+
}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AC,MAAsC,CAAC,CAAC;IACvE,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,cAA8C,CAAC,CAAC;IAEvF,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,iBAAiB,CAAC,MAAM,EAAE,MAAyC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtH,MAAM,gBAAgB,GAAG,cAAc;QACrC,CAAC,CAAC,MAAM,iBAAiB,CAAC,cAAc,EAAE,cAAiD,EAAE,UAAU,CAAC;QACxG,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,gBAAgB,CAAC;QACtB,MAAM;QACN,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO;QACP,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,cAAc;QACd,QAAQ;QACR,gBAAgB;QAChB,eAAe,EAAE,MAAM,CAAC,eAAe;KACxC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { createTranslator, type FlattenKeys, type MessageCatalog, type TranslationKey, } from "./catalog.js";
|
|
2
|
+
export type { Translator } from "./types.js";
|
|
3
|
+
export { i18nHead, type I18nHeadOptions } from "./head.js";
|
|
4
|
+
export { buildI18nContext, createI18n, createI18nAsync, type I18nConfig, type I18nContext, } from "./i18n.js";
|
|
5
|
+
export { interpolate } from "./interpolate.js";
|
|
6
|
+
export { defineLoader, defineAction, serializeI18n } from "./loader.js";
|
|
7
|
+
export { DEFAULT_COOKIE_NAME, DEFAULT_PARAM_KEY, looksLikeLocaleSegment, matchLocale, normalizeLocale, parseAcceptLanguage, resolveLocale, resolveLocaleFromDomain, resolveLocaleFull, stripLocaleFromPath, type LocaleSource, type ResolveLocaleOptions, type ResolvedLocale, } from "./locale.js";
|
|
8
|
+
export { clearMessageCache, getCachedMessages, loadLocaleMessages } from "./messages.js";
|
|
9
|
+
export { extractCount, pickPluralMessage, resolvePluralKey } from "./plural.js";
|
|
10
|
+
export { createI18nMiddleware, createI18nPluginMiddleware, configureI18nApp, readI18n, toRouteMiddleware, clearMessageCache as clearI18nMessageCache, } from "./middleware.js";
|
|
11
|
+
export { createFormatters, localeDirection } from "./format.js";
|
|
12
|
+
export { default } from "./plugin.js";
|
|
13
|
+
export { configureI18nApp as configureI18nPluginApp } from "./plugin.js";
|
|
14
|
+
export { createLinkHelper, localizePath, localizeRouteSegment, stripLocaleParam, switchLocalePath, withLocaleParam, type LocalizePathOptions, } from "./routes.js";
|
|
15
|
+
export { clearI18nRuntime, getI18nRuntime, normalizePluginOptions, registerI18nRuntime, tryGetI18nRuntime, type I18nRuntime, type NormalizedI18nOptions, } from "./registry.js";
|
|
16
|
+
export { createLocalizedSitemapEntries, renderSitemapXml, type CreateSitemapOptions, type LocalizedSitemapEntry, type SitemapAlternate, } from "./sitemap.js";
|
|
17
|
+
export type { FlatMessages, Formatters, I18nClientPayload, I18nPluginOptions, LocalizedRouteNames, MessageLoader, MessageValue, NamespaceLoader, ResolveLocaleInput, ResolvedLocaleResult, RoutingMode, TranslateValues, } from "./types.js";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE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