@koine/i18n 2.0.0-beta.134 → 2.0.0-beta.136
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/formatTo.cjs.js +58 -23
- package/adapter-js/generators/formatTo.d.ts +4 -1
- package/adapter-js/generators/formatTo.esm.js +55 -23
- package/adapter-js/generators/t.cjs.js +3 -3
- package/adapter-js/generators/t.d.ts +1 -1
- package/adapter-js/generators/t.esm.js +3 -3
- package/adapter-js/generators/tInterpolateParams.cjs.js +1 -1
- package/adapter-js/generators/tInterpolateParams.esm.js +1 -1
- package/adapter-js/generators/to.cjs.js +30 -28
- package/adapter-js/generators/to.d.ts +1 -0
- package/adapter-js/generators/to.esm.js +27 -28
- package/adapter-js/index.cjs.js +2 -2
- package/adapter-next/generators/next-redirects.cjs.js +4 -3
- package/adapter-next/generators/next-redirects.d.ts +1 -0
- package/adapter-next/generators/next-redirects.esm.js +4 -3
- package/adapter-next/generators/next-rewrites.cjs.js +4 -3
- package/adapter-next/generators/next-rewrites.d.ts +1 -0
- package/adapter-next/generators/next-rewrites.esm.js +4 -3
- package/adapter-next/generators/router-app/I18nLayout.cjs.js +9 -9
- package/adapter-next/generators/router-app/I18nLayout.esm.js +9 -9
- package/adapter-next/generators/router-app/I18nLayoutRoot.cjs.js +4 -4
- package/adapter-next/generators/router-app/I18nLayoutRoot.esm.js +4 -4
- package/adapter-next/generators/router-app/I18nPage.cjs.js +7 -7
- package/adapter-next/generators/router-app/I18nPage.esm.js +7 -7
- package/adapter-next/generators/router-app/i18nServer.cjs.js +5 -5
- package/adapter-next/generators/router-app/i18nServer.esm.js +5 -5
- package/adapter-next/generators/webpack-define.cjs.js +131 -53
- package/adapter-next/generators/webpack-define.d.ts +11 -4
- package/adapter-next/generators/webpack-define.esm.js +133 -55
- package/adapter-next/plugin-shared.cjs.js +28 -42
- package/adapter-next/plugin-shared.esm.js +28 -42
- package/adapter-react/generators/I18nLocaleContext.cjs.js +2 -2
- package/adapter-react/generators/I18nLocaleContext.esm.js +2 -2
- package/adapter-react/generators/getLocale.cjs.js +2 -2
- package/adapter-react/generators/getLocale.esm.js +2 -2
- package/adapter-react/generators/getT.cjs.js +2 -2
- package/adapter-react/generators/getT.esm.js +2 -2
- package/adapter-react/generators/getTo.cjs.js +5 -5
- package/adapter-react/generators/getTo.esm.js +5 -5
- package/package.json +3 -3
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
formatTo: {
|
|
9
|
-
name: "formatTo",
|
|
10
|
-
ext: "ts",
|
|
11
|
-
index: !1,
|
|
12
|
-
content: ()=>`
|
|
13
|
-
import { defaultLocale } from "./defaultLocale";
|
|
5
|
+
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
6
|
+
var functions = require('../../compiler/functions.cjs.js');
|
|
7
|
+
var imports = require('../../compiler/imports.cjs.js');
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
const formatTo = ({ hideDefaultLocaleInUrl: e })=>new functions.FunctionsCompiler({
|
|
10
|
+
imports: [
|
|
11
|
+
new imports.ImportsCompiler({
|
|
12
|
+
path: "defaultLocale",
|
|
13
|
+
named: [
|
|
14
|
+
{
|
|
15
|
+
name: "defaultLocale"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
})
|
|
19
|
+
],
|
|
20
|
+
comment: {
|
|
21
|
+
internal: !0
|
|
22
|
+
},
|
|
23
|
+
name: "formatTo",
|
|
24
|
+
args: [
|
|
25
|
+
{
|
|
26
|
+
name: "locale",
|
|
27
|
+
type: "string | undefined",
|
|
28
|
+
optional: !1
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "pathname",
|
|
32
|
+
type: "string",
|
|
33
|
+
optional: !1
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "params",
|
|
37
|
+
type: "object",
|
|
38
|
+
optional: !0
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
body: ({ format: a })=>`{
|
|
23
42
|
locale = locale || defaultLocale;
|
|
24
43
|
if (process.env["NODE_ENV"] === "development") {
|
|
25
44
|
if (params) {
|
|
26
45
|
pathname.replace(/\\[(.*?)\\]/g, (_, dynamicKey) => {
|
|
27
|
-
const key = dynamicKey as Extract<keyof typeof params, string
|
|
46
|
+
const key = dynamicKey${"ts" === a ? " as Extract<keyof typeof params, string>" : ""};
|
|
28
47
|
|
|
29
48
|
if (!(key in params)) {
|
|
30
49
|
console.warn(
|
|
@@ -57,19 +76,35 @@ export function formatTo(
|
|
|
57
76
|
pathname = pathname.replace(
|
|
58
77
|
/\\[(.*?)\\]/g,
|
|
59
78
|
(_, key) =>
|
|
60
|
-
params[key as keyof typeof params] + "",
|
|
79
|
+
params[key${"ts" === a ? " as keyof typeof params" : ""}] + "",
|
|
61
80
|
)
|
|
62
81
|
}
|
|
63
|
-
${
|
|
82
|
+
${e ? `
|
|
64
83
|
if (locale !== defaultLocale) {
|
|
65
84
|
return "/" + locale + (pathname === "/" ? "" : pathname);
|
|
66
85
|
}
|
|
67
86
|
` : ""}
|
|
68
87
|
return pathname;
|
|
69
|
-
}
|
|
88
|
+
}`
|
|
89
|
+
});
|
|
90
|
+
var a = createAdapter.createGenerator("js", (e)=>{
|
|
91
|
+
let { config: a } = e;
|
|
92
|
+
return {
|
|
93
|
+
formatTo: {
|
|
94
|
+
name: "formatTo",
|
|
95
|
+
ext: "ts",
|
|
96
|
+
index: !1,
|
|
97
|
+
content: ()=>`
|
|
98
|
+
${formatTo(a).$out("ts", {
|
|
99
|
+
imports: {
|
|
100
|
+
folderUp: 0
|
|
101
|
+
},
|
|
102
|
+
exports: "named"
|
|
103
|
+
})}
|
|
70
104
|
`
|
|
71
105
|
}
|
|
72
106
|
};
|
|
73
107
|
});
|
|
74
108
|
|
|
75
|
-
|
|
109
|
+
exports.default = a;
|
|
110
|
+
exports.formatTo = formatTo;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { FunctionsCompiler } from "../../compiler/functions";
|
|
2
|
+
import type { I18nCompiler } from "../../compiler/types";
|
|
3
|
+
export declare const formatTo: ({ hideDefaultLocaleInUrl, }: Pick<I18nCompiler.Config, "hideDefaultLocaleInUrl">) => FunctionsCompiler;
|
|
4
|
+
declare const _default: (data: I18nCompiler.DataCode<"js">) => {
|
|
2
5
|
formatTo: {
|
|
3
6
|
name: string;
|
|
4
7
|
ext: "ts";
|
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
|
+
import { FunctionsCompiler } from '../../compiler/functions.esm.js';
|
|
3
|
+
import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
const formatTo = ({ hideDefaultLocaleInUrl: e })=>new FunctionsCompiler({
|
|
6
|
+
imports: [
|
|
7
|
+
new ImportsCompiler({
|
|
8
|
+
path: "defaultLocale",
|
|
9
|
+
named: [
|
|
10
|
+
{
|
|
11
|
+
name: "defaultLocale"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
})
|
|
15
|
+
],
|
|
16
|
+
comment: {
|
|
17
|
+
internal: !0
|
|
18
|
+
},
|
|
19
|
+
name: "formatTo",
|
|
20
|
+
args: [
|
|
21
|
+
{
|
|
22
|
+
name: "locale",
|
|
23
|
+
type: "string | undefined",
|
|
24
|
+
optional: !1
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "pathname",
|
|
28
|
+
type: "string",
|
|
29
|
+
optional: !1
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "params",
|
|
33
|
+
type: "object",
|
|
34
|
+
optional: !0
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
body: ({ format: a })=>`{
|
|
21
38
|
locale = locale || defaultLocale;
|
|
22
39
|
if (process.env["NODE_ENV"] === "development") {
|
|
23
40
|
if (params) {
|
|
24
41
|
pathname.replace(/\\[(.*?)\\]/g, (_, dynamicKey) => {
|
|
25
|
-
const key = dynamicKey as Extract<keyof typeof params, string
|
|
42
|
+
const key = dynamicKey${"ts" === a ? " as Extract<keyof typeof params, string>" : ""};
|
|
26
43
|
|
|
27
44
|
if (!(key in params)) {
|
|
28
45
|
console.warn(
|
|
@@ -55,19 +72,34 @@ export function formatTo(
|
|
|
55
72
|
pathname = pathname.replace(
|
|
56
73
|
/\\[(.*?)\\]/g,
|
|
57
74
|
(_, key) =>
|
|
58
|
-
params[key as keyof typeof params] + "",
|
|
75
|
+
params[key${"ts" === a ? " as keyof typeof params" : ""}] + "",
|
|
59
76
|
)
|
|
60
77
|
}
|
|
61
|
-
${
|
|
78
|
+
${e ? `
|
|
62
79
|
if (locale !== defaultLocale) {
|
|
63
80
|
return "/" + locale + (pathname === "/" ? "" : pathname);
|
|
64
81
|
}
|
|
65
82
|
` : ""}
|
|
66
83
|
return pathname;
|
|
67
|
-
}
|
|
84
|
+
}`
|
|
85
|
+
});
|
|
86
|
+
var a = createGenerator("js", (e)=>{
|
|
87
|
+
let { config: a } = e;
|
|
88
|
+
return {
|
|
89
|
+
formatTo: {
|
|
90
|
+
name: "formatTo",
|
|
91
|
+
ext: "ts",
|
|
92
|
+
index: !1,
|
|
93
|
+
content: ()=>`
|
|
94
|
+
${formatTo(a).$out("ts", {
|
|
95
|
+
imports: {
|
|
96
|
+
folderUp: 0
|
|
97
|
+
},
|
|
98
|
+
exports: "named"
|
|
99
|
+
})}
|
|
68
100
|
`
|
|
69
101
|
}
|
|
70
102
|
};
|
|
71
103
|
});
|
|
72
104
|
|
|
73
|
-
export { a as default };
|
|
105
|
+
export { a as default, formatTo };
|
|
@@ -10,7 +10,7 @@ var imports = require('../../compiler/imports.cjs.js');
|
|
|
10
10
|
|
|
11
11
|
const getTranslationValueOutput = (t)=>utils.isString(t) || utils.isNumber(t) ? `"${t}"` : utils.isBoolean(t) ? `${t}` : utils.isArray(t) ? JSON.stringify(t) : `(${JSON.stringify(t)})`;
|
|
12
12
|
const areEqualTranslationsValues = (e, a)=>utils.areEqual(e, a);
|
|
13
|
-
const
|
|
13
|
+
const getTFunctionBodyWithLocales = (t, e)=>{
|
|
14
14
|
let a = "";
|
|
15
15
|
for(let n in e){
|
|
16
16
|
let r = e[n];
|
|
@@ -65,7 +65,7 @@ const getTFunctions = (t, e)=>{
|
|
|
65
65
|
let h = "", P = [
|
|
66
66
|
i.types
|
|
67
67
|
];
|
|
68
|
-
utils.isPrimitive(c) ? h += getTranslationValueOutput(c) : h +=
|
|
68
|
+
utils.isPrimitive(c) ? h += getTranslationValueOutput(c) : h += getTFunctionBodyWithLocales(a, c), $ && (m = !0, h = `tPluralise(${h}, params.count)`), d && (u = !0, h = `tInterpolateParams(${h}, params)`), u && (P.push(i.tInterpolateParams), l.add(i.tInterpolateParams)), m && (P.push(i.tPluralise), l.add(i.tPluralise)), o.push(new functions.FunctionsCompiler({
|
|
69
69
|
imports: P,
|
|
70
70
|
name: f,
|
|
71
71
|
args: y,
|
|
@@ -113,6 +113,6 @@ var l = createAdapter.createGenerator("js", (t)=>{
|
|
|
113
113
|
|
|
114
114
|
exports.areEqualTranslationsValues = areEqualTranslationsValues;
|
|
115
115
|
exports.default = l;
|
|
116
|
-
exports.
|
|
116
|
+
exports.getTFunctionBodyWithLocales = getTFunctionBodyWithLocales;
|
|
117
117
|
exports.getTFunctions = getTFunctions;
|
|
118
118
|
exports.getTranslationValueOutput = getTranslationValueOutput;
|
|
@@ -3,7 +3,7 @@ import { ImportsCompiler } from "../../compiler/imports";
|
|
|
3
3
|
import type { I18nCompiler } from "../../compiler/types";
|
|
4
4
|
export declare const getTranslationValueOutput: (value: I18nCompiler.DataTranslationValue) => string;
|
|
5
5
|
export declare const areEqualTranslationsValues: (a: I18nCompiler.DataTranslationValue, b: I18nCompiler.DataTranslationValue) => boolean;
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const getTFunctionBodyWithLocales: (defaultLocale: I18nCompiler.Config["defaultLocale"], perLocaleValues: I18nCompiler.DataTranslation["values"]) => string;
|
|
7
7
|
export declare const getTFunctions: (translations: I18nCompiler.DataTranslations, options: {
|
|
8
8
|
defaultLocale: string;
|
|
9
9
|
fnPrefix: string;
|
|
@@ -6,7 +6,7 @@ import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
|
6
6
|
|
|
7
7
|
const getTranslationValueOutput = (t)=>isString(t) || isNumber(t) ? `"${t}"` : isBoolean(t) ? `${t}` : isArray(t) ? JSON.stringify(t) : `(${JSON.stringify(t)})`;
|
|
8
8
|
const areEqualTranslationsValues = (e, a)=>areEqual(e, a);
|
|
9
|
-
const
|
|
9
|
+
const getTFunctionBodyWithLocales = (t, e)=>{
|
|
10
10
|
let a = "";
|
|
11
11
|
for(let n in e){
|
|
12
12
|
let r = e[n];
|
|
@@ -61,7 +61,7 @@ const getTFunctions = (t, e)=>{
|
|
|
61
61
|
let h = "", P = [
|
|
62
62
|
i.types
|
|
63
63
|
];
|
|
64
|
-
isPrimitive(c) ? h += getTranslationValueOutput(c) : h +=
|
|
64
|
+
isPrimitive(c) ? h += getTranslationValueOutput(c) : h += getTFunctionBodyWithLocales(a, c), $ && (m = !0, h = `tPluralise(${h}, params.count)`), d && (u = !0, h = `tInterpolateParams(${h}, params)`), u && (P.push(i.tInterpolateParams), l.add(i.tInterpolateParams)), m && (P.push(i.tPluralise), l.add(i.tPluralise)), o.push(new FunctionsCompiler({
|
|
65
65
|
imports: P,
|
|
66
66
|
name: f,
|
|
67
67
|
args: y,
|
|
@@ -107,4 +107,4 @@ var l = createGenerator("js", (t)=>{
|
|
|
107
107
|
};
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
export { areEqualTranslationsValues, l as default,
|
|
110
|
+
export { areEqualTranslationsValues, l as default, getTFunctionBodyWithLocales, getTFunctions, getTranslationValueOutput };
|
|
@@ -25,7 +25,7 @@ const tInterpolateParams = ({ start: t, end: r })=>new functions.FunctionsCompil
|
|
|
25
25
|
/${helpers.escapeEachChar(t)}(.*?)${helpers.escapeEachChar(r)}/g,
|
|
26
26
|
(_, key) =>
|
|
27
27
|
params[key.trim()${"ts" === e ? " as keyof typeof params" : ""}] + "",
|
|
28
|
-
) : value
|
|
28
|
+
) : value`
|
|
29
29
|
});
|
|
30
30
|
var d = createAdapter.createGenerator("js", (t)=>{
|
|
31
31
|
let { options: e } = t, { dynamicDelimiters: a } = e.translations.tokens;
|
|
@@ -21,7 +21,7 @@ const tInterpolateParams = ({ start: t, end: r })=>new FunctionsCompiler({
|
|
|
21
21
|
/${escapeEachChar(t)}(.*?)${escapeEachChar(r)}/g,
|
|
22
22
|
(_, key) =>
|
|
23
23
|
params[key.trim()${"ts" === e ? " as keyof typeof params" : ""}] + "",
|
|
24
|
-
) : value
|
|
24
|
+
) : value`
|
|
25
25
|
});
|
|
26
26
|
var d = createGenerator("js", (t)=>{
|
|
27
27
|
let { options: e } = t, { dynamicDelimiters: a } = e.translations.tokens;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
3
5
|
var utils = require('@koine/utils');
|
|
4
6
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
5
7
|
var functions = require('../../compiler/functions.cjs.js');
|
|
6
8
|
var imports = require('../../compiler/imports.cjs.js');
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
const getToFunctionBodyWithLocales = (t, o)=>{
|
|
9
11
|
let e = "";
|
|
10
12
|
for(let a in o){
|
|
11
13
|
let r = o[a];
|
|
12
14
|
a !== t && r !== o[t] && (e += `locale === "${a}" ? "${r}" : `);
|
|
13
15
|
}
|
|
14
16
|
return e + ('"' + o[t]) + '"';
|
|
15
|
-
}
|
|
17
|
+
};
|
|
18
|
+
let n = {
|
|
16
19
|
formatTo: new imports.ImportsCompiler({
|
|
17
20
|
path: "formatTo",
|
|
18
21
|
named: [
|
|
@@ -30,44 +33,42 @@ let n = (t, o)=>{
|
|
|
30
33
|
}
|
|
31
34
|
]
|
|
32
35
|
})
|
|
33
|
-
},
|
|
34
|
-
let { defaultLocale:
|
|
35
|
-
for(let r in
|
|
36
|
-
let
|
|
37
|
-
|
|
36
|
+
}, l = (e, r)=>{
|
|
37
|
+
let { defaultLocale: l, locales: s, fnPrefix: i } = r, d = [], u = 1 === s.length, m = new Set();
|
|
38
|
+
for(let r in m.add(n.formatTo), m.add(n.types), e.byId){
|
|
39
|
+
let s = "", { pathnames: m, params: c } = e.byId[r], p = `${i}${utils.changeCaseSnake(r)}`, f = `I18n.RouteParams["${r}"]`, I = [];
|
|
40
|
+
c && I.push({
|
|
38
41
|
name: "params",
|
|
39
|
-
type:
|
|
42
|
+
type: f,
|
|
40
43
|
optional: !1
|
|
41
|
-
}),
|
|
44
|
+
}), I.push({
|
|
42
45
|
name: "locale",
|
|
43
46
|
type: "I18n.Locale",
|
|
44
47
|
optional: !0
|
|
45
48
|
});
|
|
46
|
-
let
|
|
47
|
-
utils.isString(
|
|
49
|
+
let g = u ? '""' : "locale", R = c ? ", params" : "";
|
|
50
|
+
utils.isString(m) ? s += `formatTo(${g}, "${m}"${R});` : s += `formatTo(${g}, ${getToFunctionBodyWithLocales(l, m)}${R});`, d.push(new functions.FunctionsCompiler({
|
|
48
51
|
imports: [
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
n.formatTo,
|
|
53
|
+
n.types
|
|
51
54
|
],
|
|
52
|
-
name:
|
|
53
|
-
args:
|
|
54
|
-
body:
|
|
55
|
+
name: p,
|
|
56
|
+
args: I,
|
|
57
|
+
body: s
|
|
55
58
|
}));
|
|
56
59
|
}
|
|
57
60
|
return {
|
|
58
|
-
functions:
|
|
59
|
-
|
|
60
|
-
allImports: c
|
|
61
|
+
functions: d,
|
|
62
|
+
allImports: m
|
|
61
63
|
};
|
|
62
|
-
},
|
|
63
|
-
let
|
|
64
|
+
}, s = ({ config: t, routes: o, options: { routes: { fnsPrefix: e }, adapter: { modularized: n } } })=>{
|
|
65
|
+
let s = e || n ? "$to_" : "", { functions: i, allImports: d } = l(o, {
|
|
64
66
|
defaultLocale: t.defaultLocale,
|
|
65
67
|
locales: t.locales,
|
|
66
|
-
|
|
67
|
-
modularized: n
|
|
68
|
+
fnPrefix: s
|
|
68
69
|
});
|
|
69
|
-
return n ?
|
|
70
|
-
dir:
|
|
70
|
+
return n ? i.reduce((t, o)=>(t[o.name] = {
|
|
71
|
+
dir: s.replace(/_*$/, ""),
|
|
71
72
|
name: o.name,
|
|
72
73
|
ext: "ts",
|
|
73
74
|
index: !0,
|
|
@@ -84,7 +85,7 @@ let n = (t, o)=>{
|
|
|
84
85
|
index: !0,
|
|
85
86
|
content: ()=>"" + (imports.ImportsCompiler.outMany("ts", d, {
|
|
86
87
|
folderUp: 0
|
|
87
|
-
}) + functions.FunctionsCompiler.outMany("ts",
|
|
88
|
+
}) + functions.FunctionsCompiler.outMany("ts", i, {
|
|
88
89
|
imports: !1,
|
|
89
90
|
exports: "named"
|
|
90
91
|
}))
|
|
@@ -94,7 +95,7 @@ let n = (t, o)=>{
|
|
|
94
95
|
var u = createAdapter.createGenerator("js", (t)=>{
|
|
95
96
|
let { options: { routes: { tokens: { idDelimiter: o } } }, routes: { dynamicRoutes: e, staticRoutes: a } } = t;
|
|
96
97
|
return {
|
|
97
|
-
...
|
|
98
|
+
...s(t),
|
|
98
99
|
to: {
|
|
99
100
|
name: "to",
|
|
100
101
|
ext: "ts",
|
|
@@ -203,4 +204,5 @@ export default toSpa;
|
|
|
203
204
|
};
|
|
204
205
|
});
|
|
205
206
|
|
|
206
|
-
|
|
207
|
+
exports.default = u;
|
|
208
|
+
exports.getToFunctionBodyWithLocales = getToFunctionBodyWithLocales;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { I18nCompiler } from "../../compiler/types";
|
|
2
|
+
export declare const getToFunctionBodyWithLocales: (defaultLocale: string, perLocaleValues: Record<string, string>) => string;
|
|
2
3
|
declare const _default: (data: I18nCompiler.DataCode<"js">) => {
|
|
3
4
|
to: {
|
|
4
5
|
name: string;
|
|
@@ -3,14 +3,15 @@ import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
|
3
3
|
import { FunctionsCompiler } from '../../compiler/functions.esm.js';
|
|
4
4
|
import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const getToFunctionBodyWithLocales = (t, o)=>{
|
|
7
7
|
let e = "";
|
|
8
8
|
for(let a in o){
|
|
9
9
|
let r = o[a];
|
|
10
10
|
a !== t && r !== o[t] && (e += `locale === "${a}" ? "${r}" : `);
|
|
11
11
|
}
|
|
12
12
|
return e + ('"' + o[t]) + '"';
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
|
+
let n = {
|
|
14
15
|
formatTo: new ImportsCompiler({
|
|
15
16
|
path: "formatTo",
|
|
16
17
|
named: [
|
|
@@ -28,44 +29,42 @@ let n = (t, o)=>{
|
|
|
28
29
|
}
|
|
29
30
|
]
|
|
30
31
|
})
|
|
31
|
-
},
|
|
32
|
-
let { defaultLocale:
|
|
33
|
-
for(let r in
|
|
34
|
-
let
|
|
35
|
-
|
|
32
|
+
}, l = (e, r)=>{
|
|
33
|
+
let { defaultLocale: l, locales: s, fnPrefix: i } = r, d = [], u = 1 === s.length, m = new Set();
|
|
34
|
+
for(let r in m.add(n.formatTo), m.add(n.types), e.byId){
|
|
35
|
+
let s = "", { pathnames: m, params: c } = e.byId[r], p = `${i}${changeCaseSnake(r)}`, f = `I18n.RouteParams["${r}"]`, I = [];
|
|
36
|
+
c && I.push({
|
|
36
37
|
name: "params",
|
|
37
|
-
type:
|
|
38
|
+
type: f,
|
|
38
39
|
optional: !1
|
|
39
|
-
}),
|
|
40
|
+
}), I.push({
|
|
40
41
|
name: "locale",
|
|
41
42
|
type: "I18n.Locale",
|
|
42
43
|
optional: !0
|
|
43
44
|
});
|
|
44
|
-
let
|
|
45
|
-
isString(
|
|
45
|
+
let g = u ? '""' : "locale", R = c ? ", params" : "";
|
|
46
|
+
isString(m) ? s += `formatTo(${g}, "${m}"${R});` : s += `formatTo(${g}, ${getToFunctionBodyWithLocales(l, m)}${R});`, d.push(new FunctionsCompiler({
|
|
46
47
|
imports: [
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
n.formatTo,
|
|
49
|
+
n.types
|
|
49
50
|
],
|
|
50
|
-
name:
|
|
51
|
-
args:
|
|
52
|
-
body:
|
|
51
|
+
name: p,
|
|
52
|
+
args: I,
|
|
53
|
+
body: s
|
|
53
54
|
}));
|
|
54
55
|
}
|
|
55
56
|
return {
|
|
56
|
-
functions:
|
|
57
|
-
|
|
58
|
-
allImports: c
|
|
57
|
+
functions: d,
|
|
58
|
+
allImports: m
|
|
59
59
|
};
|
|
60
|
-
},
|
|
61
|
-
let
|
|
60
|
+
}, s = ({ config: t, routes: o, options: { routes: { fnsPrefix: e }, adapter: { modularized: n } } })=>{
|
|
61
|
+
let s = e || n ? "$to_" : "", { functions: i, allImports: d } = l(o, {
|
|
62
62
|
defaultLocale: t.defaultLocale,
|
|
63
63
|
locales: t.locales,
|
|
64
|
-
|
|
65
|
-
modularized: n
|
|
64
|
+
fnPrefix: s
|
|
66
65
|
});
|
|
67
|
-
return n ?
|
|
68
|
-
dir:
|
|
66
|
+
return n ? i.reduce((t, o)=>(t[o.name] = {
|
|
67
|
+
dir: s.replace(/_*$/, ""),
|
|
69
68
|
name: o.name,
|
|
70
69
|
ext: "ts",
|
|
71
70
|
index: !0,
|
|
@@ -82,7 +81,7 @@ let n = (t, o)=>{
|
|
|
82
81
|
index: !0,
|
|
83
82
|
content: ()=>"" + (ImportsCompiler.outMany("ts", d, {
|
|
84
83
|
folderUp: 0
|
|
85
|
-
}) + FunctionsCompiler.outMany("ts",
|
|
84
|
+
}) + FunctionsCompiler.outMany("ts", i, {
|
|
86
85
|
imports: !1,
|
|
87
86
|
exports: "named"
|
|
88
87
|
}))
|
|
@@ -92,7 +91,7 @@ let n = (t, o)=>{
|
|
|
92
91
|
var u = createGenerator("js", (t)=>{
|
|
93
92
|
let { options: { routes: { tokens: { idDelimiter: o } } }, routes: { dynamicRoutes: e, staticRoutes: a } } = t;
|
|
94
93
|
return {
|
|
95
|
-
...
|
|
94
|
+
...s(t),
|
|
96
95
|
to: {
|
|
97
96
|
name: "to",
|
|
98
97
|
ext: "ts",
|
|
@@ -201,4 +200,4 @@ export default toSpa;
|
|
|
201
200
|
};
|
|
202
201
|
});
|
|
203
202
|
|
|
204
|
-
export { u as default };
|
|
203
|
+
export { u as default, getToFunctionBodyWithLocales };
|
package/adapter-js/index.cjs.js
CHANGED
|
@@ -30,7 +30,7 @@ const adapterJs = createAdapter.createAdapter({
|
|
|
30
30
|
config,
|
|
31
31
|
createT,
|
|
32
32
|
defaultI18nMetadata,
|
|
33
|
-
formatTo,
|
|
33
|
+
formatTo.default,
|
|
34
34
|
formatUrl,
|
|
35
35
|
getI18nDictionaries,
|
|
36
36
|
getI18nMetadata,
|
|
@@ -41,7 +41,7 @@ const adapterJs = createAdapter.createAdapter({
|
|
|
41
41
|
t.default,
|
|
42
42
|
tInterpolateParams.default,
|
|
43
43
|
tPluralise.default,
|
|
44
|
-
to,
|
|
44
|
+
to.default,
|
|
45
45
|
types
|
|
46
46
|
],
|
|
47
47
|
getTransformers: ()=>({})
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
var redirects = require('../redirects.cjs.js');
|
|
5
5
|
|
|
6
|
-
var t = createAdapter.createGenerator("next", (
|
|
7
|
-
let { config:
|
|
6
|
+
var t = createAdapter.createGenerator("next", (r)=>{
|
|
7
|
+
let { config: i, options: o, routes: d } = r, n = JSON.stringify(redirects.generateRedirects(i, o.routes, d.byId), null, 2);
|
|
8
8
|
return {
|
|
9
9
|
nextRedirects: {
|
|
10
|
+
dir: createAdapter.createGenerator.dirs.internal,
|
|
10
11
|
name: "next-redirects",
|
|
11
12
|
ext: "js",
|
|
12
13
|
index: !1,
|
|
@@ -14,7 +15,7 @@ var t = createAdapter.createGenerator("next", (e)=>{
|
|
|
14
15
|
/**
|
|
15
16
|
* @type {import("next/dist/lib/load-custom-routes").Redirect[]}
|
|
16
17
|
*/
|
|
17
|
-
module.exports = ${
|
|
18
|
+
module.exports = ${n}
|
|
18
19
|
`
|
|
19
20
|
}
|
|
20
21
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
import { generateRedirects } from '../redirects.esm.js';
|
|
3
3
|
|
|
4
|
-
var t = createGenerator("next", (
|
|
5
|
-
let { config:
|
|
4
|
+
var t = createGenerator("next", (r)=>{
|
|
5
|
+
let { config: i, options: o, routes: d } = r, n = JSON.stringify(generateRedirects(i, o.routes, d.byId), null, 2);
|
|
6
6
|
return {
|
|
7
7
|
nextRedirects: {
|
|
8
|
+
dir: createGenerator.dirs.internal,
|
|
8
9
|
name: "next-redirects",
|
|
9
10
|
ext: "js",
|
|
10
11
|
index: !1,
|
|
@@ -12,7 +13,7 @@ var t = createGenerator("next", (e)=>{
|
|
|
12
13
|
/**
|
|
13
14
|
* @type {import("next/dist/lib/load-custom-routes").Redirect[]}
|
|
14
15
|
*/
|
|
15
|
-
module.exports = ${
|
|
16
|
+
module.exports = ${n}
|
|
16
17
|
`
|
|
17
18
|
}
|
|
18
19
|
};
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
var rewrites = require('../rewrites.cjs.js');
|
|
5
5
|
|
|
6
|
-
var o = createAdapter.createGenerator("next", (
|
|
7
|
-
let { config:
|
|
6
|
+
var o = createAdapter.createGenerator("next", (r)=>{
|
|
7
|
+
let { config: i, routes: o, options: n } = r, s = JSON.stringify(rewrites.generateRewrites(i, n.routes, o.byId), null, 2);
|
|
8
8
|
return {
|
|
9
9
|
nextRewrites: {
|
|
10
|
+
dir: createAdapter.createGenerator.dirs.internal,
|
|
10
11
|
name: "next-rewrites",
|
|
11
12
|
ext: "js",
|
|
12
13
|
index: !1,
|
|
@@ -14,7 +15,7 @@ var o = createAdapter.createGenerator("next", (e)=>{
|
|
|
14
15
|
/**
|
|
15
16
|
* @type {import("next/dist/lib/load-custom-routes").Rewrite[]}
|
|
16
17
|
*/
|
|
17
|
-
module.exports = ${
|
|
18
|
+
module.exports = ${s}
|
|
18
19
|
`
|
|
19
20
|
}
|
|
20
21
|
};
|