@koine/i18n 2.0.0-beta.166 → 2.0.0-beta.168
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 +1 -3
- package/adapter-js/generators/formatTo.esm.js +1 -3
- package/adapter-js/generators/t.cjs.js +49 -51
- package/adapter-js/generators/t.esm.js +49 -51
- package/adapter-js/generators/tInterpolateParamsDeep.cjs.js +1 -3
- package/adapter-js/generators/tInterpolateParamsDeep.esm.js +1 -3
- package/adapter-js/generators/tPluralise.cjs.js +1 -3
- package/adapter-js/generators/tPluralise.esm.js +1 -3
- package/adapter-js/generators/to.cjs.js +1 -3
- package/adapter-js/generators/to.esm.js +1 -3
- package/compiler/functions.d.ts +1 -1
- package/compiler/helpers.cjs.js +12 -11
- package/compiler/helpers.d.ts +0 -1
- package/compiler/helpers.esm.js +13 -11
- package/compiler/imports.cjs.js +52 -11
- package/compiler/imports.d.ts +13 -4
- package/compiler/imports.esm.js +52 -11
- package/i18nInterpolateParams.cjs.d.ts +2 -0
- package/i18nInterpolateParams.cjs.default.js +1 -0
- package/i18nInterpolateParams.cjs.mjs +2 -0
- package/i18nInterpolateParams.esm.d.ts +2 -0
- package/i18nInterpolateParamsDeep.cjs.d.ts +2 -0
- package/i18nInterpolateParamsDeep.cjs.default.js +1 -0
- package/i18nInterpolateParamsDeep.cjs.mjs +2 -0
- package/i18nInterpolateParamsDeep.esm.d.ts +2 -0
- package/i18nPluralise.cjs.d.ts +2 -0
- package/i18nPluralise.cjs.default.js +1 -0
- package/i18nPluralise.cjs.js +8 -0
- package/i18nPluralise.cjs.mjs +2 -0
- package/i18nPluralise.esm.d.ts +2 -0
- package/i18nPluralise.esm.js +3 -0
- package/index.cjs.js +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +1 -0
- package/package.json +21 -3
|
@@ -10,31 +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(
|
|
14
|
-
let { params:
|
|
15
|
-
let { values:
|
|
13
|
+
function getTFunction(t, n) {
|
|
14
|
+
let { params: r, plural: o } = t, { body: i, imports: l } = function(t, n) {
|
|
15
|
+
let { values: r, params: o, plural: i, typeValue: l, equalValues: p } = t, { defaultLocale: m, single: u } = n, y = !u && !p, h = [
|
|
16
16
|
d.types
|
|
17
17
|
];
|
|
18
|
-
return
|
|
19
|
-
imports:
|
|
20
|
-
body: (
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
return utils.isPrimitive(
|
|
18
|
+
return i && h.push(d.i18nPluralise), o && ("Primitive" === l ? h.push(d.i18nInterpolateParams) : ("Array" === l || "Object" === l) && h.push(d.i18nInterpolateParamsDeep)), {
|
|
19
|
+
imports: h,
|
|
20
|
+
body: (t)=>{
|
|
21
|
+
let n = y ? "locale = locale || global." + helpers.GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
22
|
+
n += "return ";
|
|
23
|
+
let p = "";
|
|
24
|
+
return utils.isPrimitive(r) ? p += f(r, t) : p += function(t, n, r, a) {
|
|
25
25
|
let o = "";
|
|
26
|
-
if (
|
|
27
|
-
let
|
|
28
|
-
|
|
26
|
+
if (r) for(let r in n){
|
|
27
|
+
let i = n[r];
|
|
28
|
+
r === t || utils.areEqual(i, n[t]) || (o += `locale === "${r}" ? ${f(i, a)} : `);
|
|
29
29
|
}
|
|
30
|
-
return o + f(
|
|
31
|
-
}(m,
|
|
30
|
+
return o + f(n[t], a);
|
|
31
|
+
}(m, r, y, t), i && (p = `i18nPluralise(${p}, params.${c})`), o && ("Primitive" === l ? p = `i18nInterpolateParams(${p}, params)` : ("Array" === l || "Object" === l) && (p = `i18nInterpolateParamsDeep(${p}, params)`)), n + p;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
}(
|
|
35
|
-
...
|
|
34
|
+
}(t, n), m = [], u = r ? o ? {
|
|
35
|
+
...r,
|
|
36
36
|
[c]: "number"
|
|
37
|
-
} :
|
|
37
|
+
} : r : o ? {
|
|
38
38
|
[c]: "number"
|
|
39
39
|
} : null;
|
|
40
40
|
return u && m.push({
|
|
@@ -49,50 +49,50 @@ function getTFunction(e, r) {
|
|
|
49
49
|
description: "Use this to override the current locale",
|
|
50
50
|
defaults: "current locale"
|
|
51
51
|
}), {
|
|
52
|
-
body:
|
|
52
|
+
body: i,
|
|
53
53
|
args: m,
|
|
54
|
-
imports:
|
|
54
|
+
imports: l
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
function f(
|
|
58
|
-
let
|
|
59
|
-
return utils.isString(
|
|
57
|
+
function f(e, { format: a }) {
|
|
58
|
+
let i = "ts" === a ? " as const" : "";
|
|
59
|
+
return utils.isString(e) || utils.isNumber(e) ? `"${e}"${i}` : utils.isBoolean(e) ? `${e}` : utils.isArray(e) ? JSON.stringify(e) + i : `(${JSON.stringify(e)}${i})`;
|
|
60
60
|
}
|
|
61
61
|
let d = {
|
|
62
62
|
types: types.getImportTypes(),
|
|
63
|
-
|
|
64
|
-
path: "
|
|
63
|
+
i18nInterpolateParams: new imports.ImportsCompiler({
|
|
64
|
+
path: "@koine/i18n",
|
|
65
65
|
named: [
|
|
66
66
|
{
|
|
67
|
-
name: "
|
|
67
|
+
name: "i18nInterpolateParams"
|
|
68
68
|
}
|
|
69
69
|
]
|
|
70
70
|
}),
|
|
71
|
-
|
|
72
|
-
path: "
|
|
71
|
+
i18nInterpolateParamsDeep: new imports.ImportsCompiler({
|
|
72
|
+
path: "@koine/i18n",
|
|
73
73
|
named: [
|
|
74
74
|
{
|
|
75
|
-
name: "
|
|
75
|
+
name: "i18nInterpolateParamsDeep"
|
|
76
76
|
}
|
|
77
77
|
]
|
|
78
78
|
}),
|
|
79
|
-
|
|
80
|
-
path: "
|
|
79
|
+
i18nPluralise: new imports.ImportsCompiler({
|
|
80
|
+
path: "@koine/i18n",
|
|
81
81
|
named: [
|
|
82
82
|
{
|
|
83
|
-
name: "
|
|
83
|
+
name: "i18nPluralise"
|
|
84
84
|
}
|
|
85
85
|
]
|
|
86
86
|
})
|
|
87
|
-
}, y = (
|
|
88
|
-
let
|
|
89
|
-
for(let a in
|
|
90
|
-
let o =
|
|
91
|
-
|
|
92
|
-
imports:
|
|
87
|
+
}, y = (e, t)=>{
|
|
88
|
+
let n = [], r = new Set();
|
|
89
|
+
for(let a in r.add(d.types), e){
|
|
90
|
+
let o = e[a], { imports: i, args: s, body: p } = getTFunction(o, t);
|
|
91
|
+
i.forEach((e)=>r.add(e)), n.push(new functions.FunctionsCompiler({
|
|
92
|
+
imports: i,
|
|
93
93
|
name: o.fnName,
|
|
94
|
-
args:
|
|
95
|
-
body:
|
|
94
|
+
args: s,
|
|
95
|
+
body: p,
|
|
96
96
|
comment: {
|
|
97
97
|
tags: [
|
|
98
98
|
{
|
|
@@ -104,18 +104,18 @@ let d = {
|
|
|
104
104
|
}));
|
|
105
105
|
}
|
|
106
106
|
return {
|
|
107
|
-
functions:
|
|
108
|
-
allImports:
|
|
107
|
+
functions: n,
|
|
108
|
+
allImports: r
|
|
109
109
|
};
|
|
110
110
|
};
|
|
111
|
-
var d$1 = createAdapter.createGenerator("js", (
|
|
112
|
-
let { config:
|
|
113
|
-
return
|
|
111
|
+
var d$1 = createAdapter.createGenerator("js", (e)=>{
|
|
112
|
+
let { config: t, options: { translations: n, adapter: { modularize: r } }, translations: a } = e, { dir: o } = n.functions, { functions: i, allImports: s } = y(a, t);
|
|
113
|
+
return r ? i.reduce((e, t)=>(e[t.name] = {
|
|
114
114
|
dir: o,
|
|
115
|
-
name:
|
|
115
|
+
name: t.name,
|
|
116
116
|
ext: "ts",
|
|
117
117
|
index: !0,
|
|
118
|
-
content: ()=>
|
|
118
|
+
content: ()=>t.$out("ts", {
|
|
119
119
|
imports: {
|
|
120
120
|
folderUp: 1
|
|
121
121
|
},
|
|
@@ -124,14 +124,12 @@ var d$1 = createAdapter.createGenerator("js", (t)=>{
|
|
|
124
124
|
comments: !0,
|
|
125
125
|
pure: !0
|
|
126
126
|
})
|
|
127
|
-
},
|
|
127
|
+
}, e), {}) : {
|
|
128
128
|
$t: {
|
|
129
129
|
name: o,
|
|
130
130
|
ext: "ts",
|
|
131
131
|
index: !1,
|
|
132
|
-
content: ()=>"" + (imports.ImportsCompiler.outMany("ts",
|
|
133
|
-
folderUp: 0
|
|
134
|
-
}) + functions.FunctionsCompiler.outMany("ts", l, {
|
|
132
|
+
content: ()=>"" + (imports.ImportsCompiler.outMany("ts", s) + functions.FunctionsCompiler.outMany("ts", i, {
|
|
135
133
|
imports: !1,
|
|
136
134
|
exports: "named",
|
|
137
135
|
style: "function",
|
|
@@ -6,31 +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(
|
|
10
|
-
let { params:
|
|
11
|
-
let { values:
|
|
9
|
+
function getTFunction(t, n) {
|
|
10
|
+
let { params: r, plural: o } = t, { body: i, imports: l } = function(t, n) {
|
|
11
|
+
let { values: r, params: o, plural: i, typeValue: l, equalValues: p } = t, { defaultLocale: m, single: u } = n, y = !u && !p, h = [
|
|
12
12
|
d.types
|
|
13
13
|
];
|
|
14
|
-
return
|
|
15
|
-
imports:
|
|
16
|
-
body: (
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
return isPrimitive(
|
|
14
|
+
return i && h.push(d.i18nPluralise), o && ("Primitive" === l ? h.push(d.i18nInterpolateParams) : ("Array" === l || "Object" === l) && h.push(d.i18nInterpolateParamsDeep)), {
|
|
15
|
+
imports: h,
|
|
16
|
+
body: (t)=>{
|
|
17
|
+
let n = y ? "locale = locale || global." + GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
18
|
+
n += "return ";
|
|
19
|
+
let p = "";
|
|
20
|
+
return isPrimitive(r) ? p += f(r, t) : p += function(t, n, r, a) {
|
|
21
21
|
let o = "";
|
|
22
|
-
if (
|
|
23
|
-
let
|
|
24
|
-
|
|
22
|
+
if (r) for(let r in n){
|
|
23
|
+
let i = n[r];
|
|
24
|
+
r === t || areEqual(i, n[t]) || (o += `locale === "${r}" ? ${f(i, a)} : `);
|
|
25
25
|
}
|
|
26
|
-
return o + f(
|
|
27
|
-
}(m,
|
|
26
|
+
return o + f(n[t], a);
|
|
27
|
+
}(m, r, y, t), i && (p = `i18nPluralise(${p}, params.${c})`), o && ("Primitive" === l ? p = `i18nInterpolateParams(${p}, params)` : ("Array" === l || "Object" === l) && (p = `i18nInterpolateParamsDeep(${p}, params)`)), n + p;
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
}(
|
|
31
|
-
...
|
|
30
|
+
}(t, n), m = [], u = r ? o ? {
|
|
31
|
+
...r,
|
|
32
32
|
[c]: "number"
|
|
33
|
-
} :
|
|
33
|
+
} : r : o ? {
|
|
34
34
|
[c]: "number"
|
|
35
35
|
} : null;
|
|
36
36
|
return u && m.push({
|
|
@@ -45,50 +45,50 @@ function getTFunction(e, r) {
|
|
|
45
45
|
description: "Use this to override the current locale",
|
|
46
46
|
defaults: "current locale"
|
|
47
47
|
}), {
|
|
48
|
-
body:
|
|
48
|
+
body: i,
|
|
49
49
|
args: m,
|
|
50
|
-
imports:
|
|
50
|
+
imports: l
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function f(
|
|
54
|
-
let
|
|
55
|
-
return isString(
|
|
53
|
+
function f(e, { format: a }) {
|
|
54
|
+
let i = "ts" === a ? " as const" : "";
|
|
55
|
+
return isString(e) || isNumber(e) ? `"${e}"${i}` : isBoolean(e) ? `${e}` : isArray(e) ? JSON.stringify(e) + i : `(${JSON.stringify(e)}${i})`;
|
|
56
56
|
}
|
|
57
57
|
let d = {
|
|
58
58
|
types: getImportTypes(),
|
|
59
|
-
|
|
60
|
-
path: "
|
|
59
|
+
i18nInterpolateParams: new ImportsCompiler({
|
|
60
|
+
path: "@koine/i18n",
|
|
61
61
|
named: [
|
|
62
62
|
{
|
|
63
|
-
name: "
|
|
63
|
+
name: "i18nInterpolateParams"
|
|
64
64
|
}
|
|
65
65
|
]
|
|
66
66
|
}),
|
|
67
|
-
|
|
68
|
-
path: "
|
|
67
|
+
i18nInterpolateParamsDeep: new ImportsCompiler({
|
|
68
|
+
path: "@koine/i18n",
|
|
69
69
|
named: [
|
|
70
70
|
{
|
|
71
|
-
name: "
|
|
71
|
+
name: "i18nInterpolateParamsDeep"
|
|
72
72
|
}
|
|
73
73
|
]
|
|
74
74
|
}),
|
|
75
|
-
|
|
76
|
-
path: "
|
|
75
|
+
i18nPluralise: new ImportsCompiler({
|
|
76
|
+
path: "@koine/i18n",
|
|
77
77
|
named: [
|
|
78
78
|
{
|
|
79
|
-
name: "
|
|
79
|
+
name: "i18nPluralise"
|
|
80
80
|
}
|
|
81
81
|
]
|
|
82
82
|
})
|
|
83
|
-
}, y = (
|
|
84
|
-
let
|
|
85
|
-
for(let a in
|
|
86
|
-
let o =
|
|
87
|
-
|
|
88
|
-
imports:
|
|
83
|
+
}, y = (e, t)=>{
|
|
84
|
+
let n = [], r = new Set();
|
|
85
|
+
for(let a in r.add(d.types), e){
|
|
86
|
+
let o = e[a], { imports: i, args: s, body: p } = getTFunction(o, t);
|
|
87
|
+
i.forEach((e)=>r.add(e)), n.push(new FunctionsCompiler({
|
|
88
|
+
imports: i,
|
|
89
89
|
name: o.fnName,
|
|
90
|
-
args:
|
|
91
|
-
body:
|
|
90
|
+
args: s,
|
|
91
|
+
body: p,
|
|
92
92
|
comment: {
|
|
93
93
|
tags: [
|
|
94
94
|
{
|
|
@@ -100,18 +100,18 @@ let d = {
|
|
|
100
100
|
}));
|
|
101
101
|
}
|
|
102
102
|
return {
|
|
103
|
-
functions:
|
|
104
|
-
allImports:
|
|
103
|
+
functions: n,
|
|
104
|
+
allImports: r
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
|
-
var d$1 = createGenerator("js", (
|
|
108
|
-
let { config:
|
|
109
|
-
return
|
|
107
|
+
var d$1 = createGenerator("js", (e)=>{
|
|
108
|
+
let { config: t, options: { translations: n, adapter: { modularize: r } }, translations: a } = e, { dir: o } = n.functions, { functions: i, allImports: s } = y(a, t);
|
|
109
|
+
return r ? i.reduce((e, t)=>(e[t.name] = {
|
|
110
110
|
dir: o,
|
|
111
|
-
name:
|
|
111
|
+
name: t.name,
|
|
112
112
|
ext: "ts",
|
|
113
113
|
index: !0,
|
|
114
|
-
content: ()=>
|
|
114
|
+
content: ()=>t.$out("ts", {
|
|
115
115
|
imports: {
|
|
116
116
|
folderUp: 1
|
|
117
117
|
},
|
|
@@ -120,14 +120,12 @@ var d$1 = createGenerator("js", (t)=>{
|
|
|
120
120
|
comments: !0,
|
|
121
121
|
pure: !0
|
|
122
122
|
})
|
|
123
|
-
},
|
|
123
|
+
}, e), {}) : {
|
|
124
124
|
$t: {
|
|
125
125
|
name: o,
|
|
126
126
|
ext: "ts",
|
|
127
127
|
index: !1,
|
|
128
|
-
content: ()=>"" + (ImportsCompiler.outMany("ts",
|
|
129
|
-
folderUp: 0
|
|
130
|
-
}) + FunctionsCompiler.outMany("ts", l, {
|
|
128
|
+
content: ()=>"" + (ImportsCompiler.outMany("ts", s) + FunctionsCompiler.outMany("ts", i, {
|
|
131
129
|
imports: !1,
|
|
132
130
|
exports: "named",
|
|
133
131
|
style: "function",
|
|
@@ -103,9 +103,7 @@ var I = createAdapter.createGenerator("js", (t)=>{
|
|
|
103
103
|
name: i,
|
|
104
104
|
ext: "ts",
|
|
105
105
|
index: !1,
|
|
106
|
-
content: ()=>"" + (imports.ImportsCompiler.outMany("ts", d, {
|
|
107
|
-
folderUp: 0
|
|
108
|
-
}) + functions.FunctionsCompiler.outMany("ts", u, {
|
|
106
|
+
content: ()=>"" + (imports.ImportsCompiler.outMany("ts", d) + functions.FunctionsCompiler.outMany("ts", u, {
|
|
109
107
|
imports: !1,
|
|
110
108
|
exports: "named",
|
|
111
109
|
style: "function",
|
|
@@ -99,9 +99,7 @@ var I = createGenerator("js", (t)=>{
|
|
|
99
99
|
name: i,
|
|
100
100
|
ext: "ts",
|
|
101
101
|
index: !1,
|
|
102
|
-
content: ()=>"" + (ImportsCompiler.outMany("ts", d, {
|
|
103
|
-
folderUp: 0
|
|
104
|
-
}) + FunctionsCompiler.outMany("ts", u, {
|
|
102
|
+
content: ()=>"" + (ImportsCompiler.outMany("ts", d) + FunctionsCompiler.outMany("ts", u, {
|
|
105
103
|
imports: !1,
|
|
106
104
|
exports: "named",
|
|
107
105
|
style: "function",
|
package/compiler/functions.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ type FunctionsCompilerComment = {
|
|
|
125
125
|
*/
|
|
126
126
|
tags?: FunctionsCompilerCommentTag[];
|
|
127
127
|
};
|
|
128
|
-
type FunctionsCompilerOutputOptions = {
|
|
128
|
+
export type FunctionsCompilerOutputOptions = {
|
|
129
129
|
/**
|
|
130
130
|
* Imports output options, pass `false` to do not output import' statements
|
|
131
131
|
*/
|
package/compiler/helpers.cjs.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var minimatch = require('minimatch');
|
|
4
|
+
var imports = require('./imports.cjs.js');
|
|
4
5
|
|
|
5
6
|
const GLOBAL_I18N_IDENTIFIER = "__i18n_locale";
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
let getTranslationsDir = (e = 0, r = "translations")=>imports.ImportsCompiler.getDir({
|
|
8
|
+
folderUp: e
|
|
9
|
+
}) + r;
|
|
10
|
+
let compileDataParamsToType = (e)=>"{ " + Object.keys(e).reduce((t, r)=>{
|
|
11
|
+
let a = e[r], i = "";
|
|
10
12
|
switch(a){
|
|
11
13
|
case "number":
|
|
12
|
-
|
|
14
|
+
i = "number";
|
|
13
15
|
break;
|
|
14
16
|
case "string":
|
|
15
|
-
|
|
17
|
+
i = "string";
|
|
16
18
|
break;
|
|
17
19
|
default:
|
|
18
|
-
|
|
20
|
+
i = "string | number";
|
|
19
21
|
}
|
|
20
|
-
return
|
|
22
|
+
return t.push(`${r}: ${i};`), t;
|
|
21
23
|
}, []).join(" ") + " }";
|
|
22
|
-
let escapeEachChar = (
|
|
23
|
-
let filterInputTranslationFiles = (
|
|
24
|
+
let escapeEachChar = (e)=>e.split("").map((e)=>`\\${e}`).join("");
|
|
25
|
+
let filterInputTranslationFiles = (t, r = [], a)=>t.filter((t)=>(!a || a && a(t)) && (!r.length || r.every((r)=>!minimatch.minimatch(t.path, r))));
|
|
24
26
|
|
|
25
27
|
exports.GLOBAL_I18N_IDENTIFIER = GLOBAL_I18N_IDENTIFIER;
|
|
26
28
|
exports.compileDataParamsToType = compileDataParamsToType;
|
|
27
29
|
exports.escapeEachChar = escapeEachChar;
|
|
28
30
|
exports.filterInputTranslationFiles = filterInputTranslationFiles;
|
|
29
|
-
exports.getImportDots = getImportDots;
|
|
30
31
|
exports.getTranslationsDir = getTranslationsDir;
|
package/compiler/helpers.d.ts
CHANGED
package/compiler/helpers.esm.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { minimatch } from 'minimatch';
|
|
2
|
+
import { ImportsCompiler } from './imports.esm.js';
|
|
2
3
|
|
|
3
4
|
const GLOBAL_I18N_IDENTIFIER = "__i18n_locale";
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let getTranslationsDir = (e = 0, r = "translations")=>ImportsCompiler.getDir({
|
|
6
|
+
folderUp: e
|
|
7
|
+
}) + r;
|
|
8
|
+
let compileDataParamsToType = (e)=>"{ " + Object.keys(e).reduce((t, r)=>{
|
|
9
|
+
let a = e[r], i = "";
|
|
8
10
|
switch(a){
|
|
9
11
|
case "number":
|
|
10
|
-
|
|
12
|
+
i = "number";
|
|
11
13
|
break;
|
|
12
14
|
case "string":
|
|
13
|
-
|
|
15
|
+
i = "string";
|
|
14
16
|
break;
|
|
15
17
|
default:
|
|
16
|
-
|
|
18
|
+
i = "string | number";
|
|
17
19
|
}
|
|
18
|
-
return
|
|
20
|
+
return t.push(`${r}: ${i};`), t;
|
|
19
21
|
}, []).join(" ") + " }";
|
|
20
|
-
let escapeEachChar = (
|
|
21
|
-
let filterInputTranslationFiles = (
|
|
22
|
+
let escapeEachChar = (e)=>e.split("").map((e)=>`\\${e}`).join("");
|
|
23
|
+
let filterInputTranslationFiles = (t, r = [], a)=>t.filter((t)=>(!a || a && a(t)) && (!r.length || r.every((r)=>!minimatch(t.path, r))));
|
|
22
24
|
|
|
23
|
-
export { GLOBAL_I18N_IDENTIFIER, compileDataParamsToType, escapeEachChar, filterInputTranslationFiles,
|
|
25
|
+
export { GLOBAL_I18N_IDENTIFIER, compileDataParamsToType, escapeEachChar, filterInputTranslationFiles, getTranslationsDir };
|
package/compiler/imports.cjs.js
CHANGED
|
@@ -1,28 +1,69 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var helpers = require('./helpers.cjs.js');
|
|
4
|
-
|
|
5
3
|
class ImportsCompiler {
|
|
6
4
|
constructor(t){
|
|
7
5
|
this.data = t;
|
|
8
6
|
}
|
|
9
|
-
static #t(
|
|
10
|
-
let
|
|
11
|
-
|
|
7
|
+
static #t(t) {
|
|
8
|
+
let r = t.reduce((t, r)=>{
|
|
9
|
+
let { path: e } = r.data;
|
|
10
|
+
return t[e] = t[e] || [], t[e].push(r), t;
|
|
11
|
+
}, {});
|
|
12
|
+
return Object.keys(r).map((t)=>{
|
|
13
|
+
let e = r[t];
|
|
14
|
+
if (e.length > 1) {
|
|
15
|
+
let r = [], i = "";
|
|
16
|
+
return e.forEach((t)=>{
|
|
17
|
+
let { defaulT: e, named: s } = t.data;
|
|
18
|
+
if (s && (r = [
|
|
19
|
+
...r,
|
|
20
|
+
...s
|
|
21
|
+
]), e) {
|
|
22
|
+
if (i) throw Error(`ImportsCompiler: Aggregated imports declare multiple default imports. Default import "${e}" conflicts with "${i}"`);
|
|
23
|
+
i = e;
|
|
24
|
+
}
|
|
25
|
+
}), new ImportsCompiler({
|
|
26
|
+
defaulT: i,
|
|
27
|
+
named: r,
|
|
28
|
+
path: t
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return e[0];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
static getDir(t) {
|
|
35
|
+
let { folderUp: r = 0, external: e } = t;
|
|
36
|
+
return e ? "" : (r ? Array(r).fill("..").join("/") : ".") + "/";
|
|
37
|
+
}
|
|
38
|
+
static #r(t) {
|
|
39
|
+
let { path: r, external: e } = t;
|
|
40
|
+
return "boolean" == typeof e ? e : r.startsWith("@");
|
|
41
|
+
}
|
|
42
|
+
static #e(t, r) {
|
|
43
|
+
let { path: e, defaulT: i, named: s = [] } = t, { folderUp: a } = r || {}, o = this.getDir({
|
|
44
|
+
folderUp: a,
|
|
45
|
+
external: this.#r(t)
|
|
46
|
+
}), n = "import ";
|
|
47
|
+
return i && (n += i, s.length && (n += ", ")), s.length && (n += "{ " + s.map(({ name: t, type: r })=>r ? "type " + t : t).join(", ") + " }"), n += ' from "' + o + e + '";';
|
|
12
48
|
}
|
|
13
|
-
static #
|
|
14
|
-
let { path:
|
|
15
|
-
|
|
49
|
+
static #i(t, r) {
|
|
50
|
+
let { path: e, defaulT: i, named: s = [] } = t, { folderUp: a } = r || {}, o = this.getDir({
|
|
51
|
+
folderUp: a,
|
|
52
|
+
external: this.#r(t)
|
|
53
|
+
}), n = `= require("${o + e}")`, l = "";
|
|
54
|
+
return i && (l += `const ${i} ${n};`), s.length && (i && (l += "\n"), l += `const { ${s.filter((t)=>!t.type).map((t)=>t.name).join(", ")} } ${n};`), l;
|
|
16
55
|
}
|
|
17
56
|
$out(t, r) {
|
|
18
57
|
return ImportsCompiler.out(this.data, t, r);
|
|
19
58
|
}
|
|
20
59
|
static out(t, r, e) {
|
|
21
|
-
|
|
60
|
+
if ("ts" === r) return this.#e(t, e);
|
|
61
|
+
if ("cjs" === r) return this.#i(t, e);
|
|
62
|
+
throw Error(`ImportsCompiler: Unsupported format '${r}'`);
|
|
22
63
|
}
|
|
23
64
|
static outMany(t, r, e) {
|
|
24
|
-
let
|
|
25
|
-
return
|
|
65
|
+
let i = this.#t(Array.from(r));
|
|
66
|
+
return i.length ? i.map((r)=>this.out(r.data, t, e)).join("\n") + "\n\n" : "";
|
|
26
67
|
}
|
|
27
68
|
}
|
|
28
69
|
|
package/compiler/imports.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export type ImportsCompilerData = {
|
|
|
3
3
|
* `myPath` in `import type { MyType } from "../myPath"`;
|
|
4
4
|
*/
|
|
5
5
|
path: string;
|
|
6
|
+
/**
|
|
7
|
+
* Flags an import from a thirdy part package. This is not needed when the path
|
|
8
|
+
* begins with a `@`, in the other cases we cannot infer this information.
|
|
9
|
+
*/
|
|
10
|
+
external?: boolean;
|
|
6
11
|
/**
|
|
7
12
|
* `myImport` in `import myImport from "../myPath"`;
|
|
8
13
|
* or in `import myImport, { myNamed } from "../myPath"`;
|
|
@@ -27,15 +32,19 @@ export type ImportsCompilerOutputOptions = {
|
|
|
27
32
|
/**
|
|
28
33
|
* Determines the `../` in `import type { MyType } from "../myPath"`;
|
|
29
34
|
*/
|
|
30
|
-
folderUp
|
|
35
|
+
folderUp?: number;
|
|
31
36
|
};
|
|
32
37
|
type ImportsCompilerOutputFormat = "ts" | "cjs";
|
|
33
38
|
export declare class ImportsCompiler {
|
|
34
39
|
#private;
|
|
35
40
|
data: ImportsCompilerData;
|
|
36
41
|
constructor(data: ImportsCompilerData);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
static getDir(options: {
|
|
43
|
+
folderUp?: number;
|
|
44
|
+
external?: boolean;
|
|
45
|
+
}): string;
|
|
46
|
+
$out(format: ImportsCompilerOutputFormat, options?: ImportsCompilerOutputOptions): string;
|
|
47
|
+
static out(data: ImportsCompilerData, format: ImportsCompilerOutputFormat, options?: ImportsCompilerOutputOptions): string;
|
|
48
|
+
static outMany(format: ImportsCompilerOutputFormat, instances: ImportsCompiler[] | Set<ImportsCompiler>, options?: ImportsCompilerOutputOptions): string;
|
|
40
49
|
}
|
|
41
50
|
export {};
|
package/compiler/imports.esm.js
CHANGED
|
@@ -1,26 +1,67 @@
|
|
|
1
|
-
import { getImportDots } from './helpers.esm.js';
|
|
2
|
-
|
|
3
1
|
class ImportsCompiler {
|
|
4
2
|
constructor(t){
|
|
5
3
|
this.data = t;
|
|
6
4
|
}
|
|
7
|
-
static #t(
|
|
8
|
-
let
|
|
9
|
-
|
|
5
|
+
static #t(t) {
|
|
6
|
+
let r = t.reduce((t, r)=>{
|
|
7
|
+
let { path: e } = r.data;
|
|
8
|
+
return t[e] = t[e] || [], t[e].push(r), t;
|
|
9
|
+
}, {});
|
|
10
|
+
return Object.keys(r).map((t)=>{
|
|
11
|
+
let e = r[t];
|
|
12
|
+
if (e.length > 1) {
|
|
13
|
+
let r = [], i = "";
|
|
14
|
+
return e.forEach((t)=>{
|
|
15
|
+
let { defaulT: e, named: s } = t.data;
|
|
16
|
+
if (s && (r = [
|
|
17
|
+
...r,
|
|
18
|
+
...s
|
|
19
|
+
]), e) {
|
|
20
|
+
if (i) throw Error(`ImportsCompiler: Aggregated imports declare multiple default imports. Default import "${e}" conflicts with "${i}"`);
|
|
21
|
+
i = e;
|
|
22
|
+
}
|
|
23
|
+
}), new ImportsCompiler({
|
|
24
|
+
defaulT: i,
|
|
25
|
+
named: r,
|
|
26
|
+
path: t
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return e[0];
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static getDir(t) {
|
|
33
|
+
let { folderUp: r = 0, external: e } = t;
|
|
34
|
+
return e ? "" : (r ? Array(r).fill("..").join("/") : ".") + "/";
|
|
35
|
+
}
|
|
36
|
+
static #r(t) {
|
|
37
|
+
let { path: r, external: e } = t;
|
|
38
|
+
return "boolean" == typeof e ? e : r.startsWith("@");
|
|
39
|
+
}
|
|
40
|
+
static #e(t, r) {
|
|
41
|
+
let { path: e, defaulT: i, named: s = [] } = t, { folderUp: a } = r || {}, o = this.getDir({
|
|
42
|
+
folderUp: a,
|
|
43
|
+
external: this.#r(t)
|
|
44
|
+
}), n = "import ";
|
|
45
|
+
return i && (n += i, s.length && (n += ", ")), s.length && (n += "{ " + s.map(({ name: t, type: r })=>r ? "type " + t : t).join(", ") + " }"), n += ' from "' + o + e + '";';
|
|
10
46
|
}
|
|
11
|
-
static #
|
|
12
|
-
let { path:
|
|
13
|
-
|
|
47
|
+
static #i(t, r) {
|
|
48
|
+
let { path: e, defaulT: i, named: s = [] } = t, { folderUp: a } = r || {}, o = this.getDir({
|
|
49
|
+
folderUp: a,
|
|
50
|
+
external: this.#r(t)
|
|
51
|
+
}), n = `= require("${o + e}")`, l = "";
|
|
52
|
+
return i && (l += `const ${i} ${n};`), s.length && (i && (l += "\n"), l += `const { ${s.filter((t)=>!t.type).map((t)=>t.name).join(", ")} } ${n};`), l;
|
|
14
53
|
}
|
|
15
54
|
$out(t, r) {
|
|
16
55
|
return ImportsCompiler.out(this.data, t, r);
|
|
17
56
|
}
|
|
18
57
|
static out(t, r, e) {
|
|
19
|
-
|
|
58
|
+
if ("ts" === r) return this.#e(t, e);
|
|
59
|
+
if ("cjs" === r) return this.#i(t, e);
|
|
60
|
+
throw Error(`ImportsCompiler: Unsupported format '${r}'`);
|
|
20
61
|
}
|
|
21
62
|
static outMany(t, r, e) {
|
|
22
|
-
let
|
|
23
|
-
return
|
|
63
|
+
let i = this.#t(Array.from(r));
|
|
64
|
+
return i.length ? i.map((r)=>this.out(r.data, t, e)).join("\n") + "\n\n" : "";
|
|
24
65
|
}
|
|
25
66
|
}
|
|
26
67
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./i18nInterpolateParams.cjs.js').default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./i18nInterpolateParamsDeep.cjs.js').default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./i18nPluralise.cjs.js').default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
let i18nPluralise = (e, l, r, t = new Intl.PluralRules(r || "en"))=>e[l] || e[t.select(l)] || (0 === l ? e.zero : e.other);
|
|
6
|
+
|
|
7
|
+
exports.default = i18nPluralise;
|
|
8
|
+
exports.i18nPluralise = i18nPluralise;
|
package/index.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ var formatRoutePathname = require('./formatRoutePathname.cjs.js');
|
|
|
4
4
|
var i18nDefaultMetadata = require('./i18nDefaultMetadata.cjs.js');
|
|
5
5
|
var i18nInterpolateParams = require('./i18nInterpolateParams.cjs.js');
|
|
6
6
|
var i18nInterpolateParamsDeep = require('./i18nInterpolateParamsDeep.cjs.js');
|
|
7
|
+
var i18nPluralise = require('./i18nPluralise.cjs.js');
|
|
7
8
|
var interpolateTo = require('./interpolateTo.cjs.js');
|
|
8
9
|
var rtlLocales = require('./rtlLocales.cjs.js');
|
|
9
10
|
var routeHasDynamicPortion = require('./routeHasDynamicPortion.cjs.js');
|
|
@@ -14,6 +15,7 @@ exports.formatRoutePathname = formatRoutePathname.formatRoutePathname;
|
|
|
14
15
|
exports.i18nDefaultMetadata = i18nDefaultMetadata.i18nDefaultMetadata;
|
|
15
16
|
exports.i18nInterpolateParams = i18nInterpolateParams.i18nInterpolateParams;
|
|
16
17
|
exports.i18nInterpolateParamsDeep = i18nInterpolateParamsDeep.i18nInterpolateParamsDeep;
|
|
18
|
+
exports.i18nPluralise = i18nPluralise.i18nPluralise;
|
|
17
19
|
exports.interpolateTo = interpolateTo.interpolateTo;
|
|
18
20
|
exports.rtlLocales = rtlLocales.rtlLocales;
|
|
19
21
|
exports.routeHasDynamicPortion = routeHasDynamicPortion.routeHasDynamicPortion;
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { formatRoutePathname } from "./formatRoutePathname";
|
|
|
2
2
|
export { i18nDefaultMetadata } from "./i18nDefaultMetadata";
|
|
3
3
|
export { i18nInterpolateParams } from "./i18nInterpolateParams";
|
|
4
4
|
export { i18nInterpolateParamsDeep } from "./i18nInterpolateParamsDeep";
|
|
5
|
+
export { i18nPluralise } from "./i18nPluralise";
|
|
5
6
|
export { interpolateTo } from "./interpolateTo";
|
|
6
7
|
export { rtlLocales } from "./rtlLocales";
|
|
7
8
|
export { routeHasDynamicPortion } from "./routeHasDynamicPortion";
|
package/index.esm.js
CHANGED
|
@@ -2,6 +2,7 @@ export { formatRoutePathname } from './formatRoutePathname.esm.js';
|
|
|
2
2
|
export { i18nDefaultMetadata } from './i18nDefaultMetadata.esm.js';
|
|
3
3
|
export { i18nInterpolateParams } from './i18nInterpolateParams.esm.js';
|
|
4
4
|
export { i18nInterpolateParamsDeep } from './i18nInterpolateParamsDeep.esm.js';
|
|
5
|
+
export { i18nPluralise } from './i18nPluralise.esm.js';
|
|
5
6
|
export { interpolateTo } from './interpolateTo.esm.js';
|
|
6
7
|
export { rtlLocales } from './rtlLocales.esm.js';
|
|
7
8
|
export { routeHasDynamicPortion } from './routeHasDynamicPortion.esm.js';
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"node": "^14.18.0 || >=16.0.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@koine/node": "2.0.0-beta.
|
|
9
|
-
"@koine/utils": "2.0.0-beta.
|
|
8
|
+
"@koine/node": "2.0.0-beta.168",
|
|
9
|
+
"@koine/utils": "2.0.0-beta.168",
|
|
10
10
|
"comment-json": "^4.2.4",
|
|
11
11
|
"consola": "^3.2.3",
|
|
12
12
|
"glob": "^11.0.0",
|
|
@@ -46,6 +46,24 @@
|
|
|
46
46
|
"import": "./i18nDefaultMetadata.cjs.mjs",
|
|
47
47
|
"default": "./i18nDefaultMetadata.cjs.js"
|
|
48
48
|
},
|
|
49
|
+
"./i18nInterpolateParams": {
|
|
50
|
+
"module": "./i18nInterpolateParams.esm.js",
|
|
51
|
+
"types": "./i18nInterpolateParams.esm.d.ts",
|
|
52
|
+
"import": "./i18nInterpolateParams.cjs.mjs",
|
|
53
|
+
"default": "./i18nInterpolateParams.cjs.js"
|
|
54
|
+
},
|
|
55
|
+
"./i18nInterpolateParamsDeep": {
|
|
56
|
+
"module": "./i18nInterpolateParamsDeep.esm.js",
|
|
57
|
+
"types": "./i18nInterpolateParamsDeep.esm.d.ts",
|
|
58
|
+
"import": "./i18nInterpolateParamsDeep.cjs.mjs",
|
|
59
|
+
"default": "./i18nInterpolateParamsDeep.cjs.js"
|
|
60
|
+
},
|
|
61
|
+
"./i18nPluralise": {
|
|
62
|
+
"module": "./i18nPluralise.esm.js",
|
|
63
|
+
"types": "./i18nPluralise.esm.d.ts",
|
|
64
|
+
"import": "./i18nPluralise.cjs.mjs",
|
|
65
|
+
"default": "./i18nPluralise.cjs.js"
|
|
66
|
+
},
|
|
49
67
|
"./interpolateTo": {
|
|
50
68
|
"module": "./interpolateTo.esm.js",
|
|
51
69
|
"types": "./interpolateTo.esm.d.ts",
|
|
@@ -98,5 +116,5 @@
|
|
|
98
116
|
"module": "./index.esm.js",
|
|
99
117
|
"main": "./index.cjs.js",
|
|
100
118
|
"types": "./index.esm.d.ts",
|
|
101
|
-
"version": "2.0.0-beta.
|
|
119
|
+
"version": "2.0.0-beta.168"
|
|
102
120
|
}
|