@koine/i18n 2.0.0-beta.136 → 2.0.0-beta.137
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 +2 -2
- package/adapter-js/generators/createT.esm.js +2 -2
- package/adapter-js/generators/defaultI18nMetadata.cjs.js +2 -2
- package/adapter-js/generators/defaultI18nMetadata.esm.js +2 -2
- package/adapter-js/generators/setLocale.cjs.js +43 -0
- package/adapter-js/generators/setLocale.d.ts +12 -0
- package/adapter-js/generators/setLocale.esm.js +38 -0
- package/adapter-js/generators/t.cjs.js +2 -2
- package/adapter-js/generators/t.esm.js +2 -2
- package/adapter-js/generators/tInterpolateParams.cjs.js +2 -2
- package/adapter-js/generators/tInterpolateParams.esm.js +2 -2
- package/adapter-js/generators/tPluralise.cjs.js +2 -2
- package/adapter-js/generators/tPluralise.esm.js +2 -2
- package/adapter-js/generators/to.cjs.js +2 -2
- package/adapter-js/generators/to.esm.js +2 -2
- package/adapter-js/generators/types.cjs.js +2 -2
- package/adapter-js/generators/types.esm.js +2 -2
- package/adapter-js/index.cjs.js +2 -0
- package/adapter-js/index.d.ts +15 -0
- package/adapter-js/index.esm.js +11 -9
- package/adapter-next/generators/router-app/I18nPage.cjs.js +2 -7
- package/adapter-next/generators/router-app/I18nPage.esm.js +2 -7
- package/adapter-next/generators/webpack-define.cjs.js +20 -17
- package/adapter-next/generators/webpack-define.d.ts +10 -0
- package/adapter-next/generators/webpack-define.esm.js +20 -17
- package/adapter-next/index.d.ts +31 -8
- package/adapter-next/webpackPluginI18n.cjs.js +10 -10
- package/adapter-next/webpackPluginI18n.esm.js +10 -10
- package/adapter-next-translate/index.d.ts +31 -8
- package/adapter-react/generators/I18nLocaleContext.cjs.js +3 -2
- package/adapter-react/generators/I18nLocaleContext.esm.js +3 -2
- package/adapter-react/generators/I18nTranslate.cjs.js +10 -0
- package/adapter-react/generators/I18nTranslate.esm.js +10 -0
- package/adapter-react/index.d.ts +15 -0
- package/compiler/api.d.ts +1 -1
- package/compiler/config.d.ts +6 -2
- package/compiler/functions.cjs.js +33 -27
- package/compiler/functions.d.ts +3 -1
- package/compiler/functions.esm.js +33 -27
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var e = createAdapter.createGenerator("js", (e)=>{
|
|
6
6
|
let { options: t } = e;
|
|
7
7
|
return {
|
|
8
8
|
createT: {
|
|
@@ -194,4 +194,4 @@ function objectInterpolation(
|
|
|
194
194
|
};
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
-
module.exports =
|
|
197
|
+
module.exports = e;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var e = createGenerator("js", (e)=>{
|
|
4
4
|
let { options: t } = e;
|
|
5
5
|
return {
|
|
6
6
|
createT: {
|
|
@@ -192,4 +192,4 @@ function objectInterpolation(
|
|
|
192
192
|
};
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
export {
|
|
195
|
+
export { e as default };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var t = createAdapter.createGenerator("js", (t)=>({
|
|
6
6
|
defaultI18nMetadata: {
|
|
7
7
|
name: "defaultI18nMetadata",
|
|
8
8
|
ext: "ts",
|
|
@@ -21,4 +21,4 @@ export const defaultI18nMetadata: I18n.Metadata = {
|
|
|
21
21
|
}
|
|
22
22
|
}));
|
|
23
23
|
|
|
24
|
-
module.exports =
|
|
24
|
+
module.exports = t;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var t = createGenerator("js", (t)=>({
|
|
4
4
|
defaultI18nMetadata: {
|
|
5
5
|
name: "defaultI18nMetadata",
|
|
6
6
|
ext: "ts",
|
|
@@ -19,4 +19,4 @@ export const defaultI18nMetadata: I18n.Metadata = {
|
|
|
19
19
|
}
|
|
20
20
|
}));
|
|
21
21
|
|
|
22
|
-
export {
|
|
22
|
+
export { t as default };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
6
|
+
var functions = require('../../compiler/functions.cjs.js');
|
|
7
|
+
|
|
8
|
+
const setGlobalLocale = (e)=>new functions.FunctionsCompiler({
|
|
9
|
+
imports: [],
|
|
10
|
+
name: "setGlobalLocale",
|
|
11
|
+
args: [
|
|
12
|
+
{
|
|
13
|
+
name: "value",
|
|
14
|
+
type: "string",
|
|
15
|
+
optional: !1
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
before: ({ format: e })=>"ts" === e ? `
|
|
19
|
+
declare global {
|
|
20
|
+
var __i18n_locale: I18n.Locale;
|
|
21
|
+
}` : "",
|
|
22
|
+
body: "global.__i18n_locale = value;"
|
|
23
|
+
});
|
|
24
|
+
var l = createAdapter.createGenerator("js", (e)=>({
|
|
25
|
+
setGlobalLocale: {
|
|
26
|
+
dir: "internal",
|
|
27
|
+
name: "setGlobalLocale",
|
|
28
|
+
ext: "ts",
|
|
29
|
+
index: !1,
|
|
30
|
+
content: ()=>`
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
${setGlobalLocale().$out("ts", {
|
|
35
|
+
imports: !1,
|
|
36
|
+
exports: "named"
|
|
37
|
+
})}
|
|
38
|
+
`
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
exports.default = l;
|
|
43
|
+
exports.setGlobalLocale = setGlobalLocale;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FunctionsCompiler } from "../../compiler/functions";
|
|
2
|
+
export declare const setGlobalLocale: (_options?: never) => FunctionsCompiler;
|
|
3
|
+
declare const _default: (data: import("../../compiler-sync").I18nCompiler.DataCode<"js">) => {
|
|
4
|
+
setGlobalLocale: {
|
|
5
|
+
dir: string;
|
|
6
|
+
name: string;
|
|
7
|
+
ext: "ts";
|
|
8
|
+
index: false;
|
|
9
|
+
content: () => string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
|
+
import { FunctionsCompiler } from '../../compiler/functions.esm.js';
|
|
3
|
+
|
|
4
|
+
const setGlobalLocale = (e)=>new FunctionsCompiler({
|
|
5
|
+
imports: [],
|
|
6
|
+
name: "setGlobalLocale",
|
|
7
|
+
args: [
|
|
8
|
+
{
|
|
9
|
+
name: "value",
|
|
10
|
+
type: "string",
|
|
11
|
+
optional: !1
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
before: ({ format: e })=>"ts" === e ? `
|
|
15
|
+
declare global {
|
|
16
|
+
var __i18n_locale: I18n.Locale;
|
|
17
|
+
}` : "",
|
|
18
|
+
body: "global.__i18n_locale = value;"
|
|
19
|
+
});
|
|
20
|
+
var l = createGenerator("js", (e)=>({
|
|
21
|
+
setGlobalLocale: {
|
|
22
|
+
dir: "internal",
|
|
23
|
+
name: "setGlobalLocale",
|
|
24
|
+
ext: "ts",
|
|
25
|
+
index: !1,
|
|
26
|
+
content: ()=>`
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
${setGlobalLocale().$out("ts", {
|
|
31
|
+
imports: !1,
|
|
32
|
+
exports: "named"
|
|
33
|
+
})}
|
|
34
|
+
`
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
export { l as default, setGlobalLocale };
|
|
@@ -77,7 +77,7 @@ const getTFunctions = (t, e)=>{
|
|
|
77
77
|
allImports: l
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
|
-
var
|
|
80
|
+
var d = createAdapter.createGenerator("js", (t)=>{
|
|
81
81
|
let { config: { defaultLocale: e }, options: { adapter: { modularized: a }, translations: { fnsPrefix: n } }, translations: r } = t, o = n || (a ? "$t_" : ""), { functions: l, allImports: p } = getTFunctions(r, {
|
|
82
82
|
defaultLocale: e,
|
|
83
83
|
fnPrefix: o
|
|
@@ -112,7 +112,7 @@ var l = createAdapter.createGenerator("js", (t)=>{
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
exports.areEqualTranslationsValues = areEqualTranslationsValues;
|
|
115
|
-
exports.default =
|
|
115
|
+
exports.default = d;
|
|
116
116
|
exports.getTFunctionBodyWithLocales = getTFunctionBodyWithLocales;
|
|
117
117
|
exports.getTFunctions = getTFunctions;
|
|
118
118
|
exports.getTranslationValueOutput = getTranslationValueOutput;
|
|
@@ -73,7 +73,7 @@ const getTFunctions = (t, e)=>{
|
|
|
73
73
|
allImports: l
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
-
var
|
|
76
|
+
var d = createGenerator("js", (t)=>{
|
|
77
77
|
let { config: { defaultLocale: e }, options: { adapter: { modularized: a }, translations: { fnsPrefix: n } }, translations: r } = t, o = n || (a ? "$t_" : ""), { functions: l, allImports: p } = getTFunctions(r, {
|
|
78
78
|
defaultLocale: e,
|
|
79
79
|
fnPrefix: o
|
|
@@ -107,4 +107,4 @@ var l = createGenerator("js", (t)=>{
|
|
|
107
107
|
};
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
export { areEqualTranslationsValues,
|
|
110
|
+
export { areEqualTranslationsValues, d as default, getTFunctionBodyWithLocales, getTFunctions, getTranslationValueOutput };
|
|
@@ -27,7 +27,7 @@ const tInterpolateParams = ({ start: t, end: r })=>new functions.FunctionsCompil
|
|
|
27
27
|
params[key.trim()${"ts" === e ? " as keyof typeof params" : ""}] + "",
|
|
28
28
|
) : value`
|
|
29
29
|
});
|
|
30
|
-
var
|
|
30
|
+
var c = createAdapter.createGenerator("js", (t)=>{
|
|
31
31
|
let { options: e } = t, { dynamicDelimiters: a } = e.translations.tokens;
|
|
32
32
|
return {
|
|
33
33
|
tInterpolateParams: {
|
|
@@ -47,5 +47,5 @@ ${tInterpolateParams(a).$out("ts", {
|
|
|
47
47
|
};
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
exports.default =
|
|
50
|
+
exports.default = c;
|
|
51
51
|
exports.tInterpolateParams = tInterpolateParams;
|
|
@@ -23,7 +23,7 @@ const tInterpolateParams = ({ start: t, end: r })=>new FunctionsCompiler({
|
|
|
23
23
|
params[key.trim()${"ts" === e ? " as keyof typeof params" : ""}] + "",
|
|
24
24
|
) : value`
|
|
25
25
|
});
|
|
26
|
-
var
|
|
26
|
+
var c = createGenerator("js", (t)=>{
|
|
27
27
|
let { options: e } = t, { dynamicDelimiters: a } = e.translations.tokens;
|
|
28
28
|
return {
|
|
29
29
|
tInterpolateParams: {
|
|
@@ -43,4 +43,4 @@ ${tInterpolateParams(a).$out("ts", {
|
|
|
43
43
|
};
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
export {
|
|
46
|
+
export { c as default, tInterpolateParams };
|
|
@@ -26,7 +26,7 @@ const tPluralise = ()=>new functions.FunctionsCompiler({
|
|
|
26
26
|
],
|
|
27
27
|
body: 'values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"])'
|
|
28
28
|
});
|
|
29
|
-
var
|
|
29
|
+
var u = createAdapter.createGenerator("js", (e)=>({
|
|
30
30
|
tPluralise: {
|
|
31
31
|
name: "tPluralise",
|
|
32
32
|
ext: "ts",
|
|
@@ -41,5 +41,5 @@ ${tPluralise().$out("ts", {
|
|
|
41
41
|
}
|
|
42
42
|
}));
|
|
43
43
|
|
|
44
|
-
exports.default =
|
|
44
|
+
exports.default = u;
|
|
45
45
|
exports.tPluralise = tPluralise;
|
|
@@ -22,7 +22,7 @@ const tPluralise = ()=>new FunctionsCompiler({
|
|
|
22
22
|
],
|
|
23
23
|
body: 'values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"])'
|
|
24
24
|
});
|
|
25
|
-
var
|
|
25
|
+
var u = createGenerator("js", (e)=>({
|
|
26
26
|
tPluralise: {
|
|
27
27
|
name: "tPluralise",
|
|
28
28
|
ext: "ts",
|
|
@@ -37,4 +37,4 @@ ${tPluralise().$out("ts", {
|
|
|
37
37
|
}
|
|
38
38
|
}));
|
|
39
39
|
|
|
40
|
-
export {
|
|
40
|
+
export { u as default, tPluralise };
|
|
@@ -92,7 +92,7 @@ let n = {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
|
-
var
|
|
95
|
+
var I = createAdapter.createGenerator("js", (t)=>{
|
|
96
96
|
let { options: { routes: { tokens: { idDelimiter: o } } }, routes: { dynamicRoutes: e, staticRoutes: a } } = t;
|
|
97
97
|
return {
|
|
98
98
|
...s(t),
|
|
@@ -204,5 +204,5 @@ export default toSpa;
|
|
|
204
204
|
};
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
-
exports.default =
|
|
207
|
+
exports.default = I;
|
|
208
208
|
exports.getToFunctionBodyWithLocales = getToFunctionBodyWithLocales;
|
|
@@ -88,7 +88,7 @@ let n = {
|
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
|
-
var
|
|
91
|
+
var I = createGenerator("js", (t)=>{
|
|
92
92
|
let { options: { routes: { tokens: { idDelimiter: o } } }, routes: { dynamicRoutes: e, staticRoutes: a } } = t;
|
|
93
93
|
return {
|
|
94
94
|
...s(t),
|
|
@@ -200,4 +200,4 @@ export default toSpa;
|
|
|
200
200
|
};
|
|
201
201
|
});
|
|
202
202
|
|
|
203
|
-
export {
|
|
203
|
+
export { I as default, getToFunctionBodyWithLocales };
|
|
@@ -75,7 +75,7 @@ let d = (t, n)=>!utils.isArray(n) && utils.isObject(n) && pluralisation.hasPlura
|
|
|
75
75
|
TranslationsDictionary: b(h(e))
|
|
76
76
|
};
|
|
77
77
|
};
|
|
78
|
-
var
|
|
78
|
+
var T$1 = createAdapter.createGenerator("js", (e)=>{
|
|
79
79
|
let { options: { routes: { localeParamName: t, tokens: { idDelimiter: a } } } } = e, n = R(e);
|
|
80
80
|
return {
|
|
81
81
|
types: {
|
|
@@ -426,4 +426,4 @@ export namespace I18n {
|
|
|
426
426
|
};
|
|
427
427
|
});
|
|
428
428
|
|
|
429
|
-
module.exports =
|
|
429
|
+
module.exports = T$1;
|
|
@@ -73,7 +73,7 @@ let d = (t, n)=>!isArray(n) && isObject(n) && hasPlurals(n) ? hasOnlyPluralKeys(
|
|
|
73
73
|
TranslationsDictionary: b(h(e))
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
-
var
|
|
76
|
+
var T$1 = createGenerator("js", (e)=>{
|
|
77
77
|
let { options: { routes: { localeParamName: t, tokens: { idDelimiter: a } } } } = e, n = R(e);
|
|
78
78
|
return {
|
|
79
79
|
types: {
|
|
@@ -424,4 +424,4 @@ export namespace I18n {
|
|
|
424
424
|
};
|
|
425
425
|
});
|
|
426
426
|
|
|
427
|
-
export {
|
|
427
|
+
export { T$1 as default };
|
package/adapter-js/index.cjs.js
CHANGED
|
@@ -14,6 +14,7 @@ var getT = require('./generators/getT.cjs.js');
|
|
|
14
14
|
var isLocale = require('./generators/isLocale.cjs.js');
|
|
15
15
|
var pathnameToRouteId = require('./generators/pathnameToRouteId.cjs.js');
|
|
16
16
|
var routes = require('./generators/routes.cjs.js');
|
|
17
|
+
var setLocale = require('./generators/setLocale.cjs.js');
|
|
17
18
|
var t = require('./generators/t.cjs.js');
|
|
18
19
|
var tInterpolateParams = require('./generators/tInterpolateParams.cjs.js');
|
|
19
20
|
var tPluralise = require('./generators/tPluralise.cjs.js');
|
|
@@ -38,6 +39,7 @@ const adapterJs = createAdapter.createAdapter({
|
|
|
38
39
|
isLocale,
|
|
39
40
|
pathnameToRouteId,
|
|
40
41
|
routes,
|
|
42
|
+
setLocale.default,
|
|
41
43
|
t.default,
|
|
42
44
|
tInterpolateParams.default,
|
|
43
45
|
tPluralise.default,
|
package/adapter-js/index.d.ts
CHANGED
|
@@ -160,6 +160,13 @@ export declare const adapterJs: {
|
|
|
160
160
|
index: false;
|
|
161
161
|
content: () => string;
|
|
162
162
|
}) => import("../compiler-sync").I18nCompiler.AdapterFile);
|
|
163
|
+
setGlobalLocale: false | ((file: {
|
|
164
|
+
dir: string;
|
|
165
|
+
name: string;
|
|
166
|
+
ext: "ts";
|
|
167
|
+
index: false;
|
|
168
|
+
content: () => string;
|
|
169
|
+
}) => import("../compiler-sync").I18nCompiler.AdapterFile);
|
|
163
170
|
$t: false | ((file: {
|
|
164
171
|
name: string;
|
|
165
172
|
ext: "ts";
|
|
@@ -311,6 +318,14 @@ export declare const adapterJs: {
|
|
|
311
318
|
index: false;
|
|
312
319
|
content: () => string;
|
|
313
320
|
};
|
|
321
|
+
}) | ((data: import("../compiler-sync").I18nCompiler.DataCode<"js">) => {
|
|
322
|
+
setGlobalLocale: {
|
|
323
|
+
dir: string;
|
|
324
|
+
name: string;
|
|
325
|
+
ext: "ts";
|
|
326
|
+
index: false;
|
|
327
|
+
content: () => string;
|
|
328
|
+
};
|
|
314
329
|
}) | ((data: import("../compiler-sync").I18nCompiler.DataCode<"js">) => {
|
|
315
330
|
$t: {
|
|
316
331
|
name: string;
|
package/adapter-js/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createAdapter } from '../compiler/createAdapter.esm.js';
|
|
2
2
|
import o from './generators/config.esm.js';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import e from './generators/createT.esm.js';
|
|
4
|
+
import t from './generators/defaultI18nMetadata.esm.js';
|
|
5
5
|
import a from './generators/formatTo.esm.js';
|
|
6
6
|
import m from './generators/formatUrl.esm.js';
|
|
7
7
|
import s from './generators/getI18nDictionaries.esm.js';
|
|
@@ -10,11 +10,12 @@ import i from './generators/getT.esm.js';
|
|
|
10
10
|
import p from './generators/isLocale.esm.js';
|
|
11
11
|
import f from './generators/pathnameToRouteId.esm.js';
|
|
12
12
|
import g from './generators/routes.esm.js';
|
|
13
|
-
import l from './generators/
|
|
14
|
-
import d from './generators/
|
|
15
|
-
import c from './generators/
|
|
16
|
-
import u from './generators/
|
|
17
|
-
import I from './generators/
|
|
13
|
+
import l from './generators/setLocale.esm.js';
|
|
14
|
+
import d from './generators/t.esm.js';
|
|
15
|
+
import c from './generators/tInterpolateParams.esm.js';
|
|
16
|
+
import u from './generators/tPluralise.esm.js';
|
|
17
|
+
import I from './generators/to.esm.js';
|
|
18
|
+
import T from './generators/types.esm.js';
|
|
18
19
|
|
|
19
20
|
const adapterJs = createAdapter({
|
|
20
21
|
name: "js",
|
|
@@ -24,8 +25,8 @@ const adapterJs = createAdapter({
|
|
|
24
25
|
},
|
|
25
26
|
getGenerators: (r)=>[
|
|
26
27
|
o,
|
|
27
|
-
t,
|
|
28
28
|
e,
|
|
29
|
+
t,
|
|
29
30
|
a,
|
|
30
31
|
m,
|
|
31
32
|
s,
|
|
@@ -38,7 +39,8 @@ const adapterJs = createAdapter({
|
|
|
38
39
|
d,
|
|
39
40
|
c,
|
|
40
41
|
u,
|
|
41
|
-
I
|
|
42
|
+
I,
|
|
43
|
+
T
|
|
42
44
|
],
|
|
43
45
|
getTransformers: ()=>({})
|
|
44
46
|
});
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var getI18nDictionaries_inline = require('../../../adapter-js/generators/getI18nDictionaries_inline.cjs.js');
|
|
4
4
|
var createAdapter = require('../../../compiler/createAdapter.cjs.js');
|
|
5
5
|
|
|
6
|
-
var n = createAdapter.createGenerator("next", (
|
|
7
|
-
let { config: { single: o }, options: { routes: { localeParamName: n } } } =
|
|
6
|
+
var n = createAdapter.createGenerator("next", (a)=>{
|
|
7
|
+
let { config: { single: o }, options: { routes: { localeParamName: n } } } = a;
|
|
8
8
|
return {
|
|
9
9
|
I18nPage: {
|
|
10
10
|
dir: createAdapter.createGenerator.dirs.server,
|
|
@@ -96,11 +96,6 @@ I18nPage.generateMetadata = getMetadata;
|
|
|
96
96
|
*/
|
|
97
97
|
I18nPage.locale = (props: any) => props.${n};
|
|
98
98
|
|
|
99
|
-
// declare globalThis {
|
|
100
|
-
declare global {
|
|
101
|
-
var __i18n_locale: I18n.Locale;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
99
|
/**
|
|
105
100
|
* This function both sets and return the current locale based on the given
|
|
106
101
|
* _props_ by simply reading the dedicated \`[localeParamName]\` dynamic segment
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getI18nDictionaries_inline } from '../../../adapter-js/generators/getI18nDictionaries_inline.esm.js';
|
|
2
2
|
import { createGenerator } from '../../../compiler/createAdapter.esm.js';
|
|
3
3
|
|
|
4
|
-
var n = createGenerator("next", (
|
|
5
|
-
let { config: { single: o }, options: { routes: { localeParamName: n } } } =
|
|
4
|
+
var n = createGenerator("next", (a)=>{
|
|
5
|
+
let { config: { single: o }, options: { routes: { localeParamName: n } } } = a;
|
|
6
6
|
return {
|
|
7
7
|
I18nPage: {
|
|
8
8
|
dir: createGenerator.dirs.server,
|
|
@@ -94,11 +94,6 @@ I18nPage.generateMetadata = getMetadata;
|
|
|
94
94
|
*/
|
|
95
95
|
I18nPage.locale = (props: any) => props.${n};
|
|
96
96
|
|
|
97
|
-
// declare globalThis {
|
|
98
|
-
declare global {
|
|
99
|
-
var __i18n_locale: I18n.Locale;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
97
|
/**
|
|
103
98
|
* This function both sets and return the current locale based on the given
|
|
104
99
|
* _props_ by simply reading the dedicated \`[localeParamName]\` dynamic segment
|
|
@@ -13,24 +13,24 @@ let p = (e, o)=>{
|
|
|
13
13
|
for(let o in e.byId){
|
|
14
14
|
let n = "", { pathnames: i, params: p } = e.byId[o], m = [];
|
|
15
15
|
p && m.push("params"), m.push("locale");
|
|
16
|
-
let
|
|
17
|
-
utils.isString(i) ? n += `formatTo(${
|
|
16
|
+
let c = l ? '""' : "locale", u = p ? ", params" : "";
|
|
17
|
+
utils.isString(i) ? n += `formatTo(${c}, "${i}"${u})` : n += `formatTo(${c}, ${to.getToFunctionBodyWithLocales(a, i)}${u})`, r.push(`"${o}": (${m.join(", ")}) => ${n}`);
|
|
18
18
|
}
|
|
19
19
|
return r.join(",\n ");
|
|
20
20
|
}, m = (t$1, o)=>{
|
|
21
21
|
let { defaultLocale: r, namespaceDelimiter: l } = o, s = [];
|
|
22
22
|
for(let o in t$1){
|
|
23
|
-
let { namespace: i, path: p, values: m, params:
|
|
24
|
-
|
|
23
|
+
let { namespace: i, path: p, values: m, params: c, plural: u } = t$1[o];
|
|
24
|
+
u && (c ? c.count = "number" : c = {
|
|
25
25
|
count: "number"
|
|
26
26
|
});
|
|
27
27
|
let d = [];
|
|
28
|
-
|
|
28
|
+
c && d.push("params");
|
|
29
29
|
let $ = "";
|
|
30
|
-
utils.isPrimitive(m) ? $ += t.getTranslationValueOutput(m) : $ += t.getTFunctionBodyWithLocales(r, m),
|
|
30
|
+
utils.isPrimitive(m) ? $ += t.getTranslationValueOutput(m) : $ += t.getTFunctionBodyWithLocales(r, m), u && ($ = `tPluralise(${$}, params.count)`), c && ($ = `tInterpolateParams(${$}, params)`), s.push(`"${i}${l}${p}": (${d.join(", ")}) => ${$}`);
|
|
31
31
|
}
|
|
32
32
|
return s.join(",\n ");
|
|
33
|
-
},
|
|
33
|
+
}, c = (e)=>{
|
|
34
34
|
let { dynamicRoutes: t, staticRoutes: o } = e, a = 'import("../types").I18n', n = `
|
|
35
35
|
/**
|
|
36
36
|
* Global to function (allows to select any of the all available routes)
|
|
@@ -54,7 +54,7 @@ let p = (e, o)=>{
|
|
|
54
54
|
) => ${a}.RoutePathnames[Id];`, n;
|
|
55
55
|
};
|
|
56
56
|
var I = createAdapter.createGenerator("next", (e)=>{
|
|
57
|
-
let { config: t, options: a, routes: n, translations: s } = e, { defaultLocale:
|
|
57
|
+
let { config: t, options: a, routes: n, translations: s } = e, { defaultLocale: u, locales: d, debug: $ } = t, { namespaceDelimiter: f, dynamicDelimiters: b } = a.translations.tokens, { globalName: I } = a.adapter, { cwd: g, output: h } = a.write || {
|
|
58
58
|
cwd: "",
|
|
59
59
|
output: ""
|
|
60
60
|
};
|
|
@@ -72,7 +72,7 @@ declare global {
|
|
|
72
72
|
/**
|
|
73
73
|
* Global t function (allows to select any of the all available translations)
|
|
74
74
|
*
|
|
75
|
-
* @param path e.g. \`"myNamespace${
|
|
75
|
+
* @param path e.g. \`"myNamespace${f}myPath.nestedKey"\`
|
|
76
76
|
*/
|
|
77
77
|
type GlobalT = <
|
|
78
78
|
TPath extends import("../types").I18n.TranslationsAllPaths,
|
|
@@ -81,7 +81,7 @@ declare global {
|
|
|
81
81
|
path: TPath,
|
|
82
82
|
query?: object,
|
|
83
83
|
) => TReturn;
|
|
84
|
-
${
|
|
84
|
+
${c(n)}
|
|
85
85
|
|
|
86
86
|
var ${I}: {
|
|
87
87
|
t: GlobalT;
|
|
@@ -102,10 +102,13 @@ const { DefinePlugin } = require("webpack");
|
|
|
102
102
|
module.exports = {
|
|
103
103
|
${I}: DefinePlugin.runtimeValue(
|
|
104
104
|
(_ctx) => {
|
|
105
|
+
${"internal" === $ ? 'console.log("[@koine/i18n]:webpack-define:ctx.module", _ctx.module);' : ""};
|
|
105
106
|
return {
|
|
106
107
|
to: \`(function(routeId, params) {
|
|
107
108
|
const locale = global.__i18n_locale;
|
|
108
|
-
|
|
109
|
+
${"internal" === $ ? 'console.log("[@koine/i18n]:webpack-define:to", { locale });' : ""};
|
|
110
|
+
|
|
111
|
+
const defaultLocale = "${u}";
|
|
109
112
|
|
|
110
113
|
${formatTo.formatTo(t).$out("cjs", {
|
|
111
114
|
exports: !1,
|
|
@@ -115,7 +118,7 @@ module.exports = {
|
|
|
115
118
|
|
|
116
119
|
const lookup = {
|
|
117
120
|
${p(n, {
|
|
118
|
-
defaultLocale:
|
|
121
|
+
defaultLocale: u,
|
|
119
122
|
locales: d
|
|
120
123
|
})}
|
|
121
124
|
};
|
|
@@ -127,6 +130,7 @@ module.exports = {
|
|
|
127
130
|
})\`,
|
|
128
131
|
t: \`(function(i18nKey, params) {
|
|
129
132
|
const locale = global.__i18n_locale;
|
|
133
|
+
${"internal" === $ ? 'console.log("[@koine/i18n]:webpack-define:t", { locale });' : ""};
|
|
130
134
|
|
|
131
135
|
${tPluralise.tPluralise().$out("cjs", {
|
|
132
136
|
exports: !1,
|
|
@@ -134,7 +138,7 @@ module.exports = {
|
|
|
134
138
|
comments: !1
|
|
135
139
|
})}
|
|
136
140
|
|
|
137
|
-
${tInterpolateParams.tInterpolateParams(
|
|
141
|
+
${tInterpolateParams.tInterpolateParams(b).$out("cjs", {
|
|
138
142
|
exports: !1,
|
|
139
143
|
imports: !1,
|
|
140
144
|
comments: !1
|
|
@@ -142,8 +146,8 @@ module.exports = {
|
|
|
142
146
|
|
|
143
147
|
const lookup = {
|
|
144
148
|
${m(s, {
|
|
145
|
-
defaultLocale:
|
|
146
|
-
namespaceDelimiter:
|
|
149
|
+
defaultLocale: u,
|
|
150
|
+
namespaceDelimiter: f
|
|
147
151
|
})}
|
|
148
152
|
};
|
|
149
153
|
|
|
@@ -154,10 +158,9 @@ module.exports = {
|
|
|
154
158
|
})\`,
|
|
155
159
|
}
|
|
156
160
|
},
|
|
157
|
-
// _runtimeValueOptions:
|
|
158
161
|
{
|
|
159
162
|
fileDependencies: [
|
|
160
|
-
join("${
|
|
163
|
+
join("${g}", "${h}", "internal/webpack-define.js"),
|
|
161
164
|
],
|
|
162
165
|
},
|
|
163
166
|
),
|
|
@@ -8,9 +8,19 @@ declare const _default: (data: I18nCompiler.DataCode<"next">) => {
|
|
|
8
8
|
content: () => string;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
+
* Some useful webpack DefinePlugin context (`ctx`) object properties
|
|
12
|
+
* - `ctx.module.layer` one of `"ssr"` | `"rsc"` | ?
|
|
13
|
+
* - `ctx.module.buildInfo.rsc`
|
|
14
|
+
* - `ctx.module.resourceResolveData.context`
|
|
15
|
+
*
|
|
11
16
|
* @see
|
|
12
17
|
* - [DefinePlugin / add support for watch mode](https://github.com/webpack/webpack/issues/7717)
|
|
13
18
|
* - [support expressionMemberChain in DefinePlugin](https://github.com/webpack/webpack/pull/15562)
|
|
19
|
+
*
|
|
20
|
+
* NOTE: `DefinePlugin.runtimeValue` according to webpack types should return
|
|
21
|
+
* a `CodeValuePrimitive` (aka a string usually) type but returning an object
|
|
22
|
+
* also works and allows for a nicer namespaced global api. TODO: Verify that
|
|
23
|
+
* returning an object here is intentionally supportedas unknown as string;
|
|
14
24
|
*/
|
|
15
25
|
webpackDefine: {
|
|
16
26
|
dir: string;
|