@koine/i18n 2.0.0-beta.128 → 2.0.0-beta.129
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/adapter-js/generators/getI18nDictionaries_inline.cjs.js +0 -1
- package/adapter-js/generators/getI18nDictionaries_inline.esm.js +0 -1
- package/adapter-js/generators/loadTranslations_inline.cjs.js +0 -1
- package/adapter-js/generators/loadTranslations_inline.esm.js +0 -1
- package/adapter-next/generators/I18nLayout.cjs.js +57 -31
- package/adapter-next/generators/I18nLayout.esm.js +57 -31
- package/adapter-next/generators/I18nPage.cjs.js +72 -30
- package/adapter-next/generators/I18nPage.esm.js +72 -30
- package/adapter-next/redirects.cjs.js +11 -11
- package/adapter-next/redirects.esm.js +11 -11
- package/adapter-next/rewrites.cjs.js +23 -23
- package/adapter-next/rewrites.esm.js +23 -23
- package/compiler/code/data-routes.cjs.js +1 -1
- package/compiler/code/data-routes.esm.js +1 -1
- package/formatRoutePathname.cjs.d.ts +2 -0
- package/formatRoutePathname.cjs.default.js +1 -0
- package/formatRoutePathname.cjs.mjs +2 -0
- package/formatRoutePathname.esm.d.ts +2 -0
- package/index.cjs.js +5 -3
- package/index.d.ts +4 -1
- package/index.esm.js +4 -3
- package/interpolateTo.cjs.d.ts +2 -0
- package/interpolateTo.cjs.default.js +1 -0
- package/interpolateTo.cjs.mjs +2 -0
- package/{client/interpolateTo.d.ts → interpolateTo.d.ts} +1 -1
- package/interpolateTo.esm.d.ts +2 -0
- package/package.json +27 -3
- package/routeHasDynamicPortion.cjs.d.ts +2 -0
- package/routeHasDynamicPortion.cjs.default.js +1 -0
- package/routeHasDynamicPortion.cjs.mjs +2 -0
- package/routeHasDynamicPortion.esm.d.ts +2 -0
- package/rtlLocales.cjs.d.ts +2 -0
- package/rtlLocales.cjs.default.js +1 -0
- package/rtlLocales.cjs.js +55 -0
- package/rtlLocales.cjs.mjs +2 -0
- package/rtlLocales.d.ts +2 -0
- package/rtlLocales.esm.d.ts +2 -0
- package/rtlLocales.esm.js +50 -0
- package/adapter-next/generators/__________I18nLayoutLang.d.ts +0 -10
- package/client/index.d.ts +0 -3
- /package/{client/formatRoutePathname.cjs.js → formatRoutePathname.cjs.js} +0 -0
- /package/{client/formatRoutePathname.d.ts → formatRoutePathname.d.ts} +0 -0
- /package/{client/formatRoutePathname.esm.js → formatRoutePathname.esm.js} +0 -0
- /package/{client/interpolateTo.cjs.js → interpolateTo.cjs.js} +0 -0
- /package/{client/interpolateTo.esm.js → interpolateTo.esm.js} +0 -0
- /package/{client/routeHasDynamicPortion.cjs.js → routeHasDynamicPortion.cjs.js} +0 -0
- /package/{client/routeHasDynamicPortion.d.ts → routeHasDynamicPortion.d.ts} +0 -0
- /package/{client/routeHasDynamicPortion.esm.js → routeHasDynamicPortion.esm.js} +0 -0
|
@@ -13,6 +13,8 @@ var m = createAdapter.createGenerator("next", (t)=>{
|
|
|
13
13
|
// index: true,
|
|
14
14
|
content: ()=>/* js */ `
|
|
15
15
|
import React from "react";
|
|
16
|
+
import type { Metadata } from "next/types";
|
|
17
|
+
import { rtlLocales } from "@koine/i18n";
|
|
16
18
|
// import { getI18nDictionaries } from "../getI18nDictionaries";
|
|
17
19
|
import { defaultLocale } from "../defaultLocale";
|
|
18
20
|
import { I18nTranslateProvider } from "../I18nTranslateProvider";
|
|
@@ -20,7 +22,6 @@ import { locales } from "../locales";
|
|
|
20
22
|
import type { I18n } from "../types";
|
|
21
23
|
import { getLocale } from "./getLocale";
|
|
22
24
|
import { I18nLayoutRoot } from "./I18nLayoutRoot";
|
|
23
|
-
// import { I18nNotFound } from "./I18nNotFound";
|
|
24
25
|
import { I18nLocaleContext } from "./I18nLocaleContext";
|
|
25
26
|
${getI18nDictionaries_inline.getI18nDictionaries_inline(1)}
|
|
26
27
|
|
|
@@ -79,50 +80,75 @@ type Configurator = {
|
|
|
79
80
|
* @example
|
|
80
81
|
*
|
|
81
82
|
* \`\`\`
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* };
|
|
86
|
-
* };
|
|
83
|
+
* const layout = i18nServer.layout({
|
|
84
|
+
* namespaces: ["dashboard"],
|
|
85
|
+
* });
|
|
87
86
|
*
|
|
88
|
-
*
|
|
87
|
+
* // or as a function (async supported):
|
|
88
|
+
* type Props = { params: { slug: string; }; };
|
|
89
|
+
*
|
|
90
|
+
* const layout = i18nServer.layout((props: Props, locale) => {
|
|
89
91
|
* return {
|
|
90
92
|
* namespaces: ["dashboard"],
|
|
91
93
|
* };
|
|
92
94
|
* });
|
|
93
95
|
* \`\`\`
|
|
94
96
|
*/
|
|
95
|
-
export const createI18nLayout = <
|
|
96
|
-
|
|
97
|
+
export const createI18nLayout = <
|
|
98
|
+
TProps extends {},
|
|
99
|
+
>(
|
|
100
|
+
configurator?:
|
|
101
|
+
| ((
|
|
102
|
+
props: I18n.Props<TProps>,
|
|
103
|
+
locale: I18n.Locale,
|
|
104
|
+
) => Configurator | Promise<Configurator>)
|
|
105
|
+
| Configurator,
|
|
97
106
|
) => {
|
|
107
|
+
const resolveConfigurator = async (props: I18n.Props<TProps>) => {
|
|
108
|
+
const localeParam = props.params?.${e};
|
|
109
|
+
const config = configurator
|
|
110
|
+
? typeof configurator === "function"
|
|
111
|
+
? await configurator(props, localeParam)
|
|
112
|
+
: configurator
|
|
113
|
+
: null;
|
|
114
|
+
const { locale: localeConfig, ...restConfig } = config || {};
|
|
115
|
+
const locale = localeConfig || getLocale();
|
|
116
|
+
return { ...restConfig, locale };
|
|
117
|
+
};
|
|
118
|
+
|
|
98
119
|
return {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
generateStaticParams: () => locales.map((l) => ({ ${e}: l })),
|
|
121
|
+
generateMetadata: (
|
|
122
|
+
impl: (
|
|
123
|
+
props: TProps & { locale: I18n.Locale },
|
|
124
|
+
) => Metadata | Promise<Metadata>,
|
|
125
|
+
) => {
|
|
126
|
+
return async (props: I18n.Props<TProps>): Promise<Metadata> => {
|
|
127
|
+
const { locale } = await resolveConfigurator(props);
|
|
128
|
+
const metadata = await impl({ locale, ...props });
|
|
129
|
+
return metadata;
|
|
130
|
+
};
|
|
104
131
|
},
|
|
105
132
|
default: (
|
|
106
133
|
impl: (
|
|
107
|
-
props: I18n.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
) => React.ReactNode | Promise<React.ReactNode
|
|
134
|
+
props: TProps & { locale: I18n.Locale } & React.PropsWithChildren<{
|
|
135
|
+
i18nHtmlAttrs: Pick<
|
|
136
|
+
React.ComponentPropsWithoutRef<"html">,
|
|
137
|
+
"lang" | "dir"
|
|
138
|
+
>;
|
|
139
|
+
}>,
|
|
140
|
+
) => React.ReactNode | Promise<React.ReactNode>,
|
|
114
141
|
) => {
|
|
115
142
|
return async (props: I18n.Props<TProps>) => {
|
|
116
|
-
|
|
117
|
-
const locale =
|
|
118
|
-
|
|
119
|
-
const i18nHtmlAttrs = { lang: locale, dir
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
143
|
+
const config = await resolveConfigurator(props);
|
|
144
|
+
const { locale } = config;
|
|
145
|
+
const dir = rtlLocales.includes(locale) ? "rtl" : "ltr";
|
|
146
|
+
const i18nHtmlAttrs = { lang: locale, dir };
|
|
147
|
+
const render = await impl({ locale, i18nHtmlAttrs, ...props });
|
|
148
|
+
return <I18nLayout {...config}>{render}</I18nLayout>;
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
};
|
|
126
152
|
};
|
|
127
153
|
|
|
128
154
|
createI18nLayout.Root = I18nLayoutRoot;
|
|
@@ -11,6 +11,8 @@ var m = createGenerator("next", (t)=>{
|
|
|
11
11
|
// index: true,
|
|
12
12
|
content: ()=>/* js */ `
|
|
13
13
|
import React from "react";
|
|
14
|
+
import type { Metadata } from "next/types";
|
|
15
|
+
import { rtlLocales } from "@koine/i18n";
|
|
14
16
|
// import { getI18nDictionaries } from "../getI18nDictionaries";
|
|
15
17
|
import { defaultLocale } from "../defaultLocale";
|
|
16
18
|
import { I18nTranslateProvider } from "../I18nTranslateProvider";
|
|
@@ -18,7 +20,6 @@ import { locales } from "../locales";
|
|
|
18
20
|
import type { I18n } from "../types";
|
|
19
21
|
import { getLocale } from "./getLocale";
|
|
20
22
|
import { I18nLayoutRoot } from "./I18nLayoutRoot";
|
|
21
|
-
// import { I18nNotFound } from "./I18nNotFound";
|
|
22
23
|
import { I18nLocaleContext } from "./I18nLocaleContext";
|
|
23
24
|
${getI18nDictionaries_inline(1)}
|
|
24
25
|
|
|
@@ -77,50 +78,75 @@ type Configurator = {
|
|
|
77
78
|
* @example
|
|
78
79
|
*
|
|
79
80
|
* \`\`\`
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* };
|
|
84
|
-
* };
|
|
81
|
+
* const layout = i18nServer.layout({
|
|
82
|
+
* namespaces: ["dashboard"],
|
|
83
|
+
* });
|
|
85
84
|
*
|
|
86
|
-
*
|
|
85
|
+
* // or as a function (async supported):
|
|
86
|
+
* type Props = { params: { slug: string; }; };
|
|
87
|
+
*
|
|
88
|
+
* const layout = i18nServer.layout((props: Props, locale) => {
|
|
87
89
|
* return {
|
|
88
90
|
* namespaces: ["dashboard"],
|
|
89
91
|
* };
|
|
90
92
|
* });
|
|
91
93
|
* \`\`\`
|
|
92
94
|
*/
|
|
93
|
-
export const createI18nLayout = <
|
|
94
|
-
|
|
95
|
+
export const createI18nLayout = <
|
|
96
|
+
TProps extends {},
|
|
97
|
+
>(
|
|
98
|
+
configurator?:
|
|
99
|
+
| ((
|
|
100
|
+
props: I18n.Props<TProps>,
|
|
101
|
+
locale: I18n.Locale,
|
|
102
|
+
) => Configurator | Promise<Configurator>)
|
|
103
|
+
| Configurator,
|
|
95
104
|
) => {
|
|
105
|
+
const resolveConfigurator = async (props: I18n.Props<TProps>) => {
|
|
106
|
+
const localeParam = props.params?.${e};
|
|
107
|
+
const config = configurator
|
|
108
|
+
? typeof configurator === "function"
|
|
109
|
+
? await configurator(props, localeParam)
|
|
110
|
+
: configurator
|
|
111
|
+
: null;
|
|
112
|
+
const { locale: localeConfig, ...restConfig } = config || {};
|
|
113
|
+
const locale = localeConfig || getLocale();
|
|
114
|
+
return { ...restConfig, locale };
|
|
115
|
+
};
|
|
116
|
+
|
|
96
117
|
return {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
118
|
+
generateStaticParams: () => locales.map((l) => ({ ${e}: l })),
|
|
119
|
+
generateMetadata: (
|
|
120
|
+
impl: (
|
|
121
|
+
props: TProps & { locale: I18n.Locale },
|
|
122
|
+
) => Metadata | Promise<Metadata>,
|
|
123
|
+
) => {
|
|
124
|
+
return async (props: I18n.Props<TProps>): Promise<Metadata> => {
|
|
125
|
+
const { locale } = await resolveConfigurator(props);
|
|
126
|
+
const metadata = await impl({ locale, ...props });
|
|
127
|
+
return metadata;
|
|
128
|
+
};
|
|
102
129
|
},
|
|
103
130
|
default: (
|
|
104
131
|
impl: (
|
|
105
|
-
props: I18n.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
) => React.ReactNode | Promise<React.ReactNode
|
|
132
|
+
props: TProps & { locale: I18n.Locale } & React.PropsWithChildren<{
|
|
133
|
+
i18nHtmlAttrs: Pick<
|
|
134
|
+
React.ComponentPropsWithoutRef<"html">,
|
|
135
|
+
"lang" | "dir"
|
|
136
|
+
>;
|
|
137
|
+
}>,
|
|
138
|
+
) => React.ReactNode | Promise<React.ReactNode>,
|
|
112
139
|
) => {
|
|
113
140
|
return async (props: I18n.Props<TProps>) => {
|
|
114
|
-
|
|
115
|
-
const locale =
|
|
116
|
-
|
|
117
|
-
const i18nHtmlAttrs = { lang: locale, dir
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
141
|
+
const config = await resolveConfigurator(props);
|
|
142
|
+
const { locale } = config;
|
|
143
|
+
const dir = rtlLocales.includes(locale) ? "rtl" : "ltr";
|
|
144
|
+
const i18nHtmlAttrs = { lang: locale, dir };
|
|
145
|
+
const render = await impl({ locale, i18nHtmlAttrs, ...props });
|
|
146
|
+
return <I18nLayout {...config}>{render}</I18nLayout>;
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
};
|
|
124
150
|
};
|
|
125
151
|
|
|
126
152
|
createI18nLayout.Root = I18nLayoutRoot;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var getI18nDictionaries_inline = require('../../adapter-js/generators/getI18nDictionaries_inline.cjs.js');
|
|
4
4
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
5
5
|
|
|
6
|
-
var p = createAdapter.createGenerator("next", (
|
|
7
|
-
let { config: { single:
|
|
6
|
+
var p = createAdapter.createGenerator("next", (a)=>{
|
|
7
|
+
let { config: { single: t }, options: { routes: { localeParamName: o } } } = a;
|
|
8
8
|
return {
|
|
9
9
|
I18nPage: {
|
|
10
10
|
dir: "server",
|
|
@@ -31,7 +31,7 @@ ${getI18nDictionaries_inline.getI18nDictionaries_inline(1)}
|
|
|
31
31
|
export type I18nPageProps<TRouteId extends I18n.RouteId> =
|
|
32
32
|
React.PropsWithChildren<
|
|
33
33
|
{
|
|
34
|
-
${
|
|
34
|
+
${t ? "" : `/**
|
|
35
35
|
* Optionally set this manually to override the current locale
|
|
36
36
|
*/
|
|
37
37
|
locale?: I18n.Locale;
|
|
@@ -119,7 +119,7 @@ function pageInit(paramsOrProps: I18n.Props["params"] | I18n.Props) {
|
|
|
119
119
|
const locale = (params as any).${o};
|
|
120
120
|
|
|
121
121
|
if (isLocale(locale)) {
|
|
122
|
-
${
|
|
122
|
+
${t ? "" : `
|
|
123
123
|
// set the server context based locale as early as possible, usually this
|
|
124
124
|
// function is called as first thing in the page components. Setting the
|
|
125
125
|
// locale here might help reducing the cases where a 't' function needed
|
|
@@ -127,7 +127,6 @@ function pageInit(paramsOrProps: I18n.Props["params"] | I18n.Props) {
|
|
|
127
127
|
// passing a 'locale' argument. Passing the 'locale' should not be needed
|
|
128
128
|
// actually, but...
|
|
129
129
|
I18nLocaleContext.set(locale);
|
|
130
|
-
global.__i18n_locale = locale;
|
|
131
130
|
`}return locale;
|
|
132
131
|
}
|
|
133
132
|
}
|
|
@@ -184,42 +183,85 @@ type Configurator<TRouteId extends I18n.RouteId> = {
|
|
|
184
183
|
* @example
|
|
185
184
|
*
|
|
186
185
|
* \`\`\`
|
|
187
|
-
* type Props = {
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* };
|
|
191
|
-
* };
|
|
192
|
-
*
|
|
193
|
-
* const i18nPage = i18nServer.page<Props>(async (_props, _locale) => {
|
|
186
|
+
* type Props = { params: { slug: string; }; };
|
|
187
|
+
*
|
|
188
|
+
* const page = i18nServer.page((props: Props) => {
|
|
194
189
|
* return {
|
|
195
|
-
* route: { id: "
|
|
196
|
-
* namespaces: ["~
|
|
190
|
+
* route: { id: "collection.[slug]", params: { slug: props.params.slug } },
|
|
191
|
+
* namespaces: ["~collection-single"],
|
|
197
192
|
* };
|
|
198
193
|
* });
|
|
194
|
+
*
|
|
195
|
+
* export const generateMetadata = page.generateMetadata((props) => {
|
|
196
|
+
* return {};
|
|
197
|
+
* });
|
|
198
|
+
*
|
|
199
|
+
* // or async:
|
|
200
|
+
* export const generateMetadata = page.generateMetadata(async (props) => {
|
|
201
|
+
* return {};
|
|
202
|
+
* });
|
|
203
|
+
*
|
|
204
|
+
* export default page.default((props) => {
|
|
205
|
+
* return <>{props.route.id} {props.locale}</>;
|
|
206
|
+
* });
|
|
207
|
+
*
|
|
208
|
+
* // or async:
|
|
209
|
+
* export default page.default(async (props) => {
|
|
210
|
+
* const data = await fetch(...);
|
|
211
|
+
* return <>{props.route.id} {props.locale}</>;
|
|
212
|
+
* });
|
|
199
213
|
* \`\`\`
|
|
200
|
-
* @returns
|
|
201
214
|
*/
|
|
202
|
-
export const createI18nPage = <
|
|
203
|
-
|
|
215
|
+
export const createI18nPage = <
|
|
216
|
+
TProps extends {},
|
|
217
|
+
TRouteId extends I18n.RouteId,
|
|
218
|
+
TConfig extends Configurator<TRouteId>,
|
|
219
|
+
>(
|
|
220
|
+
configurator: (
|
|
221
|
+
props: I18n.Props<TProps>,
|
|
222
|
+
locale: I18n.Locale,
|
|
223
|
+
) => TConfig | Promise<TConfig>,
|
|
204
224
|
) => {
|
|
205
225
|
return {
|
|
206
|
-
generateMetadata: (
|
|
207
|
-
|
|
226
|
+
generateMetadata: (
|
|
227
|
+
impl: (
|
|
228
|
+
props: TProps &
|
|
229
|
+
Omit<TConfig, "namespaces"> & {
|
|
230
|
+
locale: I18n.Locale;
|
|
231
|
+
},
|
|
232
|
+
) => Metadata | Promise<Metadata>,
|
|
233
|
+
) => {
|
|
234
|
+
return async (props: I18n.Props<TProps>): Promise<Metadata> => {
|
|
208
235
|
const locale = pageInit(props);
|
|
209
|
-
const {
|
|
210
|
-
const
|
|
211
|
-
return getMetadata({ ...route, locale },
|
|
236
|
+
const { namespaces, ...config } = await configurator(props, locale);
|
|
237
|
+
const metadata = await impl({ locale, ...config, ...props });
|
|
238
|
+
return getMetadata({ ...config.route, locale }, metadata);
|
|
212
239
|
};
|
|
213
240
|
},
|
|
214
|
-
default: (
|
|
215
|
-
|
|
241
|
+
default: (
|
|
242
|
+
impl: (
|
|
243
|
+
props: TProps &
|
|
244
|
+
Omit<TConfig, "namespaces"> & {
|
|
245
|
+
locale: I18n.Locale;
|
|
246
|
+
},
|
|
247
|
+
) => React.ReactNode | Promise<React.ReactNode>,
|
|
248
|
+
) => {
|
|
249
|
+
return async (props: I18n.Props<TProps>) => {
|
|
216
250
|
const locale = pageInit(props);
|
|
217
|
-
const {
|
|
218
|
-
const render = await impl(
|
|
219
|
-
return (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
251
|
+
const { namespaces, ...config } = await configurator(props, locale);
|
|
252
|
+
const render = await impl({ locale, ...config, ...props });
|
|
253
|
+
return (
|
|
254
|
+
<I18nPage
|
|
255
|
+
locale={locale}
|
|
256
|
+
namespaces={namespaces}
|
|
257
|
+
route={config.route}
|
|
258
|
+
>
|
|
259
|
+
{render}
|
|
260
|
+
</I18nPage>
|
|
261
|
+
);
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
};
|
|
223
265
|
};
|
|
224
266
|
|
|
225
267
|
export default I18nPage;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getI18nDictionaries_inline } from '../../adapter-js/generators/getI18nDictionaries_inline.esm.js';
|
|
2
2
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
3
3
|
|
|
4
|
-
var p = createGenerator("next", (
|
|
5
|
-
let { config: { single:
|
|
4
|
+
var p = createGenerator("next", (a)=>{
|
|
5
|
+
let { config: { single: t }, options: { routes: { localeParamName: o } } } = a;
|
|
6
6
|
return {
|
|
7
7
|
I18nPage: {
|
|
8
8
|
dir: "server",
|
|
@@ -29,7 +29,7 @@ ${getI18nDictionaries_inline(1)}
|
|
|
29
29
|
export type I18nPageProps<TRouteId extends I18n.RouteId> =
|
|
30
30
|
React.PropsWithChildren<
|
|
31
31
|
{
|
|
32
|
-
${
|
|
32
|
+
${t ? "" : `/**
|
|
33
33
|
* Optionally set this manually to override the current locale
|
|
34
34
|
*/
|
|
35
35
|
locale?: I18n.Locale;
|
|
@@ -117,7 +117,7 @@ function pageInit(paramsOrProps: I18n.Props["params"] | I18n.Props) {
|
|
|
117
117
|
const locale = (params as any).${o};
|
|
118
118
|
|
|
119
119
|
if (isLocale(locale)) {
|
|
120
|
-
${
|
|
120
|
+
${t ? "" : `
|
|
121
121
|
// set the server context based locale as early as possible, usually this
|
|
122
122
|
// function is called as first thing in the page components. Setting the
|
|
123
123
|
// locale here might help reducing the cases where a 't' function needed
|
|
@@ -125,7 +125,6 @@ function pageInit(paramsOrProps: I18n.Props["params"] | I18n.Props) {
|
|
|
125
125
|
// passing a 'locale' argument. Passing the 'locale' should not be needed
|
|
126
126
|
// actually, but...
|
|
127
127
|
I18nLocaleContext.set(locale);
|
|
128
|
-
global.__i18n_locale = locale;
|
|
129
128
|
`}return locale;
|
|
130
129
|
}
|
|
131
130
|
}
|
|
@@ -182,42 +181,85 @@ type Configurator<TRouteId extends I18n.RouteId> = {
|
|
|
182
181
|
* @example
|
|
183
182
|
*
|
|
184
183
|
* \`\`\`
|
|
185
|
-
* type Props = {
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* };
|
|
189
|
-
* };
|
|
190
|
-
*
|
|
191
|
-
* const i18nPage = i18nServer.page<Props>(async (_props, _locale) => {
|
|
184
|
+
* type Props = { params: { slug: string; }; };
|
|
185
|
+
*
|
|
186
|
+
* const page = i18nServer.page((props: Props) => {
|
|
192
187
|
* return {
|
|
193
|
-
* route: { id: "
|
|
194
|
-
* namespaces: ["~
|
|
188
|
+
* route: { id: "collection.[slug]", params: { slug: props.params.slug } },
|
|
189
|
+
* namespaces: ["~collection-single"],
|
|
195
190
|
* };
|
|
196
191
|
* });
|
|
192
|
+
*
|
|
193
|
+
* export const generateMetadata = page.generateMetadata((props) => {
|
|
194
|
+
* return {};
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* // or async:
|
|
198
|
+
* export const generateMetadata = page.generateMetadata(async (props) => {
|
|
199
|
+
* return {};
|
|
200
|
+
* });
|
|
201
|
+
*
|
|
202
|
+
* export default page.default((props) => {
|
|
203
|
+
* return <>{props.route.id} {props.locale}</>;
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* // or async:
|
|
207
|
+
* export default page.default(async (props) => {
|
|
208
|
+
* const data = await fetch(...);
|
|
209
|
+
* return <>{props.route.id} {props.locale}</>;
|
|
210
|
+
* });
|
|
197
211
|
* \`\`\`
|
|
198
|
-
* @returns
|
|
199
212
|
*/
|
|
200
|
-
export const createI18nPage = <
|
|
201
|
-
|
|
213
|
+
export const createI18nPage = <
|
|
214
|
+
TProps extends {},
|
|
215
|
+
TRouteId extends I18n.RouteId,
|
|
216
|
+
TConfig extends Configurator<TRouteId>,
|
|
217
|
+
>(
|
|
218
|
+
configurator: (
|
|
219
|
+
props: I18n.Props<TProps>,
|
|
220
|
+
locale: I18n.Locale,
|
|
221
|
+
) => TConfig | Promise<TConfig>,
|
|
202
222
|
) => {
|
|
203
223
|
return {
|
|
204
|
-
generateMetadata: (
|
|
205
|
-
|
|
224
|
+
generateMetadata: (
|
|
225
|
+
impl: (
|
|
226
|
+
props: TProps &
|
|
227
|
+
Omit<TConfig, "namespaces"> & {
|
|
228
|
+
locale: I18n.Locale;
|
|
229
|
+
},
|
|
230
|
+
) => Metadata | Promise<Metadata>,
|
|
231
|
+
) => {
|
|
232
|
+
return async (props: I18n.Props<TProps>): Promise<Metadata> => {
|
|
206
233
|
const locale = pageInit(props);
|
|
207
|
-
const {
|
|
208
|
-
const
|
|
209
|
-
return getMetadata({ ...route, locale },
|
|
234
|
+
const { namespaces, ...config } = await configurator(props, locale);
|
|
235
|
+
const metadata = await impl({ locale, ...config, ...props });
|
|
236
|
+
return getMetadata({ ...config.route, locale }, metadata);
|
|
210
237
|
};
|
|
211
238
|
},
|
|
212
|
-
default: (
|
|
213
|
-
|
|
239
|
+
default: (
|
|
240
|
+
impl: (
|
|
241
|
+
props: TProps &
|
|
242
|
+
Omit<TConfig, "namespaces"> & {
|
|
243
|
+
locale: I18n.Locale;
|
|
244
|
+
},
|
|
245
|
+
) => React.ReactNode | Promise<React.ReactNode>,
|
|
246
|
+
) => {
|
|
247
|
+
return async (props: I18n.Props<TProps>) => {
|
|
214
248
|
const locale = pageInit(props);
|
|
215
|
-
const {
|
|
216
|
-
const render = await impl(
|
|
217
|
-
return (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
249
|
+
const { namespaces, ...config } = await configurator(props, locale);
|
|
250
|
+
const render = await impl({ locale, ...config, ...props });
|
|
251
|
+
return (
|
|
252
|
+
<I18nPage
|
|
253
|
+
locale={locale}
|
|
254
|
+
namespaces={namespaces}
|
|
255
|
+
route={config.route}
|
|
256
|
+
>
|
|
257
|
+
{render}
|
|
258
|
+
</I18nPage>
|
|
259
|
+
);
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
};
|
|
221
263
|
};
|
|
222
264
|
|
|
223
265
|
export default I18nPage;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var utils = require('@koine/utils');
|
|
4
|
-
var formatRoutePathname = require('../
|
|
4
|
+
var formatRoutePathname = require('../formatRoutePathname.cjs.js');
|
|
5
5
|
var transformPathname = require('./transformPathname.cjs.js');
|
|
6
6
|
|
|
7
7
|
function a(e) {
|
|
8
|
-
let { localeSource: t, localeDestination:
|
|
8
|
+
let { localeSource: t, localeDestination: r, template: a, pathname: l, permanent: n } = e, i = formatRoutePathname.formatRoutePathname((t ? `${t}/` : "") + a), c = formatRoutePathname.formatRoutePathname((r ? `${r}/` : "") + l);
|
|
9
9
|
// console.log(`redirect template "${source}" to pathname "${destination}"`);
|
|
10
10
|
if (i !== c) return {
|
|
11
11
|
source: i,
|
|
@@ -13,10 +13,10 @@ function a(e) {
|
|
|
13
13
|
permanent: !!n
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
function generateRedirectForPathname(e, t,
|
|
16
|
+
function generateRedirectForPathname(e, t, o, r, l) {
|
|
17
17
|
let { defaultLocale: n, hideDefaultLocaleInUrl: i, localeParamName: c, permanentRedirects: s } = e, p = t === n, u = p && !i, m = {
|
|
18
|
-
template:
|
|
19
|
-
pathname:
|
|
18
|
+
template: o,
|
|
19
|
+
pathname: r,
|
|
20
20
|
permanent: s
|
|
21
21
|
};
|
|
22
22
|
c ? // app router:
|
|
@@ -31,7 +31,7 @@ function generateRedirectForPathname(e, t, r, o, l) {
|
|
|
31
31
|
localeSource: t,
|
|
32
32
|
localeDestination: t
|
|
33
33
|
})) : // pages router:
|
|
34
|
-
|
|
34
|
+
r !== o && (u ? l.push(a({
|
|
35
35
|
...m,
|
|
36
36
|
localeDestination: t
|
|
37
37
|
})) : p ? l.push(a(m)) : l.push(a({
|
|
@@ -46,16 +46,16 @@ function generateRedirectForPathname(e, t, r, o, l) {
|
|
|
46
46
|
* @see
|
|
47
47
|
* - https://nextjs.org/docs/pages/api-reference/next-config-js/redirects
|
|
48
48
|
* - https://vercel.com/docs/projects/project-configuration#redirects
|
|
49
|
-
*/ let generateRedirects = (
|
|
49
|
+
*/ let generateRedirects = (o, { localeParamName: a, permanentRedirects: l, tokens: n }, i)=>{
|
|
50
50
|
let c = {
|
|
51
|
-
...
|
|
51
|
+
...o,
|
|
52
52
|
localeParamName: a,
|
|
53
53
|
permanentRedirects: l
|
|
54
54
|
}, s = RegExp(utils.escapeRegExp(n.idDelimiter), "g"), p = [];
|
|
55
55
|
for(let e in i){
|
|
56
|
-
let t = i[e],
|
|
57
|
-
for(let a in
|
|
58
|
-
let l =
|
|
56
|
+
let t = i[e], o = i[e].pathnames;
|
|
57
|
+
for(let a in o){
|
|
58
|
+
let l = o[a], // prettier-ignore
|
|
59
59
|
n = transformPathname.transformPathname(e.replace(s, "/"), t.wildcard), i = transformPathname.transformPathname(l, t.wildcard);
|
|
60
60
|
// we do not redirect urls children of wildcard urls
|
|
61
61
|
if (t.inWildcard) break;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { escapeRegExp, arrayUniqueByProperties } from '@koine/utils';
|
|
2
|
-
import { formatRoutePathname } from '../
|
|
2
|
+
import { formatRoutePathname } from '../formatRoutePathname.esm.js';
|
|
3
3
|
import { transformPathname } from './transformPathname.esm.js';
|
|
4
4
|
|
|
5
5
|
function a(e) {
|
|
6
|
-
let { localeSource: t, localeDestination:
|
|
6
|
+
let { localeSource: t, localeDestination: r, template: a, pathname: l, permanent: n } = e, i = formatRoutePathname((t ? `${t}/` : "") + a), c = formatRoutePathname((r ? `${r}/` : "") + l);
|
|
7
7
|
// console.log(`redirect template "${source}" to pathname "${destination}"`);
|
|
8
8
|
if (i !== c) return {
|
|
9
9
|
source: i,
|
|
@@ -11,10 +11,10 @@ function a(e) {
|
|
|
11
11
|
permanent: !!n
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
function generateRedirectForPathname(e, t,
|
|
14
|
+
function generateRedirectForPathname(e, t, o, r, l) {
|
|
15
15
|
let { defaultLocale: n, hideDefaultLocaleInUrl: i, localeParamName: c, permanentRedirects: s } = e, p = t === n, u = p && !i, m = {
|
|
16
|
-
template:
|
|
17
|
-
pathname:
|
|
16
|
+
template: o,
|
|
17
|
+
pathname: r,
|
|
18
18
|
permanent: s
|
|
19
19
|
};
|
|
20
20
|
c ? // app router:
|
|
@@ -29,7 +29,7 @@ function generateRedirectForPathname(e, t, r, o, l) {
|
|
|
29
29
|
localeSource: t,
|
|
30
30
|
localeDestination: t
|
|
31
31
|
})) : // pages router:
|
|
32
|
-
|
|
32
|
+
r !== o && (u ? l.push(a({
|
|
33
33
|
...m,
|
|
34
34
|
localeDestination: t
|
|
35
35
|
})) : p ? l.push(a(m)) : l.push(a({
|
|
@@ -44,16 +44,16 @@ function generateRedirectForPathname(e, t, r, o, l) {
|
|
|
44
44
|
* @see
|
|
45
45
|
* - https://nextjs.org/docs/pages/api-reference/next-config-js/redirects
|
|
46
46
|
* - https://vercel.com/docs/projects/project-configuration#redirects
|
|
47
|
-
*/ let generateRedirects = (
|
|
47
|
+
*/ let generateRedirects = (o, { localeParamName: a, permanentRedirects: l, tokens: n }, i)=>{
|
|
48
48
|
let c = {
|
|
49
|
-
...
|
|
49
|
+
...o,
|
|
50
50
|
localeParamName: a,
|
|
51
51
|
permanentRedirects: l
|
|
52
52
|
}, s = RegExp(escapeRegExp(n.idDelimiter), "g"), p = [];
|
|
53
53
|
for(let e in i){
|
|
54
|
-
let t = i[e],
|
|
55
|
-
for(let a in
|
|
56
|
-
let l =
|
|
54
|
+
let t = i[e], o = i[e].pathnames;
|
|
55
|
+
for(let a in o){
|
|
56
|
+
let l = o[a], // prettier-ignore
|
|
57
57
|
n = transformPathname(e.replace(s, "/"), t.wildcard), i = transformPathname(l, t.wildcard);
|
|
58
58
|
// we do not redirect urls children of wildcard urls
|
|
59
59
|
if (t.inWildcard) break;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var utils = require('@koine/utils');
|
|
4
|
-
var formatRoutePathname = require('../
|
|
4
|
+
var formatRoutePathname = require('../formatRoutePathname.cjs.js');
|
|
5
5
|
var transformPathname = require('./transformPathname.cjs.js');
|
|
6
6
|
|
|
7
7
|
function o(e) {
|
|
8
8
|
let { localeSource: t, localeDestination: a, template: o, pathname: l, passLocale: i } = e, n = "";
|
|
9
9
|
t && (n = `/${t}`);
|
|
10
|
-
let
|
|
11
|
-
a && (
|
|
12
|
-
let
|
|
10
|
+
let s = formatRoutePathname.formatRoutePathname(n + l), c = "";
|
|
11
|
+
a && (c = `/${a}`);
|
|
12
|
+
let m = formatRoutePathname.formatRoutePathname(c + o);
|
|
13
13
|
// console.log(`rewrite pathname "${source}" to template "${destination}"`);
|
|
14
|
-
if (
|
|
15
|
-
let
|
|
16
|
-
source:
|
|
17
|
-
destination:
|
|
14
|
+
if (s === m) return;
|
|
15
|
+
let p = {
|
|
16
|
+
source: s,
|
|
17
|
+
destination: m
|
|
18
18
|
};
|
|
19
|
-
return !1 === i && (
|
|
19
|
+
return !1 === i && (p.locale = !1), p;
|
|
20
20
|
}
|
|
21
21
|
const generateRewriteForPathname = (e, t, r, a, l)=>{
|
|
22
|
-
let { defaultLocale: i, hideDefaultLocaleInUrl: n, localeParamName:
|
|
23
|
-
|
|
22
|
+
let { defaultLocale: i, hideDefaultLocaleInUrl: n, localeParamName: s } = e, c = t === i && n, // TODO: maybe support other locales to be hidden in the URL other than the default?
|
|
23
|
+
m = {
|
|
24
24
|
template: r,
|
|
25
25
|
pathname: a
|
|
26
26
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
...
|
|
27
|
+
s ? // app router:
|
|
28
|
+
c ? l.push(o({
|
|
29
|
+
...m,
|
|
30
30
|
localeDestination: t,
|
|
31
31
|
passLocale: !1
|
|
32
32
|
})) : l.push(// prettier-ignore
|
|
33
33
|
o({
|
|
34
|
-
...
|
|
34
|
+
...m,
|
|
35
35
|
localeSource: t,
|
|
36
36
|
localeDestination: t,
|
|
37
37
|
passLocale: !1
|
|
@@ -39,13 +39,13 @@ const generateRewriteForPathname = (e, t, r, a, l)=>{
|
|
|
39
39
|
// this condition only applies to the pages router as with the app one
|
|
40
40
|
// even if the template matches the pathname we always need to rewrite
|
|
41
41
|
// as the localeParam is always needed in the rewrite destination
|
|
42
|
-
a !== r && (
|
|
42
|
+
a !== r && (c ? l.push(o(m)) : l.push(// `passLocale` must be `false` or the locale prefixed rewrite won't
|
|
43
43
|
// be applied and does not forward the locale to the route context
|
|
44
44
|
// when the locale is included in the URL. In fact we explicitly
|
|
45
45
|
// add the locale to the rewrite rule in order to get the least
|
|
46
46
|
// amount of existing URLs which is a good SEO practice
|
|
47
47
|
o({
|
|
48
|
-
...
|
|
48
|
+
...m,
|
|
49
49
|
localeSource: t,
|
|
50
50
|
passLocale: !1
|
|
51
51
|
})));
|
|
@@ -57,27 +57,27 @@ const generateRewriteForPathname = (e, t, r, a, l)=>{
|
|
|
57
57
|
* - https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites
|
|
58
58
|
* - https://vercel.com/docs/projects/project-configuration#rewrites
|
|
59
59
|
*/ let generateRewrites = (r, { tokens: o, localeParamName: l, permanentRedirects: i }, n)=>{
|
|
60
|
-
let
|
|
60
|
+
let s = {
|
|
61
61
|
...r,
|
|
62
62
|
localeParamName: l,
|
|
63
63
|
permanentRedirects: i
|
|
64
|
-
},
|
|
64
|
+
}, c = RegExp(utils.escapeRegExp(o.idDelimiter), "g"), m = [];
|
|
65
65
|
for(let e in n){
|
|
66
66
|
let t = n[e], r = n[e].pathnames;
|
|
67
67
|
for(let o in r){
|
|
68
|
-
let l = r[o], i = e.replace(
|
|
68
|
+
let l = r[o], i = e.replace(c, "/");
|
|
69
69
|
// we do not rewrite urls children of wildcard urls
|
|
70
70
|
if (t.inWildcard) break;
|
|
71
71
|
// we need to rewrite both the root path...
|
|
72
|
-
generateRewriteForPathname(
|
|
73
|
-
generateRewriteForPathname(
|
|
72
|
+
generateRewriteForPathname(s, o, transformPathname.transformPathname(i), transformPathname.transformPathname(l), m), t.wildcard && // and for wildcard routes the ones with the `/:segment*` portion
|
|
73
|
+
generateRewriteForPathname(s, o, transformPathname.transformPathname(i, t.wildcard), transformPathname.transformPathname(l, t.wildcard), m);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
// simple sort by destination:
|
|
77
77
|
// return a.destination.localeCompare(b.destination);
|
|
78
78
|
// sort by locale
|
|
79
79
|
// return a.
|
|
80
|
-
return utils.arrayUniqueByProperties(
|
|
80
|
+
return utils.arrayUniqueByProperties(m.filter(Boolean), [
|
|
81
81
|
"source",
|
|
82
82
|
"destination"
|
|
83
83
|
]).sort((e, t)=>// simple sort by source:
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { escapeRegExp, arrayUniqueByProperties } from '@koine/utils';
|
|
2
|
-
import { formatRoutePathname } from '../
|
|
2
|
+
import { formatRoutePathname } from '../formatRoutePathname.esm.js';
|
|
3
3
|
import { transformPathname } from './transformPathname.esm.js';
|
|
4
4
|
|
|
5
5
|
function o(e) {
|
|
6
6
|
let { localeSource: t, localeDestination: a, template: o, pathname: l, passLocale: i } = e, n = "";
|
|
7
7
|
t && (n = `/${t}`);
|
|
8
|
-
let
|
|
9
|
-
a && (
|
|
10
|
-
let
|
|
8
|
+
let s = formatRoutePathname(n + l), c = "";
|
|
9
|
+
a && (c = `/${a}`);
|
|
10
|
+
let m = formatRoutePathname(c + o);
|
|
11
11
|
// console.log(`rewrite pathname "${source}" to template "${destination}"`);
|
|
12
|
-
if (
|
|
13
|
-
let
|
|
14
|
-
source:
|
|
15
|
-
destination:
|
|
12
|
+
if (s === m) return;
|
|
13
|
+
let p = {
|
|
14
|
+
source: s,
|
|
15
|
+
destination: m
|
|
16
16
|
};
|
|
17
|
-
return !1 === i && (
|
|
17
|
+
return !1 === i && (p.locale = !1), p;
|
|
18
18
|
}
|
|
19
19
|
const generateRewriteForPathname = (e, t, r, a, l)=>{
|
|
20
|
-
let { defaultLocale: i, hideDefaultLocaleInUrl: n, localeParamName:
|
|
21
|
-
|
|
20
|
+
let { defaultLocale: i, hideDefaultLocaleInUrl: n, localeParamName: s } = e, c = t === i && n, // TODO: maybe support other locales to be hidden in the URL other than the default?
|
|
21
|
+
m = {
|
|
22
22
|
template: r,
|
|
23
23
|
pathname: a
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...
|
|
25
|
+
s ? // app router:
|
|
26
|
+
c ? l.push(o({
|
|
27
|
+
...m,
|
|
28
28
|
localeDestination: t,
|
|
29
29
|
passLocale: !1
|
|
30
30
|
})) : l.push(// prettier-ignore
|
|
31
31
|
o({
|
|
32
|
-
...
|
|
32
|
+
...m,
|
|
33
33
|
localeSource: t,
|
|
34
34
|
localeDestination: t,
|
|
35
35
|
passLocale: !1
|
|
@@ -37,13 +37,13 @@ const generateRewriteForPathname = (e, t, r, a, l)=>{
|
|
|
37
37
|
// this condition only applies to the pages router as with the app one
|
|
38
38
|
// even if the template matches the pathname we always need to rewrite
|
|
39
39
|
// as the localeParam is always needed in the rewrite destination
|
|
40
|
-
a !== r && (
|
|
40
|
+
a !== r && (c ? l.push(o(m)) : l.push(// `passLocale` must be `false` or the locale prefixed rewrite won't
|
|
41
41
|
// be applied and does not forward the locale to the route context
|
|
42
42
|
// when the locale is included in the URL. In fact we explicitly
|
|
43
43
|
// add the locale to the rewrite rule in order to get the least
|
|
44
44
|
// amount of existing URLs which is a good SEO practice
|
|
45
45
|
o({
|
|
46
|
-
...
|
|
46
|
+
...m,
|
|
47
47
|
localeSource: t,
|
|
48
48
|
passLocale: !1
|
|
49
49
|
})));
|
|
@@ -55,27 +55,27 @@ const generateRewriteForPathname = (e, t, r, a, l)=>{
|
|
|
55
55
|
* - https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites
|
|
56
56
|
* - https://vercel.com/docs/projects/project-configuration#rewrites
|
|
57
57
|
*/ let generateRewrites = (r, { tokens: o, localeParamName: l, permanentRedirects: i }, n)=>{
|
|
58
|
-
let
|
|
58
|
+
let s = {
|
|
59
59
|
...r,
|
|
60
60
|
localeParamName: l,
|
|
61
61
|
permanentRedirects: i
|
|
62
|
-
},
|
|
62
|
+
}, c = RegExp(escapeRegExp(o.idDelimiter), "g"), m = [];
|
|
63
63
|
for(let e in n){
|
|
64
64
|
let t = n[e], r = n[e].pathnames;
|
|
65
65
|
for(let o in r){
|
|
66
|
-
let l = r[o], i = e.replace(
|
|
66
|
+
let l = r[o], i = e.replace(c, "/");
|
|
67
67
|
// we do not rewrite urls children of wildcard urls
|
|
68
68
|
if (t.inWildcard) break;
|
|
69
69
|
// we need to rewrite both the root path...
|
|
70
|
-
generateRewriteForPathname(
|
|
71
|
-
generateRewriteForPathname(
|
|
70
|
+
generateRewriteForPathname(s, o, transformPathname(i), transformPathname(l), m), t.wildcard && // and for wildcard routes the ones with the `/:segment*` portion
|
|
71
|
+
generateRewriteForPathname(s, o, transformPathname(i, t.wildcard), transformPathname(l, t.wildcard), m);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
// simple sort by destination:
|
|
75
75
|
// return a.destination.localeCompare(b.destination);
|
|
76
76
|
// sort by locale
|
|
77
77
|
// return a.
|
|
78
|
-
return arrayUniqueByProperties(
|
|
78
|
+
return arrayUniqueByProperties(m.filter(Boolean), [
|
|
79
79
|
"source",
|
|
80
80
|
"destination"
|
|
81
81
|
]).sort((e, t)=>// simple sort by source:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { escapeRegExp, objectSortByKeysMatching, objectFlat, objectSort } from '@koine/utils';
|
|
2
|
-
import { formatRoutePathname } from '../../
|
|
2
|
+
import { formatRoutePathname } from '../../formatRoutePathname.esm.js';
|
|
3
3
|
|
|
4
4
|
const codeDataRoutesOptions = {
|
|
5
5
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./formatRoutePathname.cjs.js').default;
|
package/index.cjs.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var formatRoutePathname = require('./
|
|
4
|
-
var interpolateTo = require('./
|
|
5
|
-
var
|
|
3
|
+
var formatRoutePathname = require('./formatRoutePathname.cjs.js');
|
|
4
|
+
var interpolateTo = require('./interpolateTo.cjs.js');
|
|
5
|
+
var rtlLocales = require('./rtlLocales.cjs.js');
|
|
6
|
+
var routeHasDynamicPortion = require('./routeHasDynamicPortion.cjs.js');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
exports.formatRoutePathname = formatRoutePathname.formatRoutePathname;
|
|
10
11
|
exports.interpolateTo = interpolateTo.interpolateTo;
|
|
12
|
+
exports.rtlLocales = rtlLocales.rtlLocales;
|
|
11
13
|
exports.routeHasDynamicPortion = routeHasDynamicPortion.routeHasDynamicPortion;
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { formatRoutePathname } from "./formatRoutePathname";
|
|
2
|
+
export { interpolateTo } from "./interpolateTo";
|
|
3
|
+
export { rtlLocales } from "./rtlLocales";
|
|
4
|
+
export { routeHasDynamicPortion } from "./routeHasDynamicPortion";
|
|
2
5
|
export * from "./types";
|
package/index.esm.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { formatRoutePathname } from './
|
|
2
|
-
export { interpolateTo } from './
|
|
3
|
-
export {
|
|
1
|
+
export { formatRoutePathname } from './formatRoutePathname.esm.js';
|
|
2
|
+
export { interpolateTo } from './interpolateTo.esm.js';
|
|
3
|
+
export { rtlLocales } from './rtlLocales.esm.js';
|
|
4
|
+
export { routeHasDynamicPortion } from './routeHasDynamicPortion.esm.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./interpolateTo.cjs.js').default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { I18nUtils } from "
|
|
1
|
+
import type { I18nUtils } from "./types";
|
|
2
2
|
export declare function interpolateTo<TRouteId extends string>(value: TRouteId): string;
|
|
3
3
|
export declare function interpolateTo<TRouteId extends string>(value: TRouteId, params: I18nUtils.DynamicParams<TRouteId>): string;
|
|
4
4
|
export default interpolateTo;
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@koine/i18n",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@koine/node": "2.0.0-beta.
|
|
6
|
-
"@koine/utils": "2.0.0-beta.
|
|
5
|
+
"@koine/node": "2.0.0-beta.129",
|
|
6
|
+
"@koine/utils": "2.0.0-beta.129",
|
|
7
7
|
"glob": "^10.3.10",
|
|
8
8
|
"minimatch": "^9.0.3",
|
|
9
9
|
"negotiator": "^0.6.3",
|
|
@@ -37,6 +37,30 @@
|
|
|
37
37
|
"import": "./index.cjs.mjs",
|
|
38
38
|
"default": "./index.cjs.js"
|
|
39
39
|
},
|
|
40
|
+
"./formatRoutePathname": {
|
|
41
|
+
"module": "./formatRoutePathname.esm.js",
|
|
42
|
+
"types": "./formatRoutePathname.esm.d.ts",
|
|
43
|
+
"import": "./formatRoutePathname.cjs.mjs",
|
|
44
|
+
"default": "./formatRoutePathname.cjs.js"
|
|
45
|
+
},
|
|
46
|
+
"./interpolateTo": {
|
|
47
|
+
"module": "./interpolateTo.esm.js",
|
|
48
|
+
"types": "./interpolateTo.esm.d.ts",
|
|
49
|
+
"import": "./interpolateTo.cjs.mjs",
|
|
50
|
+
"default": "./interpolateTo.cjs.js"
|
|
51
|
+
},
|
|
52
|
+
"./routeHasDynamicPortion": {
|
|
53
|
+
"module": "./routeHasDynamicPortion.esm.js",
|
|
54
|
+
"types": "./routeHasDynamicPortion.esm.d.ts",
|
|
55
|
+
"import": "./routeHasDynamicPortion.cjs.mjs",
|
|
56
|
+
"default": "./routeHasDynamicPortion.cjs.js"
|
|
57
|
+
},
|
|
58
|
+
"./rtlLocales": {
|
|
59
|
+
"module": "./rtlLocales.esm.js",
|
|
60
|
+
"types": "./rtlLocales.esm.d.ts",
|
|
61
|
+
"import": "./rtlLocales.cjs.mjs",
|
|
62
|
+
"default": "./rtlLocales.cjs.js"
|
|
63
|
+
},
|
|
40
64
|
"./compiler": {
|
|
41
65
|
"module": "./compiler.esm.js",
|
|
42
66
|
"types": "./compiler.esm.d.ts",
|
|
@@ -65,5 +89,5 @@
|
|
|
65
89
|
"module": "./index.esm.js",
|
|
66
90
|
"main": "./index.cjs.js",
|
|
67
91
|
"types": "./index.esm.d.ts",
|
|
68
|
-
"version": "2.0.0-beta.
|
|
92
|
+
"version": "2.0.0-beta.129"
|
|
69
93
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./routeHasDynamicPortion.cjs.js').default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./rtlLocales.cjs.js').default;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* List of Right-to-left language codes
|
|
7
|
+
*
|
|
8
|
+
* @borrows [shadiabuhilal/rtl-detect](https://github.com/shadiabuhilal/rtl-detect)
|
|
9
|
+
* @see https://en.wikipedia.org/wiki/Right-to-left_script
|
|
10
|
+
* @see https://en.wikipedia.org/wiki/Script_(Unicode)
|
|
11
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
|
|
12
|
+
*/ let rtlLocales = [
|
|
13
|
+
"ae",
|
|
14
|
+
// Avestan
|
|
15
|
+
"ar",
|
|
16
|
+
// 'العربية', Arabic
|
|
17
|
+
"arc",
|
|
18
|
+
// Aramaic
|
|
19
|
+
"bcc",
|
|
20
|
+
// 'بلوچی مکرانی', Southern Balochi
|
|
21
|
+
"bqi",
|
|
22
|
+
// 'بختياري', Bakthiari
|
|
23
|
+
"ckb",
|
|
24
|
+
// 'Soranî / کوردی', Sorani
|
|
25
|
+
"dv",
|
|
26
|
+
// Dhivehi
|
|
27
|
+
"fa",
|
|
28
|
+
// 'فارسی', Persian
|
|
29
|
+
"glk",
|
|
30
|
+
// 'گیلکی', Gilaki
|
|
31
|
+
"he",
|
|
32
|
+
// 'עברית', Hebrew
|
|
33
|
+
"ku",
|
|
34
|
+
// 'Kurdî / كوردی', Kurdish
|
|
35
|
+
"mzn",
|
|
36
|
+
// 'مازِرونی', Mazanderani
|
|
37
|
+
"nqo",
|
|
38
|
+
// N'Ko
|
|
39
|
+
"pnb",
|
|
40
|
+
// 'پنجابی', Western Punjabi
|
|
41
|
+
"prs",
|
|
42
|
+
// 'دری', Darī
|
|
43
|
+
"ps",
|
|
44
|
+
// 'پښتو', Pashto,
|
|
45
|
+
"sd",
|
|
46
|
+
// 'سنڌي', Sindhi
|
|
47
|
+
"ug",
|
|
48
|
+
// 'Uyghurche / ئۇيغۇرچە', Uyghur
|
|
49
|
+
"ur",
|
|
50
|
+
// 'اردو', Urdu
|
|
51
|
+
"yi"
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
exports.default = rtlLocales;
|
|
55
|
+
exports.rtlLocales = rtlLocales;
|
package/rtlLocales.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of Right-to-left language codes
|
|
3
|
+
*
|
|
4
|
+
* @borrows [shadiabuhilal/rtl-detect](https://github.com/shadiabuhilal/rtl-detect)
|
|
5
|
+
* @see https://en.wikipedia.org/wiki/Right-to-left_script
|
|
6
|
+
* @see https://en.wikipedia.org/wiki/Script_(Unicode)
|
|
7
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
|
|
8
|
+
*/ let rtlLocales = [
|
|
9
|
+
"ae",
|
|
10
|
+
// Avestan
|
|
11
|
+
"ar",
|
|
12
|
+
// 'العربية', Arabic
|
|
13
|
+
"arc",
|
|
14
|
+
// Aramaic
|
|
15
|
+
"bcc",
|
|
16
|
+
// 'بلوچی مکرانی', Southern Balochi
|
|
17
|
+
"bqi",
|
|
18
|
+
// 'بختياري', Bakthiari
|
|
19
|
+
"ckb",
|
|
20
|
+
// 'Soranî / کوردی', Sorani
|
|
21
|
+
"dv",
|
|
22
|
+
// Dhivehi
|
|
23
|
+
"fa",
|
|
24
|
+
// 'فارسی', Persian
|
|
25
|
+
"glk",
|
|
26
|
+
// 'گیلکی', Gilaki
|
|
27
|
+
"he",
|
|
28
|
+
// 'עברית', Hebrew
|
|
29
|
+
"ku",
|
|
30
|
+
// 'Kurdî / كوردی', Kurdish
|
|
31
|
+
"mzn",
|
|
32
|
+
// 'مازِرونی', Mazanderani
|
|
33
|
+
"nqo",
|
|
34
|
+
// N'Ko
|
|
35
|
+
"pnb",
|
|
36
|
+
// 'پنجابی', Western Punjabi
|
|
37
|
+
"prs",
|
|
38
|
+
// 'دری', Darī
|
|
39
|
+
"ps",
|
|
40
|
+
// 'پښتو', Pashto,
|
|
41
|
+
"sd",
|
|
42
|
+
// 'سنڌي', Sindhi
|
|
43
|
+
"ug",
|
|
44
|
+
// 'Uyghurche / ئۇيغۇرچە', Uyghur
|
|
45
|
+
"ur",
|
|
46
|
+
// 'اردو', Urdu
|
|
47
|
+
"yi"
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export { rtlLocales as default, rtlLocales };
|
package/client/index.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|