@koine/i18n 2.0.0-beta.141 → 2.0.0-beta.143
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/createT.cjs.js +7 -6
- package/adapter-js/generators/createT.d.ts +2 -1
- package/adapter-js/generators/createT.esm.js +7 -6
- package/adapter-js/generators/defaultI18nMetadata.cjs.js +3 -2
- package/adapter-js/generators/defaultI18nMetadata.d.ts +1 -0
- package/adapter-js/generators/defaultI18nMetadata.esm.js +3 -2
- package/adapter-js/generators/formatTo.cjs.js +4 -3
- package/adapter-js/generators/formatTo.d.ts +1 -0
- package/adapter-js/generators/formatTo.esm.js +4 -3
- package/adapter-js/generators/formatUrl.cjs.js +4 -3
- package/adapter-js/generators/formatUrl.esm.js +4 -3
- package/adapter-js/generators/getI18nDictionaries.cjs.js +27 -4
- package/adapter-js/generators/getI18nDictionaries.d.ts +1 -0
- package/adapter-js/generators/getI18nDictionaries.esm.js +27 -4
- package/adapter-js/generators/getI18nMetadata.cjs.js +16 -15
- package/adapter-js/generators/getI18nMetadata.d.ts +1 -0
- package/adapter-js/generators/getI18nMetadata.esm.js +16 -15
- package/adapter-js/generators/getT.cjs.js +2 -5
- package/adapter-js/generators/getT.esm.js +2 -5
- package/adapter-js/generators/loadTranslations.cjs.js +29 -0
- package/adapter-js/generators/loadTranslations.d.ts +1 -0
- package/adapter-js/generators/loadTranslations.esm.js +27 -0
- package/adapter-js/generators/pathnameToRouteId.cjs.js +2 -2
- package/adapter-js/generators/pathnameToRouteId.esm.js +2 -2
- package/adapter-js/generators/routes.cjs.js +18 -14
- package/adapter-js/generators/routes.d.ts +4 -0
- package/adapter-js/generators/routes.esm.js +18 -14
- package/adapter-js/generators/setLocale.cjs.js +5 -7
- package/adapter-js/generators/setLocale.esm.js +5 -7
- package/adapter-js/generators/t.cjs.js +45 -45
- package/adapter-js/generators/t.d.ts +7 -4
- package/adapter-js/generators/t.esm.js +44 -44
- package/adapter-js/generators/tInterpolateParams.cjs.js +5 -4
- package/adapter-js/generators/tInterpolateParams.d.ts +1 -0
- package/adapter-js/generators/tInterpolateParams.esm.js +5 -4
- package/adapter-js/generators/tInterpolateParamsDeep.cjs.js +4 -3
- package/adapter-js/generators/tInterpolateParamsDeep.d.ts +1 -0
- package/adapter-js/generators/tInterpolateParamsDeep.esm.js +4 -3
- package/adapter-js/generators/tPluralise.cjs.js +7 -4
- package/adapter-js/generators/tPluralise.d.ts +1 -0
- package/adapter-js/generators/tPluralise.esm.js +7 -4
- package/adapter-js/generators/to.cjs.js +54 -53
- package/adapter-js/generators/to.d.ts +8 -4
- package/adapter-js/generators/to.esm.js +53 -52
- package/adapter-js/generators/types.cjs.js +98 -84
- package/adapter-js/generators/types.d.ts +1 -0
- package/adapter-js/generators/types.esm.js +96 -85
- package/adapter-js/index.cjs.js +3 -1
- package/adapter-js/index.d.ts +69 -28
- package/adapter-js/index.esm.js +12 -10
- package/adapter-next/generators/next-redirects.cjs.js +3 -2
- package/adapter-next/generators/next-redirects.d.ts +1 -0
- package/adapter-next/generators/next-redirects.esm.js +3 -2
- package/adapter-next/generators/next-rewrites.cjs.js +3 -2
- package/adapter-next/generators/next-rewrites.d.ts +1 -0
- package/adapter-next/generators/next-rewrites.esm.js +3 -2
- package/adapter-next/generators/router-app/I18nLayout.cjs.js +12 -14
- package/adapter-next/generators/router-app/I18nLayout.esm.js +12 -14
- package/adapter-next/generators/router-app/I18nLayoutRoot.cjs.js +5 -5
- package/adapter-next/generators/router-app/I18nLayoutRoot.esm.js +5 -5
- package/adapter-next/generators/router-app/I18nPage.cjs.js +13 -15
- package/adapter-next/generators/router-app/I18nPage.esm.js +13 -15
- package/adapter-next/generators/router-app/i18nServer.cjs.js +2 -2
- package/adapter-next/generators/router-app/i18nServer.esm.js +2 -2
- package/adapter-next/generators/router-pages/I18nApp.cjs.js +6 -6
- package/adapter-next/generators/router-pages/I18nApp.esm.js +6 -6
- package/adapter-next/generators/router-pages/I18nDocument.cjs.js +2 -2
- package/adapter-next/generators/router-pages/I18nDocument.esm.js +2 -2
- package/adapter-next/generators/router-pages/I18nHead.cjs.js +3 -4
- package/adapter-next/generators/router-pages/I18nHead.d.ts +1 -0
- package/adapter-next/generators/router-pages/I18nHead.esm.js +3 -4
- package/adapter-next/generators/router-pages/I18nSetter.cjs.js +3 -3
- package/adapter-next/generators/router-pages/I18nSetter.esm.js +3 -3
- package/adapter-next/generators/router-pages/i18nGet.cjs.js +12 -14
- package/adapter-next/generators/router-pages/i18nGet.esm.js +12 -14
- package/adapter-next/generators/useRouteId.cjs.js +3 -3
- package/adapter-next/generators/useRouteId.esm.js +3 -3
- package/adapter-next/generators/webpack-define.cjs.js +55 -61
- package/adapter-next/generators/webpack-define.d.ts +15 -15
- package/adapter-next/generators/webpack-define.esm.js +57 -63
- package/adapter-next/index.cjs.js +5 -26
- package/adapter-next/index.d.ts +146 -77
- package/adapter-next/index.esm.js +17 -38
- package/adapter-next-translate/index.d.ts +149 -80
- package/adapter-react/generators/I18nEffects.cjs.js +5 -6
- package/adapter-react/generators/I18nEffects.d.ts +2 -1
- package/adapter-react/generators/I18nEffects.esm.js +5 -6
- package/adapter-react/generators/I18nHeadTags.cjs.js +1 -1
- package/adapter-react/generators/I18nHeadTags.esm.js +1 -1
- package/adapter-react/generators/I18nMetadata.cjs.js +14 -17
- package/adapter-react/generators/I18nMetadata.d.ts +6 -3
- package/adapter-react/generators/I18nMetadata.esm.js +14 -17
- package/adapter-react/generators/I18nRoute.cjs.js +10 -12
- package/adapter-react/generators/I18nRoute.d.ts +5 -2
- package/adapter-react/generators/I18nRoute.esm.js +10 -12
- package/adapter-react/generators/I18nTranslate.cjs.js +11 -11
- package/adapter-react/generators/I18nTranslate.d.ts +2 -0
- package/adapter-react/generators/I18nTranslate.esm.js +11 -11
- package/adapter-react/generators/Trans.cjs.js +4 -3
- package/adapter-react/generators/Trans.d.ts +1 -0
- package/adapter-react/generators/Trans.esm.js +4 -3
- package/adapter-react/generators/getT.cjs.js +3 -6
- package/adapter-react/generators/getT.esm.js +3 -6
- package/adapter-react/generators/getTo.cjs.js +2 -2
- package/adapter-react/generators/getTo.esm.js +2 -2
- package/adapter-react/generators/useRouteId.cjs.js +1 -1
- package/adapter-react/generators/useRouteId.esm.js +1 -1
- package/adapter-react/generators/useToSpa.cjs.js +2 -1
- package/adapter-react/generators/useToSpa.d.ts +2 -1
- package/adapter-react/generators/useToSpa.esm.js +2 -1
- package/adapter-react/index.d.ts +125 -62
- package/compiler/code/data-routes.cjs.js +3 -2
- package/compiler/code/data-routes.esm.js +3 -2
- package/compiler/code/generate.cjs.js +7 -10
- package/compiler/code/generate.esm.js +7 -10
- package/compiler/createAdapter.d.ts +2 -2
- package/compiler/pluralisation.esm.js +1 -1
- package/compiler/types.d.ts +1 -0
- package/package.json +3 -3
- package/adapter-js/generators/getI18nDictionaries_inline.cjs.js +0 -34
- package/adapter-js/generators/getI18nDictionaries_inline.d.ts +0 -4
- package/adapter-js/generators/getI18nDictionaries_inline.esm.js +0 -32
- package/adapter-js/generators/loadTranslations_inline.cjs.js +0 -14
- package/adapter-js/generators/loadTranslations_inline.d.ts +0 -1
- package/adapter-js/generators/loadTranslations_inline.esm.js +0 -12
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var e = createAdapter.createGenerator("js", (
|
|
6
|
-
let { options:
|
|
5
|
+
var e = createAdapter.createGenerator("js", (t)=>{
|
|
6
|
+
let { options: n } = t;
|
|
7
7
|
return {
|
|
8
8
|
createT: {
|
|
9
|
+
dir: createAdapter.createGenerator.dirs.internal,
|
|
9
10
|
name: "createT",
|
|
10
11
|
ext: "ts",
|
|
11
|
-
index: !
|
|
12
|
+
index: !1,
|
|
12
13
|
content: ()=>`
|
|
13
|
-
import type { I18n } from "
|
|
14
|
-
import { defaultLocale } from "
|
|
14
|
+
import type { I18n } from "../types";
|
|
15
|
+
import { defaultLocale } from "../defaultLocale";
|
|
15
16
|
import { tInterpolateParams } from "./tInterpolateParams";
|
|
16
17
|
|
|
17
18
|
// An optional parameter allowEmptyStrings - true as default.
|
|
@@ -53,7 +54,7 @@ export function createT(
|
|
|
53
54
|
query?: I18n.TranslationQuery,
|
|
54
55
|
options?: I18n.TranslationOptions,
|
|
55
56
|
): TReturn => {
|
|
56
|
-
const [namespace, key] = path.split("${
|
|
57
|
+
const [namespace, key] = path.split("${n.translations.tokens.namespaceDelimiter}");
|
|
57
58
|
const dic = (namespace && dictionaries[namespace]) || {};
|
|
58
59
|
const pluralisedKey = getPluralisedKey(pluralRules, dic, key, query, options);
|
|
59
60
|
const dicValue = getDicValue(dic, pluralisedKey, query, options);
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var e = createGenerator("js", (
|
|
4
|
-
let { options:
|
|
3
|
+
var e = createGenerator("js", (t)=>{
|
|
4
|
+
let { options: n } = t;
|
|
5
5
|
return {
|
|
6
6
|
createT: {
|
|
7
|
+
dir: createGenerator.dirs.internal,
|
|
7
8
|
name: "createT",
|
|
8
9
|
ext: "ts",
|
|
9
|
-
index: !
|
|
10
|
+
index: !1,
|
|
10
11
|
content: ()=>`
|
|
11
|
-
import type { I18n } from "
|
|
12
|
-
import { defaultLocale } from "
|
|
12
|
+
import type { I18n } from "../types";
|
|
13
|
+
import { defaultLocale } from "../defaultLocale";
|
|
13
14
|
import { tInterpolateParams } from "./tInterpolateParams";
|
|
14
15
|
|
|
15
16
|
// An optional parameter allowEmptyStrings - true as default.
|
|
@@ -51,7 +52,7 @@ export function createT(
|
|
|
51
52
|
query?: I18n.TranslationQuery,
|
|
52
53
|
options?: I18n.TranslationOptions,
|
|
53
54
|
): TReturn => {
|
|
54
|
-
const [namespace, key] = path.split("${
|
|
55
|
+
const [namespace, key] = path.split("${n.translations.tokens.namespaceDelimiter}");
|
|
55
56
|
const dic = (namespace && dictionaries[namespace]) || {};
|
|
56
57
|
const pluralisedKey = getPluralisedKey(pluralRules, dic, key, query, options);
|
|
57
58
|
const dicValue = getDicValue(dic, pluralisedKey, query, options);
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var t = createAdapter.createGenerator("js", (
|
|
5
|
+
var t = createAdapter.createGenerator("js", (a)=>({
|
|
6
6
|
defaultI18nMetadata: {
|
|
7
|
+
dir: createAdapter.createGenerator.dirs.internal,
|
|
7
8
|
name: "defaultI18nMetadata",
|
|
8
9
|
ext: "ts",
|
|
9
10
|
index: !1,
|
|
10
11
|
content: ()=>`
|
|
11
|
-
import type { I18n } from "
|
|
12
|
+
import type { I18n } from "../types";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @internal
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var t = createGenerator("js", (
|
|
3
|
+
var t = createGenerator("js", (a)=>({
|
|
4
4
|
defaultI18nMetadata: {
|
|
5
|
+
dir: createGenerator.dirs.internal,
|
|
5
6
|
name: "defaultI18nMetadata",
|
|
6
7
|
ext: "ts",
|
|
7
8
|
index: !1,
|
|
8
9
|
content: ()=>`
|
|
9
|
-
import type { I18n } from "
|
|
10
|
+
import type { I18n } from "../types";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @internal
|
|
@@ -74,14 +74,15 @@ const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, o)=>new funct
|
|
|
74
74
|
return pathname;
|
|
75
75
|
`
|
|
76
76
|
});
|
|
77
|
-
var a = createAdapter.createGenerator("js", (
|
|
78
|
-
let { config:
|
|
77
|
+
var a = createAdapter.createGenerator("js", (a)=>{
|
|
78
|
+
let { config: t } = a;
|
|
79
79
|
return {
|
|
80
80
|
formatTo: {
|
|
81
|
+
dir: createAdapter.createGenerator.dirs.internal,
|
|
81
82
|
name: "formatTo",
|
|
82
83
|
ext: "ts",
|
|
83
84
|
index: !1,
|
|
84
|
-
content: ()=>formatTo(
|
|
85
|
+
content: ()=>formatTo(t, !0).$out("ts", {
|
|
85
86
|
imports: {
|
|
86
87
|
folderUp: 0
|
|
87
88
|
},
|
|
@@ -3,6 +3,7 @@ import type { I18nCompiler } from "../../compiler/types";
|
|
|
3
3
|
export declare const formatTo: ({ defaultLocale, hideDefaultLocaleInUrl, }: Pick<I18nCompiler.Config, "defaultLocale" | "hideDefaultLocaleInUrl" | "trailingSlash">, devDebug?: boolean) => FunctionsCompiler;
|
|
4
4
|
declare const _default: (data: I18nCompiler.DataCode<"js">) => {
|
|
5
5
|
formatTo: {
|
|
6
|
+
dir: string;
|
|
6
7
|
name: string;
|
|
7
8
|
ext: "ts";
|
|
8
9
|
index: false;
|
|
@@ -70,14 +70,15 @@ const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, o)=>new Funct
|
|
|
70
70
|
return pathname;
|
|
71
71
|
`
|
|
72
72
|
});
|
|
73
|
-
var a = createGenerator("js", (
|
|
74
|
-
let { config:
|
|
73
|
+
var a = createGenerator("js", (a)=>{
|
|
74
|
+
let { config: t } = a;
|
|
75
75
|
return {
|
|
76
76
|
formatTo: {
|
|
77
|
+
dir: createGenerator.dirs.internal,
|
|
77
78
|
name: "formatTo",
|
|
78
79
|
ext: "ts",
|
|
79
80
|
index: !1,
|
|
80
|
-
content: ()=>formatTo(
|
|
81
|
+
content: ()=>formatTo(t, !0).$out("ts", {
|
|
81
82
|
imports: {
|
|
82
83
|
folderUp: 0
|
|
83
84
|
},
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
5
|
var m = createAdapter.createGenerator("js", (e)=>{
|
|
6
|
-
let { config: { baseUrl:
|
|
6
|
+
let { config: { baseUrl: t, trailingSlash: a } } = e;
|
|
7
7
|
return {
|
|
8
8
|
formatUrl: {
|
|
9
9
|
name: "formatUrl",
|
|
@@ -14,10 +14,11 @@ var m = createAdapter.createGenerator("js", (e)=>{
|
|
|
14
14
|
* Returns an absolute normalised URL prepending the \`baseUrl\` i18n option to
|
|
15
15
|
* the given pathname. It respects the \`trailingSlash\` option.
|
|
16
16
|
*
|
|
17
|
-
* @internal
|
|
18
17
|
* @param pathname Normalised, always prepended with a locale (if needed) and a slash
|
|
19
18
|
*/
|
|
20
|
-
export const formatUrl = (pathname: string) => "${
|
|
19
|
+
export const formatUrl = (pathname: string) => "${t}" + ${a ? "pathname" : '(pathname === "/" ? "" : pathname)'};
|
|
20
|
+
|
|
21
|
+
export default formatUrl;
|
|
21
22
|
`
|
|
22
23
|
}
|
|
23
24
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
3
|
var m = createGenerator("js", (e)=>{
|
|
4
|
-
let { config: { baseUrl:
|
|
4
|
+
let { config: { baseUrl: t, trailingSlash: a } } = e;
|
|
5
5
|
return {
|
|
6
6
|
formatUrl: {
|
|
7
7
|
name: "formatUrl",
|
|
@@ -12,10 +12,11 @@ var m = createGenerator("js", (e)=>{
|
|
|
12
12
|
* Returns an absolute normalised URL prepending the \`baseUrl\` i18n option to
|
|
13
13
|
* the given pathname. It respects the \`trailingSlash\` option.
|
|
14
14
|
*
|
|
15
|
-
* @internal
|
|
16
15
|
* @param pathname Normalised, always prepended with a locale (if needed) and a slash
|
|
17
16
|
*/
|
|
18
|
-
export const formatUrl = (pathname: string) => "${
|
|
17
|
+
export const formatUrl = (pathname: string) => "${t}" + ${a ? "pathname" : '(pathname === "/" ? "" : pathname)'};
|
|
18
|
+
|
|
19
|
+
export default formatUrl;
|
|
19
20
|
`
|
|
20
21
|
}
|
|
21
22
|
};
|
|
@@ -1,18 +1,41 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
|
-
var getI18nDictionaries_inline = require('./getI18nDictionaries_inline.cjs.js');
|
|
5
4
|
|
|
6
5
|
var s = createAdapter.createGenerator("js", (e)=>({
|
|
7
6
|
getI18nDictionaries: {
|
|
7
|
+
dir: createAdapter.createGenerator.dirs.internal,
|
|
8
8
|
name: "getI18nDictionaries",
|
|
9
9
|
ext: "ts",
|
|
10
10
|
index: !1,
|
|
11
11
|
content: ()=>`
|
|
12
|
-
import { defaultLocale } from "
|
|
13
|
-
import type { I18n } from "
|
|
12
|
+
import { defaultLocale } from "../defaultLocale";
|
|
13
|
+
import type { I18n } from "../types";
|
|
14
|
+
import { loadTranslations } from "./loadTranslations";
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
type GetI18nDictionariesOptions = {
|
|
17
|
+
locale?: I18n.Locale;
|
|
18
|
+
namespaces?: I18n.TranslateNamespace[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export async function getI18nDictionaries({
|
|
22
|
+
locale = defaultLocale,
|
|
23
|
+
namespaces = [],
|
|
24
|
+
}: GetI18nDictionariesOptions) {
|
|
25
|
+
const translations =
|
|
26
|
+
(await Promise.all(
|
|
27
|
+
namespaces.map((namespace) => loadTranslations(locale, namespace)
|
|
28
|
+
.catch(() => ({}))
|
|
29
|
+
),
|
|
30
|
+
)) || [];
|
|
31
|
+
|
|
32
|
+
return namespaces.reduce((dictionaries, ns, idx) => {
|
|
33
|
+
dictionaries[ns] =
|
|
34
|
+
translations[idx] ||
|
|
35
|
+
(null as unknown as I18n.TranslationsDictionaryLoose);
|
|
36
|
+
return dictionaries;
|
|
37
|
+
}, {} as I18n.Dictionaries);
|
|
38
|
+
}
|
|
16
39
|
`
|
|
17
40
|
}
|
|
18
41
|
}));
|
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
|
-
import { getI18nDictionaries_inline } from './getI18nDictionaries_inline.esm.js';
|
|
3
2
|
|
|
4
3
|
var s = createGenerator("js", (e)=>({
|
|
5
4
|
getI18nDictionaries: {
|
|
5
|
+
dir: createGenerator.dirs.internal,
|
|
6
6
|
name: "getI18nDictionaries",
|
|
7
7
|
ext: "ts",
|
|
8
8
|
index: !1,
|
|
9
9
|
content: ()=>`
|
|
10
|
-
import { defaultLocale } from "
|
|
11
|
-
import type { I18n } from "
|
|
10
|
+
import { defaultLocale } from "../defaultLocale";
|
|
11
|
+
import type { I18n } from "../types";
|
|
12
|
+
import { loadTranslations } from "./loadTranslations";
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
type GetI18nDictionariesOptions = {
|
|
15
|
+
locale?: I18n.Locale;
|
|
16
|
+
namespaces?: I18n.TranslateNamespace[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export async function getI18nDictionaries({
|
|
20
|
+
locale = defaultLocale,
|
|
21
|
+
namespaces = [],
|
|
22
|
+
}: GetI18nDictionariesOptions) {
|
|
23
|
+
const translations =
|
|
24
|
+
(await Promise.all(
|
|
25
|
+
namespaces.map((namespace) => loadTranslations(locale, namespace)
|
|
26
|
+
.catch(() => ({}))
|
|
27
|
+
),
|
|
28
|
+
)) || [];
|
|
29
|
+
|
|
30
|
+
return namespaces.reduce((dictionaries, ns, idx) => {
|
|
31
|
+
dictionaries[ns] =
|
|
32
|
+
translations[idx] ||
|
|
33
|
+
(null as unknown as I18n.TranslationsDictionaryLoose);
|
|
34
|
+
return dictionaries;
|
|
35
|
+
}, {} as I18n.Dictionaries);
|
|
36
|
+
}
|
|
14
37
|
`
|
|
15
38
|
}
|
|
16
39
|
}));
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var n = createAdapter.createGenerator("js", (
|
|
6
|
-
let { routes: { dynamicRoutes:
|
|
5
|
+
var n = createAdapter.createGenerator("js", (e)=>{
|
|
6
|
+
let { routes: { dynamicRoutes: a, staticRoutes: o } } = e;
|
|
7
7
|
return {
|
|
8
8
|
getI18nMetadata: {
|
|
9
|
+
dir: createAdapter.createGenerator.dirs.internal,
|
|
9
10
|
name: "getI18nMetadata",
|
|
10
11
|
ext: "ts",
|
|
11
12
|
index: !1,
|
|
12
13
|
content: ()=>`
|
|
14
|
+
import { defaultLocale } from "../defaultLocale";
|
|
15
|
+
import { formatUrl } from "../formatUrl";
|
|
16
|
+
import { locales } from "../locales";
|
|
17
|
+
import { to } from "../to";
|
|
18
|
+
import type { I18n } from "../types";
|
|
13
19
|
import { defaultI18nMetadata } from "./defaultI18nMetadata";
|
|
14
|
-
import { defaultLocale } from "./defaultLocale";
|
|
15
|
-
import { formatUrl } from "./formatUrl";
|
|
16
|
-
import { locales } from "./locales";
|
|
17
20
|
import { type RouteIdError, isErrorRoute } from "./routesError";
|
|
18
|
-
import { to } from "./to";
|
|
19
|
-
import type { I18n } from "./types";
|
|
20
21
|
|
|
21
22
|
type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
22
23
|
locale: I18n.Locale;
|
|
@@ -31,30 +32,30 @@ type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
|
31
32
|
*/
|
|
32
33
|
export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
33
34
|
locale: currentLocale,
|
|
34
|
-
id,${
|
|
35
|
+
id,${a.length ? `
|
|
35
36
|
params,` : ""}
|
|
36
37
|
}: GetI18nMetadataOptions<TRouteId>) {
|
|
37
|
-
if (isErrorRoute(id)) return defaultI18nMetadata;${
|
|
38
|
+
if (isErrorRoute(id)) return defaultI18nMetadata;${a.length && !o.length ? `
|
|
38
39
|
params = params as NonNullable<typeof params>;` : ""}
|
|
39
40
|
const alternates: I18n.Alternates = {
|
|
40
|
-
"x-default": formatUrl(${
|
|
41
|
+
"x-default": formatUrl(${a.length && o.length ? `
|
|
41
42
|
// @ ts-ignore dynamic to fn typing
|
|
42
43
|
params ? to(id, params, defaultLocale) : to(id, defaultLocale),
|
|
43
|
-
),` :
|
|
44
|
+
),` : a.length ? "to(id, params, defaultLocale))," : "to(id, defaultLocale)),"}
|
|
44
45
|
};
|
|
45
46
|
locales.forEach((locale) => {
|
|
46
|
-
alternates[locale] = formatUrl(${
|
|
47
|
+
alternates[locale] = formatUrl(${a.length && o.length ? `
|
|
47
48
|
// @ ts-ignore dynamic to fn typing
|
|
48
49
|
params ? to(id, params, locale) : to(id, locale),
|
|
49
|
-
);` :
|
|
50
|
+
);` : a.length ? "to(id, params, locale));" : "to(id, locale));"}
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
return {
|
|
53
54
|
alternates,
|
|
54
|
-
canonical: formatUrl(${
|
|
55
|
+
canonical: formatUrl(${a.length && o.length ? `
|
|
55
56
|
// @ ts-ignore dynamic to fn typing
|
|
56
57
|
params ? to(id, params, currentLocale) : to(id, currentLocale),
|
|
57
|
-
),` :
|
|
58
|
+
),` : a.length ? "to(id, params, currentLocale))," : "to(id, currentLocale)),"}
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
`
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var n = createGenerator("js", (
|
|
4
|
-
let { routes: { dynamicRoutes:
|
|
3
|
+
var n = createGenerator("js", (e)=>{
|
|
4
|
+
let { routes: { dynamicRoutes: a, staticRoutes: o } } = e;
|
|
5
5
|
return {
|
|
6
6
|
getI18nMetadata: {
|
|
7
|
+
dir: createGenerator.dirs.internal,
|
|
7
8
|
name: "getI18nMetadata",
|
|
8
9
|
ext: "ts",
|
|
9
10
|
index: !1,
|
|
10
11
|
content: ()=>`
|
|
12
|
+
import { defaultLocale } from "../defaultLocale";
|
|
13
|
+
import { formatUrl } from "../formatUrl";
|
|
14
|
+
import { locales } from "../locales";
|
|
15
|
+
import { to } from "../to";
|
|
16
|
+
import type { I18n } from "../types";
|
|
11
17
|
import { defaultI18nMetadata } from "./defaultI18nMetadata";
|
|
12
|
-
import { defaultLocale } from "./defaultLocale";
|
|
13
|
-
import { formatUrl } from "./formatUrl";
|
|
14
|
-
import { locales } from "./locales";
|
|
15
18
|
import { type RouteIdError, isErrorRoute } from "./routesError";
|
|
16
|
-
import { to } from "./to";
|
|
17
|
-
import type { I18n } from "./types";
|
|
18
19
|
|
|
19
20
|
type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
20
21
|
locale: I18n.Locale;
|
|
@@ -29,30 +30,30 @@ type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
|
29
30
|
*/
|
|
30
31
|
export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
31
32
|
locale: currentLocale,
|
|
32
|
-
id,${
|
|
33
|
+
id,${a.length ? `
|
|
33
34
|
params,` : ""}
|
|
34
35
|
}: GetI18nMetadataOptions<TRouteId>) {
|
|
35
|
-
if (isErrorRoute(id)) return defaultI18nMetadata;${
|
|
36
|
+
if (isErrorRoute(id)) return defaultI18nMetadata;${a.length && !o.length ? `
|
|
36
37
|
params = params as NonNullable<typeof params>;` : ""}
|
|
37
38
|
const alternates: I18n.Alternates = {
|
|
38
|
-
"x-default": formatUrl(${
|
|
39
|
+
"x-default": formatUrl(${a.length && o.length ? `
|
|
39
40
|
// @ ts-ignore dynamic to fn typing
|
|
40
41
|
params ? to(id, params, defaultLocale) : to(id, defaultLocale),
|
|
41
|
-
),` :
|
|
42
|
+
),` : a.length ? "to(id, params, defaultLocale))," : "to(id, defaultLocale)),"}
|
|
42
43
|
};
|
|
43
44
|
locales.forEach((locale) => {
|
|
44
|
-
alternates[locale] = formatUrl(${
|
|
45
|
+
alternates[locale] = formatUrl(${a.length && o.length ? `
|
|
45
46
|
// @ ts-ignore dynamic to fn typing
|
|
46
47
|
params ? to(id, params, locale) : to(id, locale),
|
|
47
|
-
);` :
|
|
48
|
+
);` : a.length ? "to(id, params, locale));" : "to(id, locale));"}
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
return {
|
|
51
52
|
alternates,
|
|
52
|
-
canonical: formatUrl(${
|
|
53
|
+
canonical: formatUrl(${a.length && o.length ? `
|
|
53
54
|
// @ ts-ignore dynamic to fn typing
|
|
54
55
|
params ? to(id, params, currentLocale) : to(id, currentLocale),
|
|
55
|
-
),` :
|
|
56
|
+
),` : a.length ? "to(id, params, currentLocale))," : "to(id, currentLocale)),"}
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
`
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
|
-
var loadTranslations_inline = require('./loadTranslations_inline.cjs.js');
|
|
5
4
|
|
|
6
5
|
var p = createAdapter.createGenerator("js", (a)=>({
|
|
7
6
|
getT: {
|
|
@@ -9,12 +8,10 @@ var p = createAdapter.createGenerator("js", (a)=>({
|
|
|
9
8
|
ext: "ts",
|
|
10
9
|
index: !0,
|
|
11
10
|
content: ()=>`
|
|
12
|
-
import { createT } from "./createT";
|
|
13
|
-
|
|
11
|
+
import { createT } from "./internal/createT";
|
|
12
|
+
import { loadTranslations } from "./internal/loadTranslations";
|
|
14
13
|
import type { I18n } from "./types";
|
|
15
14
|
|
|
16
|
-
${loadTranslations_inline.loadTranslations_inline()}
|
|
17
|
-
|
|
18
15
|
export async function getT<TNamespace extends I18n.TranslateNamespace>(
|
|
19
16
|
locale: I18n.Locale,
|
|
20
17
|
namespace: TNamespace,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
|
-
import { loadTranslations_inline } from './loadTranslations_inline.esm.js';
|
|
3
2
|
|
|
4
3
|
var p = createGenerator("js", (a)=>({
|
|
5
4
|
getT: {
|
|
@@ -7,12 +6,10 @@ var p = createGenerator("js", (a)=>({
|
|
|
7
6
|
ext: "ts",
|
|
8
7
|
index: !0,
|
|
9
8
|
content: ()=>`
|
|
10
|
-
import { createT } from "./createT";
|
|
11
|
-
|
|
9
|
+
import { createT } from "./internal/createT";
|
|
10
|
+
import { loadTranslations } from "./internal/loadTranslations";
|
|
12
11
|
import type { I18n } from "./types";
|
|
13
12
|
|
|
14
|
-
${loadTranslations_inline()}
|
|
15
|
-
|
|
16
13
|
export async function getT<TNamespace extends I18n.TranslateNamespace>(
|
|
17
14
|
locale: I18n.Locale,
|
|
18
15
|
namespace: TNamespace,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
|
+
var helpers = require('../../compiler/helpers.cjs.js');
|
|
5
|
+
|
|
6
|
+
var f = createAdapter.createGenerator("js", (t)=>({
|
|
7
|
+
loadTranslations: {
|
|
8
|
+
dir: createAdapter.createGenerator.dirs.internal,
|
|
9
|
+
name: "loadTranslations",
|
|
10
|
+
ext: "ts",
|
|
11
|
+
index: !1,
|
|
12
|
+
content: ()=>`
|
|
13
|
+
import type { I18n } from "../types";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export const loadTranslations = (
|
|
19
|
+
locale: I18n.Locale,
|
|
20
|
+
namespace: I18n.TranslateNamespace,
|
|
21
|
+
) =>
|
|
22
|
+
import(\`${helpers.getTranslationsDir(1)}/\${locale}/\${namespace}.json\`).then(
|
|
23
|
+
(m) => m.default,
|
|
24
|
+
);
|
|
25
|
+
`
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
module.exports = f;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
|
+
import { getTranslationsDir } from '../../compiler/helpers.esm.js';
|
|
3
|
+
|
|
4
|
+
var f = createGenerator("js", (t)=>({
|
|
5
|
+
loadTranslations: {
|
|
6
|
+
dir: createGenerator.dirs.internal,
|
|
7
|
+
name: "loadTranslations",
|
|
8
|
+
ext: "ts",
|
|
9
|
+
index: !1,
|
|
10
|
+
content: ()=>`
|
|
11
|
+
import type { I18n } from "../types";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const loadTranslations = (
|
|
17
|
+
locale: I18n.Locale,
|
|
18
|
+
namespace: I18n.TranslateNamespace,
|
|
19
|
+
) =>
|
|
20
|
+
import(\`${getTranslationsDir(1)}/\${locale}/\${namespace}.json\`).then(
|
|
21
|
+
(m) => m.default,
|
|
22
|
+
);
|
|
23
|
+
`
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
export { f as default };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var utils = require('@koine/utils');
|
|
4
4
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var g = createAdapter.createGenerator("js", (t)=>{
|
|
7
7
|
let { options: a } = t, { idDelimiter: r, optionalCatchAll: o, catchAll: n } = a.routes.tokens;
|
|
8
8
|
return {
|
|
9
9
|
pathnameToRouteId: {
|
|
@@ -30,4 +30,4 @@ export default pathnameToRouteId;
|
|
|
30
30
|
};
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
module.exports =
|
|
33
|
+
module.exports = g;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { escapeRegExp } from '@koine/utils';
|
|
2
2
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var g = createGenerator("js", (t)=>{
|
|
5
5
|
let { options: a } = t, { idDelimiter: r, optionalCatchAll: o, catchAll: n } = a.routes.tokens;
|
|
6
6
|
return {
|
|
7
7
|
pathnameToRouteId: {
|
|
@@ -28,4 +28,4 @@ export default pathnameToRouteId;
|
|
|
28
28
|
};
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
export {
|
|
31
|
+
export { g as default };
|