@koine/i18n 2.0.0-beta.136 → 2.0.0-beta.138
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 +57 -0
- package/adapter-js/generators/setLocale.d.ts +12 -0
- package/adapter-js/generators/setLocale.esm.js +52 -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/I18nLayout.cjs.js +29 -9
- package/adapter-next/generators/router-app/I18nLayout.esm.js +29 -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 +22 -18
- package/adapter-next/generators/webpack-define.d.ts +10 -0
- package/adapter-next/generators/webpack-define.esm.js +22 -18
- 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 +6 -4
- package/adapter-react/generators/I18nLocaleContext.esm.js +6 -4
- 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/compiler/helpers.cjs.js +2 -0
- package/compiler/helpers.d.ts +1 -0
- package/compiler/helpers.esm.js +2 -1
- 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,57 @@
|
|
|
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
|
+
var helpers = require('../../compiler/helpers.cjs.js');
|
|
8
|
+
var imports = require('../../compiler/imports.cjs.js');
|
|
9
|
+
|
|
10
|
+
const setGlobalLocale = (e)=>new functions.FunctionsCompiler({
|
|
11
|
+
imports: [
|
|
12
|
+
new imports.ImportsCompiler({
|
|
13
|
+
path: "types",
|
|
14
|
+
named: [
|
|
15
|
+
{
|
|
16
|
+
name: "I18n",
|
|
17
|
+
type: !0
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
})
|
|
21
|
+
],
|
|
22
|
+
name: "setGlobalLocale",
|
|
23
|
+
args: [
|
|
24
|
+
{
|
|
25
|
+
name: "value",
|
|
26
|
+
type: "string",
|
|
27
|
+
optional: !1
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
before: ({ format: e })=>"ts" === e ? `
|
|
31
|
+
declare global {
|
|
32
|
+
var ${helpers.GLOBAL_I18N_IDENTIFIER}: I18n.Locale;
|
|
33
|
+
}` : "",
|
|
34
|
+
body: `global.${helpers.GLOBAL_I18N_IDENTIFIER} = value;`
|
|
35
|
+
});
|
|
36
|
+
var l = createAdapter.createGenerator("js", (e)=>({
|
|
37
|
+
setGlobalLocale: {
|
|
38
|
+
dir: "internal",
|
|
39
|
+
name: "setGlobalLocale",
|
|
40
|
+
ext: "ts",
|
|
41
|
+
index: !1,
|
|
42
|
+
content: ()=>`
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
${setGlobalLocale().$out("ts", {
|
|
47
|
+
imports: {
|
|
48
|
+
folderUp: 1
|
|
49
|
+
},
|
|
50
|
+
exports: "named"
|
|
51
|
+
})}
|
|
52
|
+
`
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
exports.default = l;
|
|
57
|
+
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,52 @@
|
|
|
1
|
+
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
|
+
import { FunctionsCompiler } from '../../compiler/functions.esm.js';
|
|
3
|
+
import { GLOBAL_I18N_IDENTIFIER } from '../../compiler/helpers.esm.js';
|
|
4
|
+
import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
5
|
+
|
|
6
|
+
const setGlobalLocale = (e)=>new FunctionsCompiler({
|
|
7
|
+
imports: [
|
|
8
|
+
new ImportsCompiler({
|
|
9
|
+
path: "types",
|
|
10
|
+
named: [
|
|
11
|
+
{
|
|
12
|
+
name: "I18n",
|
|
13
|
+
type: !0
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
})
|
|
17
|
+
],
|
|
18
|
+
name: "setGlobalLocale",
|
|
19
|
+
args: [
|
|
20
|
+
{
|
|
21
|
+
name: "value",
|
|
22
|
+
type: "string",
|
|
23
|
+
optional: !1
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
before: ({ format: e })=>"ts" === e ? `
|
|
27
|
+
declare global {
|
|
28
|
+
var ${GLOBAL_I18N_IDENTIFIER}: I18n.Locale;
|
|
29
|
+
}` : "",
|
|
30
|
+
body: `global.${GLOBAL_I18N_IDENTIFIER} = value;`
|
|
31
|
+
});
|
|
32
|
+
var l = createGenerator("js", (e)=>({
|
|
33
|
+
setGlobalLocale: {
|
|
34
|
+
dir: "internal",
|
|
35
|
+
name: "setGlobalLocale",
|
|
36
|
+
ext: "ts",
|
|
37
|
+
index: !1,
|
|
38
|
+
content: ()=>`
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
${setGlobalLocale().$out("ts", {
|
|
43
|
+
imports: {
|
|
44
|
+
folderUp: 1
|
|
45
|
+
},
|
|
46
|
+
exports: "named"
|
|
47
|
+
})}
|
|
48
|
+
`
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
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
|
});
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var getI18nDictionaries_inline = require('../../../adapter-js/generators/getI18nDictionaries_inline.cjs.js');
|
|
4
4
|
var createAdapter = require('../../../compiler/createAdapter.cjs.js');
|
|
5
|
+
var helpers = require('../../../compiler/helpers.cjs.js');
|
|
5
6
|
|
|
6
|
-
var a = createAdapter.createGenerator("next", (
|
|
7
|
-
let { options: { routes: { localeParamName:
|
|
7
|
+
var a = createAdapter.createGenerator("next", (a)=>{
|
|
8
|
+
let { options: { routes: { localeParamName: r } } } = a;
|
|
8
9
|
return {
|
|
9
10
|
I18nLayout: {
|
|
10
11
|
dir: createAdapter.createGenerator.dirs.server,
|
|
@@ -62,7 +63,7 @@ export const I18nLayout = async ({
|
|
|
62
63
|
*
|
|
63
64
|
* **For App Router only**
|
|
64
65
|
*/
|
|
65
|
-
I18nLayout.locale = (props: any) => props.params.${
|
|
66
|
+
I18nLayout.locale = (props: any) => props.params.${r};
|
|
66
67
|
|
|
67
68
|
type Configurator = {
|
|
68
69
|
/**
|
|
@@ -97,7 +98,7 @@ type Configurator = {
|
|
|
97
98
|
* };
|
|
98
99
|
* });
|
|
99
100
|
*
|
|
100
|
-
* // 2) export the metadata (maybe only in /app/[${
|
|
101
|
+
* // 2) export the metadata (maybe only in /app/[${r}]/layout.tsx)
|
|
101
102
|
*
|
|
102
103
|
* // with a sync function
|
|
103
104
|
* export const generateMetadata = layout.generateMetadata((props) => {
|
|
@@ -111,7 +112,7 @@ type Configurator = {
|
|
|
111
112
|
*
|
|
112
113
|
* // 3) export the default component
|
|
113
114
|
*
|
|
114
|
-
* // 3a) in /app/[${
|
|
115
|
+
* // 3a) in /app/[${r}]/layout.tsx)
|
|
115
116
|
*
|
|
116
117
|
* // only thing to do is to spread the i18nHtmlAttrs prop on the <html> element
|
|
117
118
|
* export default layout.default((props) => {
|
|
@@ -125,7 +126,7 @@ type Configurator = {
|
|
|
125
126
|
* );
|
|
126
127
|
* });
|
|
127
128
|
*
|
|
128
|
-
* // 3b) in /app/[${
|
|
129
|
+
* // 3b) in /app/[${r}]/ ...folders... /layout.tsx)
|
|
129
130
|
*
|
|
130
131
|
* // with a sync function (if you do not need to await)
|
|
131
132
|
* export default layout.default((props) => {
|
|
@@ -150,7 +151,7 @@ export const createI18nLayout = <
|
|
|
150
151
|
| Configurator,
|
|
151
152
|
) => {
|
|
152
153
|
const resolveConfigurator = async (props: I18n.Props<TProps>) => {
|
|
153
|
-
const localeParam = props.params?.${
|
|
154
|
+
const localeParam = props.params?.${r};
|
|
154
155
|
const config = configurator
|
|
155
156
|
? typeof configurator === "function"
|
|
156
157
|
? await configurator(props, localeParam)
|
|
@@ -162,7 +163,7 @@ export const createI18nLayout = <
|
|
|
162
163
|
};
|
|
163
164
|
|
|
164
165
|
return {
|
|
165
|
-
generateStaticParams: () => locales.map((l) => ({ ${
|
|
166
|
+
generateStaticParams: () => locales.map((l) => ({ ${r}: l })),
|
|
166
167
|
generateMetadata: (
|
|
167
168
|
impl: (
|
|
168
169
|
props: TProps & { locale: I18n.Locale },
|
|
@@ -177,6 +178,17 @@ export const createI18nLayout = <
|
|
|
177
178
|
default: (
|
|
178
179
|
impl: (
|
|
179
180
|
props: TProps & { locale: I18n.Locale } & React.PropsWithChildren<{
|
|
181
|
+
/**
|
|
182
|
+
* Render this in
|
|
183
|
+
* - \`/app/[${r}]/layout.tsx\`
|
|
184
|
+
* - \`/app/not-found.tsx\`
|
|
185
|
+
*/
|
|
186
|
+
I18nScript: React.ReactNode;
|
|
187
|
+
/**
|
|
188
|
+
* Spread this prop on the \`<html {...i18nHtmlAttrs}>\` element in:
|
|
189
|
+
* - \`/app/[${r}]/layout.tsx\`
|
|
190
|
+
* - \`/app/not-found.tsx\`
|
|
191
|
+
*/
|
|
180
192
|
i18nHtmlAttrs: Pick<
|
|
181
193
|
React.ComponentPropsWithoutRef<"html">,
|
|
182
194
|
"lang" | "dir"
|
|
@@ -189,7 +201,15 @@ export const createI18nLayout = <
|
|
|
189
201
|
const { locale } = config;
|
|
190
202
|
const dir = rtlLocales.includes(locale) ? "rtl" : "ltr";
|
|
191
203
|
const i18nHtmlAttrs = { lang: locale, dir };
|
|
192
|
-
const
|
|
204
|
+
const I18nScript = (
|
|
205
|
+
<script dangerouslySetInnerHTML={{ __html: \`window.global = window.global || {}; global.${helpers.GLOBAL_I18N_IDENTIFIER} = "\${locale}";\`}}></script>
|
|
206
|
+
);
|
|
207
|
+
const render = await impl({
|
|
208
|
+
locale,
|
|
209
|
+
I18nScript,
|
|
210
|
+
i18nHtmlAttrs,
|
|
211
|
+
...props
|
|
212
|
+
});
|
|
193
213
|
return <I18nLayout {...config}>{render}</I18nLayout>;
|
|
194
214
|
};
|
|
195
215
|
},
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { getI18nDictionaries_inline } from '../../../adapter-js/generators/getI18nDictionaries_inline.esm.js';
|
|
2
2
|
import { createGenerator } from '../../../compiler/createAdapter.esm.js';
|
|
3
|
+
import { GLOBAL_I18N_IDENTIFIER } from '../../../compiler/helpers.esm.js';
|
|
3
4
|
|
|
4
|
-
var a = createGenerator("next", (
|
|
5
|
-
let { options: { routes: { localeParamName:
|
|
5
|
+
var a = createGenerator("next", (a)=>{
|
|
6
|
+
let { options: { routes: { localeParamName: r } } } = a;
|
|
6
7
|
return {
|
|
7
8
|
I18nLayout: {
|
|
8
9
|
dir: createGenerator.dirs.server,
|
|
@@ -60,7 +61,7 @@ export const I18nLayout = async ({
|
|
|
60
61
|
*
|
|
61
62
|
* **For App Router only**
|
|
62
63
|
*/
|
|
63
|
-
I18nLayout.locale = (props: any) => props.params.${
|
|
64
|
+
I18nLayout.locale = (props: any) => props.params.${r};
|
|
64
65
|
|
|
65
66
|
type Configurator = {
|
|
66
67
|
/**
|
|
@@ -95,7 +96,7 @@ type Configurator = {
|
|
|
95
96
|
* };
|
|
96
97
|
* });
|
|
97
98
|
*
|
|
98
|
-
* // 2) export the metadata (maybe only in /app/[${
|
|
99
|
+
* // 2) export the metadata (maybe only in /app/[${r}]/layout.tsx)
|
|
99
100
|
*
|
|
100
101
|
* // with a sync function
|
|
101
102
|
* export const generateMetadata = layout.generateMetadata((props) => {
|
|
@@ -109,7 +110,7 @@ type Configurator = {
|
|
|
109
110
|
*
|
|
110
111
|
* // 3) export the default component
|
|
111
112
|
*
|
|
112
|
-
* // 3a) in /app/[${
|
|
113
|
+
* // 3a) in /app/[${r}]/layout.tsx)
|
|
113
114
|
*
|
|
114
115
|
* // only thing to do is to spread the i18nHtmlAttrs prop on the <html> element
|
|
115
116
|
* export default layout.default((props) => {
|
|
@@ -123,7 +124,7 @@ type Configurator = {
|
|
|
123
124
|
* );
|
|
124
125
|
* });
|
|
125
126
|
*
|
|
126
|
-
* // 3b) in /app/[${
|
|
127
|
+
* // 3b) in /app/[${r}]/ ...folders... /layout.tsx)
|
|
127
128
|
*
|
|
128
129
|
* // with a sync function (if you do not need to await)
|
|
129
130
|
* export default layout.default((props) => {
|
|
@@ -148,7 +149,7 @@ export const createI18nLayout = <
|
|
|
148
149
|
| Configurator,
|
|
149
150
|
) => {
|
|
150
151
|
const resolveConfigurator = async (props: I18n.Props<TProps>) => {
|
|
151
|
-
const localeParam = props.params?.${
|
|
152
|
+
const localeParam = props.params?.${r};
|
|
152
153
|
const config = configurator
|
|
153
154
|
? typeof configurator === "function"
|
|
154
155
|
? await configurator(props, localeParam)
|
|
@@ -160,7 +161,7 @@ export const createI18nLayout = <
|
|
|
160
161
|
};
|
|
161
162
|
|
|
162
163
|
return {
|
|
163
|
-
generateStaticParams: () => locales.map((l) => ({ ${
|
|
164
|
+
generateStaticParams: () => locales.map((l) => ({ ${r}: l })),
|
|
164
165
|
generateMetadata: (
|
|
165
166
|
impl: (
|
|
166
167
|
props: TProps & { locale: I18n.Locale },
|
|
@@ -175,6 +176,17 @@ export const createI18nLayout = <
|
|
|
175
176
|
default: (
|
|
176
177
|
impl: (
|
|
177
178
|
props: TProps & { locale: I18n.Locale } & React.PropsWithChildren<{
|
|
179
|
+
/**
|
|
180
|
+
* Render this in
|
|
181
|
+
* - \`/app/[${r}]/layout.tsx\`
|
|
182
|
+
* - \`/app/not-found.tsx\`
|
|
183
|
+
*/
|
|
184
|
+
I18nScript: React.ReactNode;
|
|
185
|
+
/**
|
|
186
|
+
* Spread this prop on the \`<html {...i18nHtmlAttrs}>\` element in:
|
|
187
|
+
* - \`/app/[${r}]/layout.tsx\`
|
|
188
|
+
* - \`/app/not-found.tsx\`
|
|
189
|
+
*/
|
|
178
190
|
i18nHtmlAttrs: Pick<
|
|
179
191
|
React.ComponentPropsWithoutRef<"html">,
|
|
180
192
|
"lang" | "dir"
|
|
@@ -187,7 +199,15 @@ export const createI18nLayout = <
|
|
|
187
199
|
const { locale } = config;
|
|
188
200
|
const dir = rtlLocales.includes(locale) ? "rtl" : "ltr";
|
|
189
201
|
const i18nHtmlAttrs = { lang: locale, dir };
|
|
190
|
-
const
|
|
202
|
+
const I18nScript = (
|
|
203
|
+
<script dangerouslySetInnerHTML={{ __html: \`window.global = window.global || {}; global.${GLOBAL_I18N_IDENTIFIER} = "\${locale}";\`}}></script>
|
|
204
|
+
);
|
|
205
|
+
const render = await impl({
|
|
206
|
+
locale,
|
|
207
|
+
I18nScript,
|
|
208
|
+
i18nHtmlAttrs,
|
|
209
|
+
...props
|
|
210
|
+
});
|
|
191
211
|
return <I18nLayout {...config}>{render}</I18nLayout>;
|
|
192
212
|
};
|
|
193
213
|
},
|
|
@@ -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
|