@koine/i18n 2.0.0-beta.154 → 2.0.0-beta.155
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 +13 -3
- package/adapter-js/generators/formatTo.esm.js +13 -3
- package/adapter-js/generators/t.cjs.js +36 -36
- package/adapter-js/generators/t.d.ts +2 -2
- package/adapter-js/generators/t.esm.js +36 -36
- package/adapter-js/generators/tInterpolateParams.cjs.js +17 -8
- package/adapter-js/generators/tInterpolateParams.esm.js +17 -8
- package/adapter-js/generators/tInterpolateParamsDeep.cjs.js +10 -1
- package/adapter-js/generators/tInterpolateParamsDeep.esm.js +10 -1
- package/adapter-js/generators/tPluralise.cjs.js +11 -1
- package/adapter-js/generators/tPluralise.esm.js +11 -1
- package/adapter-js/generators/to.cjs.js +14 -15
- package/adapter-js/generators/to.d.ts +2 -2
- package/adapter-js/generators/to.esm.js +14 -15
- package/adapter-next/generators/webpack-define.cjs.js +36 -28
- package/adapter-next/generators/webpack-define.esm.js +36 -28
- package/adapter-next-translate/index.d.ts +18 -4
- package/compiler/functions.cjs.js +34 -23
- package/compiler/functions.d.ts +46 -8
- package/compiler/functions.esm.js +34 -23
- package/package.json +3 -3
|
@@ -5,12 +5,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
6
6
|
var functions = require('../../compiler/functions.cjs.js');
|
|
7
7
|
|
|
8
|
-
const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t },
|
|
8
|
+
const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, n)=>new functions.FunctionsCompiler({
|
|
9
9
|
imports: [],
|
|
10
10
|
comment: {
|
|
11
11
|
internal: !0
|
|
12
12
|
},
|
|
13
13
|
name: "formatTo",
|
|
14
|
+
generics: [
|
|
15
|
+
{
|
|
16
|
+
name: "T",
|
|
17
|
+
type: "string"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
14
20
|
args: [
|
|
15
21
|
{
|
|
16
22
|
name: "locale",
|
|
@@ -19,7 +25,7 @@ const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, o)=>new funct
|
|
|
19
25
|
},
|
|
20
26
|
{
|
|
21
27
|
name: "pathname",
|
|
22
|
-
type: "
|
|
28
|
+
type: "T",
|
|
23
29
|
optional: !1
|
|
24
30
|
},
|
|
25
31
|
{
|
|
@@ -28,9 +34,13 @@ const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, o)=>new funct
|
|
|
28
34
|
optional: !0
|
|
29
35
|
}
|
|
30
36
|
],
|
|
37
|
+
returns: {
|
|
38
|
+
name: "T",
|
|
39
|
+
explicit: !0
|
|
40
|
+
},
|
|
31
41
|
body: ({ format: a })=>`
|
|
32
42
|
locale = locale || "${e}";
|
|
33
|
-
${
|
|
43
|
+
${n ? `
|
|
34
44
|
if (process.env["NODE_ENV"] === "development") {
|
|
35
45
|
if (params) {
|
|
36
46
|
pathname.replace(/\\[(.*?)\\]/g, (_, dynamicKey) => {
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
import { FunctionsCompiler } from '../../compiler/functions.esm.js';
|
|
3
3
|
|
|
4
|
-
const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t },
|
|
4
|
+
const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, n)=>new FunctionsCompiler({
|
|
5
5
|
imports: [],
|
|
6
6
|
comment: {
|
|
7
7
|
internal: !0
|
|
8
8
|
},
|
|
9
9
|
name: "formatTo",
|
|
10
|
+
generics: [
|
|
11
|
+
{
|
|
12
|
+
name: "T",
|
|
13
|
+
type: "string"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
10
16
|
args: [
|
|
11
17
|
{
|
|
12
18
|
name: "locale",
|
|
@@ -15,7 +21,7 @@ const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, o)=>new Funct
|
|
|
15
21
|
},
|
|
16
22
|
{
|
|
17
23
|
name: "pathname",
|
|
18
|
-
type: "
|
|
24
|
+
type: "T",
|
|
19
25
|
optional: !1
|
|
20
26
|
},
|
|
21
27
|
{
|
|
@@ -24,9 +30,13 @@ const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, o)=>new Funct
|
|
|
24
30
|
optional: !0
|
|
25
31
|
}
|
|
26
32
|
],
|
|
33
|
+
returns: {
|
|
34
|
+
name: "T",
|
|
35
|
+
explicit: !0
|
|
36
|
+
},
|
|
27
37
|
body: ({ format: a })=>`
|
|
28
38
|
locale = locale || "${e}";
|
|
29
|
-
${
|
|
39
|
+
${n ? `
|
|
30
40
|
if (process.env["NODE_ENV"] === "development") {
|
|
31
41
|
if (params) {
|
|
32
42
|
pathname.replace(/\\[(.*?)\\]/g, (_, dynamicKey) => {
|
|
@@ -10,28 +10,31 @@ var imports = require('../../compiler/imports.cjs.js');
|
|
|
10
10
|
var types = require('./types.cjs.js');
|
|
11
11
|
|
|
12
12
|
let c = "count";
|
|
13
|
-
function getTFunction(t,
|
|
14
|
-
let { params:
|
|
15
|
-
let { values:
|
|
13
|
+
function getTFunction(t, r) {
|
|
14
|
+
let { params: n, plural: o } = t, { body: l, imports: s } = function(t, r) {
|
|
15
|
+
let { values: n, params: o, plural: l, typeValue: s, equalValues: i } = t, { defaultLocale: m, single: u } = r, y = !u && !i, P = [
|
|
16
16
|
d.types
|
|
17
|
-
]
|
|
18
|
-
P
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
|
|
17
|
+
];
|
|
18
|
+
return l && P.push(d.tPluralise), o && ("Primitive" === s ? P.push(d.tInterpolateParams) : ("Array" === s || "Object" === s) && P.push(d.tInterpolateParamsDeep)), {
|
|
19
|
+
imports: P,
|
|
20
|
+
body: (t)=>{
|
|
21
|
+
let r = y ? "locale = locale || global." + helpers.GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
22
|
+
r += "return ";
|
|
23
|
+
let i = "";
|
|
24
|
+
return utils.isPrimitive(n) ? i += f(n, t) : i += function(t, r, n, a) {
|
|
25
|
+
let o = "";
|
|
26
|
+
if (n) for(let n in r){
|
|
27
|
+
let l = r[n];
|
|
28
|
+
n === t || utils.areEqual(l, r[t]) || (o += `locale === "${n}" ? ${f(l, a)} : `);
|
|
29
|
+
}
|
|
30
|
+
return o + f(r[t], a);
|
|
31
|
+
}(m, n, y, t), l && (i = `tPluralise(${i}, params.${c})`), o && ("Primitive" === s ? i = `tInterpolateParams(${i}, params)` : ("Array" === s || "Object" === s) && (i = `tInterpolateParamsDeep(${i}, params)`)), r + i;
|
|
25
32
|
}
|
|
26
|
-
return a + f(n[t]);
|
|
27
|
-
}(m, r, y), l && (h.push(d.tPluralise), $ = `tPluralise(${$}, params.${c})`), o && ("Primitive" === s ? (h.push(d.tInterpolateParams), $ = `tInterpolateParams(${$}, params)`) : ("Array" === s || "Object" === s) && (h.push(d.tInterpolateParamsDeep), $ = `tInterpolateParamsDeep(${$}, params)`)), {
|
|
28
|
-
body: P + $,
|
|
29
|
-
imports: h
|
|
30
33
|
};
|
|
31
|
-
}(t,
|
|
32
|
-
...
|
|
34
|
+
}(t, r), m = [], u = n ? o ? {
|
|
35
|
+
...n,
|
|
33
36
|
[c]: "number"
|
|
34
|
-
} :
|
|
37
|
+
} : n : o ? {
|
|
35
38
|
[c]: "number"
|
|
36
39
|
} : null;
|
|
37
40
|
return u && m.push({
|
|
@@ -51,8 +54,9 @@ function getTFunction(t, n) {
|
|
|
51
54
|
imports: s
|
|
52
55
|
};
|
|
53
56
|
}
|
|
54
|
-
function f(e) {
|
|
55
|
-
|
|
57
|
+
function f(e, { format: a }) {
|
|
58
|
+
let l = "ts" === a ? " as const" : "";
|
|
59
|
+
return utils.isString(e) || utils.isNumber(e) ? `"${e}"${l}` : utils.isBoolean(e) ? `${e}` : utils.isArray(e) ? JSON.stringify(e) + l : `(${JSON.stringify(e)}${l})`;
|
|
56
60
|
}
|
|
57
61
|
let d = {
|
|
58
62
|
types: types.getImportTypes(),
|
|
@@ -81,36 +85,32 @@ let d = {
|
|
|
81
85
|
]
|
|
82
86
|
})
|
|
83
87
|
}, y = (e, t)=>{
|
|
84
|
-
let
|
|
85
|
-
for(let
|
|
86
|
-
let
|
|
87
|
-
|
|
88
|
-
imports:
|
|
89
|
-
name:
|
|
90
|
-
args:
|
|
91
|
-
body:
|
|
88
|
+
let n = [], a = new Set();
|
|
89
|
+
for(let r in a.add(d.types), e){
|
|
90
|
+
let o = e[r], { imports: l, args: p, body: i } = getTFunction(o, t);
|
|
91
|
+
l.forEach((e)=>a.add(e)), n.push(new functions.FunctionsCompiler({
|
|
92
|
+
imports: l,
|
|
93
|
+
name: o.fnName,
|
|
94
|
+
args: p,
|
|
95
|
+
body: i,
|
|
92
96
|
comment: {
|
|
93
97
|
tags: [
|
|
94
98
|
{
|
|
95
99
|
key: "i18nKey",
|
|
96
|
-
val: `\`${
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
key: "i18nDefaultValue",
|
|
100
|
-
val: `\`${JSON.stringify(l.values[n])}\``
|
|
100
|
+
val: `\`${o.fullKey}\``
|
|
101
101
|
}
|
|
102
102
|
]
|
|
103
103
|
}
|
|
104
104
|
}));
|
|
105
105
|
}
|
|
106
106
|
return {
|
|
107
|
-
functions:
|
|
107
|
+
functions: n,
|
|
108
108
|
allImports: a
|
|
109
109
|
};
|
|
110
110
|
};
|
|
111
111
|
var c$1 = createAdapter.createGenerator("js", (e)=>{
|
|
112
|
-
let { config: t, options: { translations:
|
|
113
|
-
return
|
|
112
|
+
let { config: t, options: { translations: r, adapter: { modularize: n } }, translations: a } = e, { dir: o } = r.functions, { functions: l, allImports: p } = y(a, t);
|
|
113
|
+
return n ? l.reduce((e, t)=>(e[t.name] = {
|
|
114
114
|
dir: o,
|
|
115
115
|
name: t.name,
|
|
116
116
|
ext: "ts",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type FunctionsCompilerDataArg } from "../../compiler/functions";
|
|
1
|
+
import { type FunctionsCompilerBodyOptions, type FunctionsCompilerDataArg } from "../../compiler/functions";
|
|
2
2
|
import { ImportsCompiler } from "../../compiler/imports";
|
|
3
3
|
import type { I18nCompiler } from "../../compiler/types";
|
|
4
4
|
export declare function getTFunction(translation: I18nCompiler.DataTranslation, options: Pick<I18nCompiler.Config, "defaultLocale" | "single">): {
|
|
5
|
-
body: string;
|
|
5
|
+
body: (functionBodyOpts: FunctionsCompilerBodyOptions) => string;
|
|
6
6
|
args: FunctionsCompilerDataArg[];
|
|
7
7
|
imports: ImportsCompiler[];
|
|
8
8
|
};
|
|
@@ -6,28 +6,31 @@ import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
|
6
6
|
import { getImportTypes } from './types.esm.js';
|
|
7
7
|
|
|
8
8
|
let c = "count";
|
|
9
|
-
function getTFunction(t,
|
|
10
|
-
let { params:
|
|
11
|
-
let { values:
|
|
9
|
+
function getTFunction(t, r) {
|
|
10
|
+
let { params: n, plural: o } = t, { body: l, imports: s } = function(t, r) {
|
|
11
|
+
let { values: n, params: o, plural: l, typeValue: s, equalValues: i } = t, { defaultLocale: m, single: u } = r, y = !u && !i, P = [
|
|
12
12
|
d.types
|
|
13
|
-
]
|
|
14
|
-
P
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
|
|
13
|
+
];
|
|
14
|
+
return l && P.push(d.tPluralise), o && ("Primitive" === s ? P.push(d.tInterpolateParams) : ("Array" === s || "Object" === s) && P.push(d.tInterpolateParamsDeep)), {
|
|
15
|
+
imports: P,
|
|
16
|
+
body: (t)=>{
|
|
17
|
+
let r = y ? "locale = locale || global." + GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
18
|
+
r += "return ";
|
|
19
|
+
let i = "";
|
|
20
|
+
return isPrimitive(n) ? i += f(n, t) : i += function(t, r, n, a) {
|
|
21
|
+
let o = "";
|
|
22
|
+
if (n) for(let n in r){
|
|
23
|
+
let l = r[n];
|
|
24
|
+
n === t || areEqual(l, r[t]) || (o += `locale === "${n}" ? ${f(l, a)} : `);
|
|
25
|
+
}
|
|
26
|
+
return o + f(r[t], a);
|
|
27
|
+
}(m, n, y, t), l && (i = `tPluralise(${i}, params.${c})`), o && ("Primitive" === s ? i = `tInterpolateParams(${i}, params)` : ("Array" === s || "Object" === s) && (i = `tInterpolateParamsDeep(${i}, params)`)), r + i;
|
|
21
28
|
}
|
|
22
|
-
return a + f(n[t]);
|
|
23
|
-
}(m, r, y), l && (h.push(d.tPluralise), $ = `tPluralise(${$}, params.${c})`), o && ("Primitive" === s ? (h.push(d.tInterpolateParams), $ = `tInterpolateParams(${$}, params)`) : ("Array" === s || "Object" === s) && (h.push(d.tInterpolateParamsDeep), $ = `tInterpolateParamsDeep(${$}, params)`)), {
|
|
24
|
-
body: P + $,
|
|
25
|
-
imports: h
|
|
26
29
|
};
|
|
27
|
-
}(t,
|
|
28
|
-
...
|
|
30
|
+
}(t, r), m = [], u = n ? o ? {
|
|
31
|
+
...n,
|
|
29
32
|
[c]: "number"
|
|
30
|
-
} :
|
|
33
|
+
} : n : o ? {
|
|
31
34
|
[c]: "number"
|
|
32
35
|
} : null;
|
|
33
36
|
return u && m.push({
|
|
@@ -47,8 +50,9 @@ function getTFunction(t, n) {
|
|
|
47
50
|
imports: s
|
|
48
51
|
};
|
|
49
52
|
}
|
|
50
|
-
function f(e) {
|
|
51
|
-
|
|
53
|
+
function f(e, { format: a }) {
|
|
54
|
+
let l = "ts" === a ? " as const" : "";
|
|
55
|
+
return isString(e) || isNumber(e) ? `"${e}"${l}` : isBoolean(e) ? `${e}` : isArray(e) ? JSON.stringify(e) + l : `(${JSON.stringify(e)}${l})`;
|
|
52
56
|
}
|
|
53
57
|
let d = {
|
|
54
58
|
types: getImportTypes(),
|
|
@@ -77,36 +81,32 @@ let d = {
|
|
|
77
81
|
]
|
|
78
82
|
})
|
|
79
83
|
}, y = (e, t)=>{
|
|
80
|
-
let
|
|
81
|
-
for(let
|
|
82
|
-
let
|
|
83
|
-
|
|
84
|
-
imports:
|
|
85
|
-
name:
|
|
86
|
-
args:
|
|
87
|
-
body:
|
|
84
|
+
let n = [], a = new Set();
|
|
85
|
+
for(let r in a.add(d.types), e){
|
|
86
|
+
let o = e[r], { imports: l, args: p, body: i } = getTFunction(o, t);
|
|
87
|
+
l.forEach((e)=>a.add(e)), n.push(new FunctionsCompiler({
|
|
88
|
+
imports: l,
|
|
89
|
+
name: o.fnName,
|
|
90
|
+
args: p,
|
|
91
|
+
body: i,
|
|
88
92
|
comment: {
|
|
89
93
|
tags: [
|
|
90
94
|
{
|
|
91
95
|
key: "i18nKey",
|
|
92
|
-
val: `\`${
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
key: "i18nDefaultValue",
|
|
96
|
-
val: `\`${JSON.stringify(l.values[n])}\``
|
|
96
|
+
val: `\`${o.fullKey}\``
|
|
97
97
|
}
|
|
98
98
|
]
|
|
99
99
|
}
|
|
100
100
|
}));
|
|
101
101
|
}
|
|
102
102
|
return {
|
|
103
|
-
functions:
|
|
103
|
+
functions: n,
|
|
104
104
|
allImports: a
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
107
|
var c$1 = createGenerator("js", (e)=>{
|
|
108
|
-
let { config: t, options: { translations:
|
|
109
|
-
return
|
|
108
|
+
let { config: t, options: { translations: r, adapter: { modularize: n } }, translations: a } = e, { dir: o } = r.functions, { functions: l, allImports: p } = y(a, t);
|
|
109
|
+
return n ? l.reduce((e, t)=>(e[t.name] = {
|
|
110
110
|
dir: o,
|
|
111
111
|
name: t.name,
|
|
112
112
|
ext: "ts",
|
|
@@ -6,16 +6,22 @@ var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
|
6
6
|
var functions = require('../../compiler/functions.cjs.js');
|
|
7
7
|
var helpers = require('../../compiler/helpers.cjs.js');
|
|
8
8
|
|
|
9
|
-
const tInterpolateParams = ({ start:
|
|
9
|
+
const tInterpolateParams = ({ start: e, end: a })=>new functions.FunctionsCompiler({
|
|
10
10
|
imports: [],
|
|
11
11
|
comment: {
|
|
12
12
|
internal: !0
|
|
13
13
|
},
|
|
14
14
|
name: "tInterpolateParams",
|
|
15
|
+
generics: [
|
|
16
|
+
{
|
|
17
|
+
name: "T",
|
|
18
|
+
type: "string | number | boolean"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
15
21
|
args: [
|
|
16
22
|
{
|
|
17
23
|
name: "value",
|
|
18
|
-
type: "
|
|
24
|
+
type: "T",
|
|
19
25
|
optional: !1
|
|
20
26
|
},
|
|
21
27
|
{
|
|
@@ -24,22 +30,25 @@ const tInterpolateParams = ({ start: t, end: r })=>new functions.FunctionsCompil
|
|
|
24
30
|
optional: !0
|
|
25
31
|
}
|
|
26
32
|
],
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
returns: {
|
|
34
|
+
name: "T"
|
|
35
|
+
},
|
|
36
|
+
body: ({ format: t })=>`params ? value.replace(
|
|
37
|
+
/${helpers.escapeEachChar(e)}(.*?)${helpers.escapeEachChar(a)}/g,
|
|
29
38
|
(_, key) =>
|
|
30
|
-
params[key.trim()${"ts" ===
|
|
39
|
+
params[key.trim()${"ts" === t ? " as keyof typeof params" : ""}] + "",
|
|
31
40
|
) : value`,
|
|
32
41
|
implicitReturn: !0
|
|
33
42
|
});
|
|
34
|
-
var u = createAdapter.createGenerator("js", (
|
|
35
|
-
let { options:
|
|
43
|
+
var u = createAdapter.createGenerator("js", (t)=>{
|
|
44
|
+
let { options: r } = t, { dynamicDelimiters: a } = r.translations.tokens;
|
|
36
45
|
return {
|
|
37
46
|
tInterpolateParams: {
|
|
38
47
|
dir: createAdapter.createGenerator.dirs.internal,
|
|
39
48
|
name: "tInterpolateParams",
|
|
40
49
|
ext: "ts",
|
|
41
50
|
index: !1,
|
|
42
|
-
content: ()=>tInterpolateParams(
|
|
51
|
+
content: ()=>tInterpolateParams(a).$out("ts", {
|
|
43
52
|
imports: !1,
|
|
44
53
|
exports: "named"
|
|
45
54
|
})
|
|
@@ -2,16 +2,22 @@ import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
|
2
2
|
import { FunctionsCompiler } from '../../compiler/functions.esm.js';
|
|
3
3
|
import { escapeEachChar } from '../../compiler/helpers.esm.js';
|
|
4
4
|
|
|
5
|
-
const tInterpolateParams = ({ start:
|
|
5
|
+
const tInterpolateParams = ({ start: e, end: a })=>new FunctionsCompiler({
|
|
6
6
|
imports: [],
|
|
7
7
|
comment: {
|
|
8
8
|
internal: !0
|
|
9
9
|
},
|
|
10
10
|
name: "tInterpolateParams",
|
|
11
|
+
generics: [
|
|
12
|
+
{
|
|
13
|
+
name: "T",
|
|
14
|
+
type: "string | number | boolean"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
11
17
|
args: [
|
|
12
18
|
{
|
|
13
19
|
name: "value",
|
|
14
|
-
type: "
|
|
20
|
+
type: "T",
|
|
15
21
|
optional: !1
|
|
16
22
|
},
|
|
17
23
|
{
|
|
@@ -20,22 +26,25 @@ const tInterpolateParams = ({ start: t, end: r })=>new FunctionsCompiler({
|
|
|
20
26
|
optional: !0
|
|
21
27
|
}
|
|
22
28
|
],
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
returns: {
|
|
30
|
+
name: "T"
|
|
31
|
+
},
|
|
32
|
+
body: ({ format: t })=>`params ? value.replace(
|
|
33
|
+
/${escapeEachChar(e)}(.*?)${escapeEachChar(a)}/g,
|
|
25
34
|
(_, key) =>
|
|
26
|
-
params[key.trim()${"ts" ===
|
|
35
|
+
params[key.trim()${"ts" === t ? " as keyof typeof params" : ""}] + "",
|
|
27
36
|
) : value`,
|
|
28
37
|
implicitReturn: !0
|
|
29
38
|
});
|
|
30
|
-
var u = createGenerator("js", (
|
|
31
|
-
let { options:
|
|
39
|
+
var u = createGenerator("js", (t)=>{
|
|
40
|
+
let { options: r } = t, { dynamicDelimiters: a } = r.translations.tokens;
|
|
32
41
|
return {
|
|
33
42
|
tInterpolateParams: {
|
|
34
43
|
dir: createGenerator.dirs.internal,
|
|
35
44
|
name: "tInterpolateParams",
|
|
36
45
|
ext: "ts",
|
|
37
46
|
index: !1,
|
|
38
|
-
content: ()=>tInterpolateParams(
|
|
47
|
+
content: ()=>tInterpolateParams(a).$out("ts", {
|
|
39
48
|
imports: !1,
|
|
40
49
|
exports: "named"
|
|
41
50
|
})
|
|
@@ -21,10 +21,16 @@ const tInterpolateParamsDeep = ()=>new functions.FunctionsCompiler({
|
|
|
21
21
|
internal: !0
|
|
22
22
|
},
|
|
23
23
|
name: "tInterpolateParamsDeep",
|
|
24
|
+
generics: [
|
|
25
|
+
{
|
|
26
|
+
name: "T",
|
|
27
|
+
type: "string | object | unknown[]"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
24
30
|
args: [
|
|
25
31
|
{
|
|
26
32
|
name: "value",
|
|
27
|
-
type: "
|
|
33
|
+
type: "T",
|
|
28
34
|
optional: !1
|
|
29
35
|
},
|
|
30
36
|
{
|
|
@@ -33,6 +39,9 @@ const tInterpolateParamsDeep = ()=>new functions.FunctionsCompiler({
|
|
|
33
39
|
optional: !0
|
|
34
40
|
}
|
|
35
41
|
],
|
|
42
|
+
returns: {
|
|
43
|
+
name: "T"
|
|
44
|
+
},
|
|
36
45
|
body: ()=>'if (Array.isArray(value)) { for (let i = 0; i < value.length; i++) { value[i] = tInterpolateParamsDeep(value[i], params); } } else if (typeof value === "object") { for (const key in value) { value[key] = tInterpolateParamsDeep(value[key], params); } } else { value = tInterpolateParams(value, params); } return value;'
|
|
37
46
|
});
|
|
38
47
|
var I = createAdapter.createGenerator("js", (t)=>({
|
|
@@ -17,10 +17,16 @@ const tInterpolateParamsDeep = ()=>new FunctionsCompiler({
|
|
|
17
17
|
internal: !0
|
|
18
18
|
},
|
|
19
19
|
name: "tInterpolateParamsDeep",
|
|
20
|
+
generics: [
|
|
21
|
+
{
|
|
22
|
+
name: "T",
|
|
23
|
+
type: "string | object | unknown[]"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
20
26
|
args: [
|
|
21
27
|
{
|
|
22
28
|
name: "value",
|
|
23
|
-
type: "
|
|
29
|
+
type: "T",
|
|
24
30
|
optional: !1
|
|
25
31
|
},
|
|
26
32
|
{
|
|
@@ -29,6 +35,9 @@ const tInterpolateParamsDeep = ()=>new FunctionsCompiler({
|
|
|
29
35
|
optional: !0
|
|
30
36
|
}
|
|
31
37
|
],
|
|
38
|
+
returns: {
|
|
39
|
+
name: "T"
|
|
40
|
+
},
|
|
32
41
|
body: ()=>'if (Array.isArray(value)) { for (let i = 0; i < value.length; i++) { value[i] = tInterpolateParamsDeep(value[i], params); } } else if (typeof value === "object") { for (const key in value) { value[key] = tInterpolateParamsDeep(value[key], params); } } else { value = tInterpolateParams(value, params); } return value;'
|
|
33
42
|
});
|
|
34
43
|
var I = createGenerator("js", (t)=>({
|
|
@@ -12,10 +12,16 @@ const tPluralise = ()=>new functions.FunctionsCompiler({
|
|
|
12
12
|
internal: !0
|
|
13
13
|
},
|
|
14
14
|
name: "tPluralise",
|
|
15
|
+
generics: [
|
|
16
|
+
{
|
|
17
|
+
name: "T",
|
|
18
|
+
type: "{ [pluralKey: string]: string | number | boolean }"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
15
21
|
args: [
|
|
16
22
|
{
|
|
17
23
|
name: "values",
|
|
18
|
-
type: "
|
|
24
|
+
type: "T",
|
|
19
25
|
optional: !1
|
|
20
26
|
},
|
|
21
27
|
{
|
|
@@ -24,6 +30,10 @@ const tPluralise = ()=>new functions.FunctionsCompiler({
|
|
|
24
30
|
optional: !1
|
|
25
31
|
}
|
|
26
32
|
],
|
|
33
|
+
returns: {
|
|
34
|
+
name: "T[keyof T]",
|
|
35
|
+
explicit: !0
|
|
36
|
+
},
|
|
27
37
|
body: 'values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"])',
|
|
28
38
|
implicitReturn: !0
|
|
29
39
|
});
|
|
@@ -8,10 +8,16 @@ const tPluralise = ()=>new FunctionsCompiler({
|
|
|
8
8
|
internal: !0
|
|
9
9
|
},
|
|
10
10
|
name: "tPluralise",
|
|
11
|
+
generics: [
|
|
12
|
+
{
|
|
13
|
+
name: "T",
|
|
14
|
+
type: "{ [pluralKey: string]: string | number | boolean }"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
11
17
|
args: [
|
|
12
18
|
{
|
|
13
19
|
name: "values",
|
|
14
|
-
type: "
|
|
20
|
+
type: "T",
|
|
15
21
|
optional: !1
|
|
16
22
|
},
|
|
17
23
|
{
|
|
@@ -20,6 +26,10 @@ const tPluralise = ()=>new FunctionsCompiler({
|
|
|
20
26
|
optional: !1
|
|
21
27
|
}
|
|
22
28
|
],
|
|
29
|
+
returns: {
|
|
30
|
+
name: "T[keyof T]",
|
|
31
|
+
explicit: !0
|
|
32
|
+
},
|
|
23
33
|
body: 'values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"])',
|
|
24
34
|
implicitReturn: !0
|
|
25
35
|
});
|
|
@@ -11,17 +11,20 @@ var types = require('./types.cjs.js');
|
|
|
11
11
|
|
|
12
12
|
function getToFunction(e, o) {
|
|
13
13
|
let { id: r, params: n } = e, l = function(e, o) {
|
|
14
|
-
let { params: r, pathnames: n, equalValues: l } = e, { defaultLocale: s, single: i } = o, u = i
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
let r =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
let { params: r, pathnames: n, equalValues: l } = e, { defaultLocale: s, single: i } = o, u = !i && !l, d = i ? '""' : "locale", m = r ? ", params" : "";
|
|
15
|
+
return (e)=>{
|
|
16
|
+
let o = u ? "locale = locale || global." + helpers.GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
17
|
+
o += "return ";
|
|
18
|
+
let r = "";
|
|
19
|
+
return utils.isString(n) ? r += `formatTo(${d}, "${n}"${m})` : r += `formatTo(${d}, ${function(t, e, { format: o }) {
|
|
20
|
+
let a = "ts" === o ? " as const" : "", r = "";
|
|
21
|
+
for(let o in e){
|
|
22
|
+
let n = e[o];
|
|
23
|
+
o !== t && n !== e[t] && (r += `locale === "${o}" ? "${n}"${a} : `);
|
|
24
|
+
}
|
|
25
|
+
return r + ('"' + e[t] + '"') + a;
|
|
26
|
+
}(s, n, e)}${m})`, o + r;
|
|
27
|
+
};
|
|
25
28
|
}(e, o), s = [];
|
|
26
29
|
return n && s.push({
|
|
27
30
|
name: "params",
|
|
@@ -71,10 +74,6 @@ var P = createAdapter.createGenerator("js", (t)=>{
|
|
|
71
74
|
{
|
|
72
75
|
key: "i18nRouteId",
|
|
73
76
|
val: `\`${n}\``
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
key: "i18nDefaultValue",
|
|
77
|
-
val: `\`"${r.pathnames[e.defaultLocale]}"\``
|
|
78
77
|
}
|
|
79
78
|
]
|
|
80
79
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type FunctionsCompilerDataArg } from "../../compiler/functions";
|
|
1
|
+
import { type FunctionsCompilerBodyOptions, type FunctionsCompilerDataArg } from "../../compiler/functions";
|
|
2
2
|
import type { I18nCompiler } from "../../compiler/types";
|
|
3
3
|
export declare function getToFunction(route: I18nCompiler.DataRoute, options: Pick<I18nCompiler.Config, "defaultLocale" | "single">): {
|
|
4
|
-
body: string;
|
|
4
|
+
body: (functionBodyOpts: FunctionsCompilerBodyOptions) => string;
|
|
5
5
|
args: FunctionsCompilerDataArg[];
|
|
6
6
|
};
|
|
7
7
|
declare const _default: (data: I18nCompiler.DataCode<"js">) => {
|