@koine/i18n 2.0.0-beta.196 → 2.0.0-beta.198
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/getI18nMetadata.cjs.js +3 -3
- package/adapter-js/generators/getI18nMetadata.esm.js +3 -3
- package/adapter-js/generators/types.cjs.js +41 -40
- package/adapter-js/generators/types.esm.js +41 -40
- package/adapter-next/plugin/rewrites.cjs.js +29 -30
- package/adapter-next/plugin/rewrites.d.ts +7 -0
- package/adapter-next/plugin/rewrites.esm.js +29 -31
- package/compiler/code/data-routes.cjs.js +42 -41
- package/compiler/code/data-routes.esm.js +42 -41
- package/compiler/code/data-translations.cjs.js +19 -18
- package/compiler/code/data-translations.esm.js +19 -18
- package/compiler/code/write.cjs.js +6 -5
- package/compiler/code/write.esm.js +6 -5
- package/i18nFormatRoutePathname.cjs.js +4 -3
- package/i18nFormatRoutePathname.esm.js +4 -3
- package/i18nInterpolateRouteParams.cjs.js +7 -6
- package/i18nInterpolateRouteParams.esm.js +7 -6
- package/package.json +3 -3
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var i = createAdapter.createGenerator("js", (
|
|
6
|
-
let { routes: { dynamicRoutes: a, staticRoutes: o } } =
|
|
5
|
+
var i = createAdapter.createGenerator("js", (t)=>{
|
|
6
|
+
let { routes: { dynamicRoutes: a, staticRoutes: o } } = t;
|
|
7
7
|
return {
|
|
8
8
|
getI18nMetadata: {
|
|
9
9
|
dir: createAdapter.createGenerator.dirs.internal,
|
|
@@ -47,7 +47,7 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
47
47
|
locales.forEach((locale) => {
|
|
48
48
|
alternates[locale] = formatUrl(${a.length && o.length ? `
|
|
49
49
|
// @ ts-ignore dynamic to fn typing
|
|
50
|
-
params ? to(id, params, locale) : to(id, locale),
|
|
50
|
+
params ? to(id, paramsByLocale?.[locale] ?? params, locale) : to(id, locale),
|
|
51
51
|
);` : a.length ? "to(id, paramsByLocale?.[locale] ?? params, locale));" : "to(id, locale));"}
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var i = createGenerator("js", (
|
|
4
|
-
let { routes: { dynamicRoutes: a, staticRoutes: o } } =
|
|
3
|
+
var i = createGenerator("js", (t)=>{
|
|
4
|
+
let { routes: { dynamicRoutes: a, staticRoutes: o } } = t;
|
|
5
5
|
return {
|
|
6
6
|
getI18nMetadata: {
|
|
7
7
|
dir: createGenerator.dirs.internal,
|
|
@@ -45,7 +45,7 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
45
45
|
locales.forEach((locale) => {
|
|
46
46
|
alternates[locale] = formatUrl(${a.length && o.length ? `
|
|
47
47
|
// @ ts-ignore dynamic to fn typing
|
|
48
|
-
params ? to(id, params, locale) : to(id, locale),
|
|
48
|
+
params ? to(id, paramsByLocale?.[locale] ?? params, locale) : to(id, locale),
|
|
49
49
|
);` : a.length ? "to(id, paramsByLocale?.[locale] ?? params, locale));" : "to(id, locale));"}
|
|
50
50
|
});
|
|
51
51
|
|
|
@@ -9,15 +9,16 @@ var imports = require('../../compiler/imports.cjs.js');
|
|
|
9
9
|
var pluralisation = require('../../compiler/pluralisation.cjs.js');
|
|
10
10
|
|
|
11
11
|
function getTypeLocale(e) {
|
|
12
|
-
return
|
|
12
|
+
return m(e.locales);
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
let T = /;\[\];/g, y = /;+/g;
|
|
15
|
+
function m(e, t = true) {
|
|
15
16
|
return (t ? e.sort() : e).filter(utils.isString).map((e)=>`"${e}"`).join(" | ");
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
18
|
+
function u(e, t) {
|
|
19
|
+
return m(Object.keys(e.byId).filter((a)=>t(a, e.byId[a]))) || "never";
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
+
function h(e) {
|
|
21
22
|
return `{
|
|
22
23
|
${e.join("\n ")}
|
|
23
24
|
}`;
|
|
@@ -32,13 +33,13 @@ const getImportTypes = ()=>new imports.ImportsCompiler({
|
|
|
32
33
|
]
|
|
33
34
|
});
|
|
34
35
|
var x = createAdapter.createGenerator("js", (i)=>{
|
|
35
|
-
let { options: { routes: { tokens: { idDelimiter:
|
|
36
|
-
let { config: i, routes:
|
|
36
|
+
let { options: { routes: { tokens: { idDelimiter: m } }, translations: { tokens: { keyDelimiter: f, namespaceDelimiter: I } } } } = i, R = function(s) {
|
|
37
|
+
let { config: i, routes: m, options: f } = s;
|
|
37
38
|
return {
|
|
38
39
|
Locale: getTypeLocale(i),
|
|
39
|
-
RouteIdStatic:
|
|
40
|
-
RouteIdDynamic:
|
|
41
|
-
RouteSpa:
|
|
40
|
+
RouteIdStatic: u(m, (e, { params: t })=>!t),
|
|
41
|
+
RouteIdDynamic: u(m, (e, { params: t })=>!!t),
|
|
42
|
+
RouteSpa: h(function(e, t, a) {
|
|
42
43
|
let n = Object.keys(t.byId).reduce((e, a)=>{
|
|
43
44
|
if (t.byId[a].inWildcard) for(let n = 0; n < t.wildcardIds.length; n++){
|
|
44
45
|
let s = t.wildcardIds[n];
|
|
@@ -55,28 +56,28 @@ var x = createAdapter.createGenerator("js", (i)=>{
|
|
|
55
56
|
s.push(`"${o}": { ${l.join(" ")} }`);
|
|
56
57
|
}
|
|
57
58
|
return s;
|
|
58
|
-
}(i,
|
|
59
|
-
RoutePathnames:
|
|
59
|
+
}(i, m, f)),
|
|
60
|
+
RoutePathnames: h(function(e, t) {
|
|
60
61
|
let a = [];
|
|
61
62
|
for(let n in t.byId){
|
|
62
63
|
let s = t.byId[n];
|
|
63
64
|
a.push(`"${s.id}": "${s.pathnames[e.defaultLocale]}";`);
|
|
64
65
|
}
|
|
65
66
|
return a;
|
|
66
|
-
}(i,
|
|
67
|
-
RouteParams:
|
|
67
|
+
}(i, m)),
|
|
68
|
+
RouteParams: h(function(e) {
|
|
68
69
|
let t = [];
|
|
69
70
|
for(let a in e.byId){
|
|
70
71
|
let { params: n } = e.byId[a];
|
|
71
72
|
n && t.push(`"${a}": ${helpers.compileDataParamsToType(n)};`);
|
|
72
73
|
}
|
|
73
74
|
return t;
|
|
74
|
-
}(
|
|
75
|
-
TranslationsDictionary:
|
|
76
|
-
let { config: { defaultLocale: o }, input: { translationFiles: i }, options: { translations: { ignorePaths:
|
|
77
|
-
for(let s = 0; s <
|
|
78
|
-
let { path: o, data: r } =
|
|
79
|
-
|
|
75
|
+
}(m)),
|
|
76
|
+
TranslationsDictionary: h(function(s) {
|
|
77
|
+
let { config: { defaultLocale: o }, input: { translationFiles: i }, options: { translations: { ignorePaths: m } } } = s, u = helpers.filterInputTranslationFiles(i, m, (e)=>e.locale === o), h = [];
|
|
78
|
+
for(let s = 0; s < u.length; s++){
|
|
79
|
+
let { path: o, data: r } = u[s], i = o.replace(".json", "");
|
|
80
|
+
h.push(`"${i}": ${function s(o) {
|
|
80
81
|
let r = "", i = "";
|
|
81
82
|
if (utils.isBoolean(o) ? i = "boolean" : utils.isString(o) && (i = "string"), i) r += i + ";";
|
|
82
83
|
else if (o) {
|
|
@@ -93,10 +94,10 @@ var x = createAdapter.createGenerator("js", (i)=>{
|
|
|
93
94
|
r += "};";
|
|
94
95
|
}
|
|
95
96
|
} else r += "";
|
|
96
|
-
return (r = r.replace(
|
|
97
|
+
return (r = r.replace(T, "[];")).replace(y, ";");
|
|
97
98
|
}(r)}`);
|
|
98
99
|
}
|
|
99
|
-
return
|
|
100
|
+
return h.sort();
|
|
100
101
|
}(s))
|
|
101
102
|
};
|
|
102
103
|
}(i);
|
|
@@ -148,7 +149,7 @@ export namespace I18n {
|
|
|
148
149
|
/**
|
|
149
150
|
* Any of the available locale code
|
|
150
151
|
*/
|
|
151
|
-
export type Locale = ${
|
|
152
|
+
export type Locale = ${R.Locale};
|
|
152
153
|
|
|
153
154
|
/**
|
|
154
155
|
* Utility to map values by all available locales
|
|
@@ -179,32 +180,32 @@ export namespace I18n {
|
|
|
179
180
|
/**
|
|
180
181
|
* The static routes available ids
|
|
181
182
|
*/
|
|
182
|
-
export type RouteIdStatic = ${
|
|
183
|
+
export type RouteIdStatic = ${R.RouteIdStatic};
|
|
183
184
|
|
|
184
185
|
/**
|
|
185
186
|
* The dynamic routes available ids
|
|
186
187
|
*/
|
|
187
|
-
export type RouteIdDynamic = ${
|
|
188
|
+
export type RouteIdDynamic = ${R.RouteIdDynamic};
|
|
188
189
|
|
|
189
190
|
/**
|
|
190
191
|
* Route dynamic params dictionary for each dynamic route id
|
|
191
192
|
*/
|
|
192
|
-
export type RouteParams = ${
|
|
193
|
+
export type RouteParams = ${R.RouteParams};
|
|
193
194
|
|
|
194
195
|
/**
|
|
195
196
|
* Map every route id to its actual pathname value for the default locale
|
|
196
197
|
*/
|
|
197
|
-
export type RoutePathnames = ${
|
|
198
|
+
export type RoutePathnames = ${R.RoutePathnames};
|
|
198
199
|
|
|
199
200
|
/**
|
|
200
201
|
* Map every SPA path divided by their roots to their actual pathname value for the default locale
|
|
201
202
|
*/
|
|
202
|
-
export type RouteSpa = ${
|
|
203
|
+
export type RouteSpa = ${R.RouteSpa};
|
|
203
204
|
|
|
204
205
|
/**
|
|
205
206
|
* Utility to join two route ids
|
|
206
207
|
*/
|
|
207
|
-
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${
|
|
208
|
+
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${m}\${Tail}\` extends RouteId ? \`\${Root}${m}\${Tail}\` : never;
|
|
208
209
|
|
|
209
210
|
/**
|
|
210
211
|
* Extract all children routes that starts with the given string
|
|
@@ -221,7 +222,7 @@ export namespace I18n {
|
|
|
221
222
|
* The types extracted from the translations JSON files, this is a little
|
|
222
223
|
* more sophisticated than the type result of \`typeof "./en/messages.json"\`
|
|
223
224
|
*/
|
|
224
|
-
export type TranslationsDictionary = ${
|
|
225
|
+
export type TranslationsDictionary = ${R.TranslationsDictionary};
|
|
225
226
|
|
|
226
227
|
/**
|
|
227
228
|
* Any of the available translations dictionary namespaces
|
|
@@ -243,13 +244,13 @@ export namespace I18n {
|
|
|
243
244
|
*
|
|
244
245
|
* \`T\` can be any of all possible paths begininng with a namespace:
|
|
245
246
|
* - \`namespace\` only a namespace
|
|
246
|
-
* - \`namespace${
|
|
247
|
-
* - \`namespace${
|
|
247
|
+
* - \`namespace${I}myKey\` sub dictionaries within a namespace
|
|
248
|
+
* - \`namespace${I}myKey.nested\` whatever nested level of nesting
|
|
248
249
|
*/
|
|
249
250
|
export type TranslationsChildrenOf<T extends TranslationAtGeneric> =
|
|
250
251
|
T extends TranslationsNamespace
|
|
251
252
|
? TranslationsPaths<TranslationsDictionary[T]>
|
|
252
|
-
: T extends \`\${infer Namespace}${
|
|
253
|
+
: T extends \`\${infer Namespace}${I}\${infer Path}\`
|
|
253
254
|
? Namespace extends TranslationsNamespace
|
|
254
255
|
? I18nUtils.Get<TranslationsDictionary[Namespace], Path> extends object
|
|
255
256
|
? TranslationsPaths<I18nUtils.Get<TranslationsDictionary[Namespace], Path>>
|
|
@@ -259,12 +260,12 @@ export namespace I18n {
|
|
|
259
260
|
|
|
260
261
|
/**
|
|
261
262
|
* All translations ancestor partial _paths_ of the given one, e.g. if \`T\` would be
|
|
262
|
-
* \`"area${
|
|
263
|
-
* \`"area${
|
|
263
|
+
* \`"area${f}main${f}[id]${f}edit"\` the generated type would be the union
|
|
264
|
+
* \`"area${f}main${f}[id]" | "area${f}main" | "area"\`.
|
|
264
265
|
*/
|
|
265
266
|
export type TranslationsAncestorsOf<
|
|
266
267
|
T extends string,
|
|
267
|
-
TSeparator extends string = "${
|
|
268
|
+
TSeparator extends string = "${f}",
|
|
268
269
|
> = I18nUtils.BuildRecursiveJoin<Split<T, TSeparator>, TSeparator>;
|
|
269
270
|
|
|
270
271
|
/**
|
|
@@ -272,13 +273,13 @@ export namespace I18n {
|
|
|
272
273
|
*
|
|
273
274
|
* \`T\` can be any of all possible paths begininng with a namespace:
|
|
274
275
|
* - \`namespace\` only a namespace
|
|
275
|
-
* - \`namespace${
|
|
276
|
-
* - \`namespace${
|
|
276
|
+
* - \`namespace${I}myKey\` sub dictionaries within a namespace
|
|
277
|
+
* - \`namespace${I}myKey${f}nested\` whatever nested level of nesting
|
|
277
278
|
*/
|
|
278
279
|
export type TranslationAt<T extends TranslationAtGeneric> =
|
|
279
280
|
T extends TranslationsNamespace
|
|
280
281
|
? TranslationsDictionary[T]
|
|
281
|
-
: T extends \`\${infer Namespace}${
|
|
282
|
+
: T extends \`\${infer Namespace}${I}\${infer Path}\`
|
|
282
283
|
? Namespace extends TranslationsNamespace
|
|
283
284
|
? I18nUtils.Get<TranslationsDictionary[Namespace], Path>
|
|
284
285
|
: never
|
|
@@ -297,7 +298,7 @@ export namespace I18n {
|
|
|
297
298
|
*
|
|
298
299
|
* \`T\` can be any of all possible paths:
|
|
299
300
|
* - \`myKey\` sub dictionaries within a namespace
|
|
300
|
-
* - \`myKey${
|
|
301
|
+
* - \`myKey${f}nested\` whatever nested level of nesting within a namespace
|
|
301
302
|
*/
|
|
302
303
|
export type TranslationAtNamespace<
|
|
303
304
|
TNamespace extends TranslationsNamespace,
|
|
@@ -5,15 +5,16 @@ import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
|
5
5
|
import { transformKeysForPlurals, hasPlurals, hasOnlyPluralKeys, pickNonPluralValue } from '../../compiler/pluralisation.esm.js';
|
|
6
6
|
|
|
7
7
|
function getTypeLocale(e) {
|
|
8
|
-
return
|
|
8
|
+
return m(e.locales);
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
let T = /;\[\];/g, y = /;+/g;
|
|
11
|
+
function m(e, t = true) {
|
|
11
12
|
return (t ? e.sort() : e).filter(isString).map((e)=>`"${e}"`).join(" | ");
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
-
return
|
|
14
|
+
function u(e, t) {
|
|
15
|
+
return m(Object.keys(e.byId).filter((a)=>t(a, e.byId[a]))) || "never";
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function h(e) {
|
|
17
18
|
return `{
|
|
18
19
|
${e.join("\n ")}
|
|
19
20
|
}`;
|
|
@@ -28,13 +29,13 @@ const getImportTypes = ()=>new ImportsCompiler({
|
|
|
28
29
|
]
|
|
29
30
|
});
|
|
30
31
|
var x = createGenerator("js", (i)=>{
|
|
31
|
-
let { options: { routes: { tokens: { idDelimiter:
|
|
32
|
-
let { config: i, routes:
|
|
32
|
+
let { options: { routes: { tokens: { idDelimiter: m } }, translations: { tokens: { keyDelimiter: f, namespaceDelimiter: I } } } } = i, R = function(s) {
|
|
33
|
+
let { config: i, routes: m, options: f } = s;
|
|
33
34
|
return {
|
|
34
35
|
Locale: getTypeLocale(i),
|
|
35
|
-
RouteIdStatic:
|
|
36
|
-
RouteIdDynamic:
|
|
37
|
-
RouteSpa:
|
|
36
|
+
RouteIdStatic: u(m, (e, { params: t })=>!t),
|
|
37
|
+
RouteIdDynamic: u(m, (e, { params: t })=>!!t),
|
|
38
|
+
RouteSpa: h(function(e, t, a) {
|
|
38
39
|
let n = Object.keys(t.byId).reduce((e, a)=>{
|
|
39
40
|
if (t.byId[a].inWildcard) for(let n = 0; n < t.wildcardIds.length; n++){
|
|
40
41
|
let s = t.wildcardIds[n];
|
|
@@ -51,28 +52,28 @@ var x = createGenerator("js", (i)=>{
|
|
|
51
52
|
s.push(`"${o}": { ${l.join(" ")} }`);
|
|
52
53
|
}
|
|
53
54
|
return s;
|
|
54
|
-
}(i,
|
|
55
|
-
RoutePathnames:
|
|
55
|
+
}(i, m, f)),
|
|
56
|
+
RoutePathnames: h(function(e, t) {
|
|
56
57
|
let a = [];
|
|
57
58
|
for(let n in t.byId){
|
|
58
59
|
let s = t.byId[n];
|
|
59
60
|
a.push(`"${s.id}": "${s.pathnames[e.defaultLocale]}";`);
|
|
60
61
|
}
|
|
61
62
|
return a;
|
|
62
|
-
}(i,
|
|
63
|
-
RouteParams:
|
|
63
|
+
}(i, m)),
|
|
64
|
+
RouteParams: h(function(e) {
|
|
64
65
|
let t = [];
|
|
65
66
|
for(let a in e.byId){
|
|
66
67
|
let { params: n } = e.byId[a];
|
|
67
68
|
n && t.push(`"${a}": ${compileDataParamsToType(n)};`);
|
|
68
69
|
}
|
|
69
70
|
return t;
|
|
70
|
-
}(
|
|
71
|
-
TranslationsDictionary:
|
|
72
|
-
let { config: { defaultLocale: o }, input: { translationFiles: i }, options: { translations: { ignorePaths:
|
|
73
|
-
for(let s = 0; s <
|
|
74
|
-
let { path: o, data: r } =
|
|
75
|
-
|
|
71
|
+
}(m)),
|
|
72
|
+
TranslationsDictionary: h(function(s) {
|
|
73
|
+
let { config: { defaultLocale: o }, input: { translationFiles: i }, options: { translations: { ignorePaths: m } } } = s, u = filterInputTranslationFiles(i, m, (e)=>e.locale === o), h = [];
|
|
74
|
+
for(let s = 0; s < u.length; s++){
|
|
75
|
+
let { path: o, data: r } = u[s], i = o.replace(".json", "");
|
|
76
|
+
h.push(`"${i}": ${function s(o) {
|
|
76
77
|
let r = "", i = "";
|
|
77
78
|
if (isBoolean(o) ? i = "boolean" : isString(o) && (i = "string"), i) r += i + ";";
|
|
78
79
|
else if (o) {
|
|
@@ -89,10 +90,10 @@ var x = createGenerator("js", (i)=>{
|
|
|
89
90
|
r += "};";
|
|
90
91
|
}
|
|
91
92
|
} else r += "";
|
|
92
|
-
return (r = r.replace(
|
|
93
|
+
return (r = r.replace(T, "[];")).replace(y, ";");
|
|
93
94
|
}(r)}`);
|
|
94
95
|
}
|
|
95
|
-
return
|
|
96
|
+
return h.sort();
|
|
96
97
|
}(s))
|
|
97
98
|
};
|
|
98
99
|
}(i);
|
|
@@ -144,7 +145,7 @@ export namespace I18n {
|
|
|
144
145
|
/**
|
|
145
146
|
* Any of the available locale code
|
|
146
147
|
*/
|
|
147
|
-
export type Locale = ${
|
|
148
|
+
export type Locale = ${R.Locale};
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* Utility to map values by all available locales
|
|
@@ -175,32 +176,32 @@ export namespace I18n {
|
|
|
175
176
|
/**
|
|
176
177
|
* The static routes available ids
|
|
177
178
|
*/
|
|
178
|
-
export type RouteIdStatic = ${
|
|
179
|
+
export type RouteIdStatic = ${R.RouteIdStatic};
|
|
179
180
|
|
|
180
181
|
/**
|
|
181
182
|
* The dynamic routes available ids
|
|
182
183
|
*/
|
|
183
|
-
export type RouteIdDynamic = ${
|
|
184
|
+
export type RouteIdDynamic = ${R.RouteIdDynamic};
|
|
184
185
|
|
|
185
186
|
/**
|
|
186
187
|
* Route dynamic params dictionary for each dynamic route id
|
|
187
188
|
*/
|
|
188
|
-
export type RouteParams = ${
|
|
189
|
+
export type RouteParams = ${R.RouteParams};
|
|
189
190
|
|
|
190
191
|
/**
|
|
191
192
|
* Map every route id to its actual pathname value for the default locale
|
|
192
193
|
*/
|
|
193
|
-
export type RoutePathnames = ${
|
|
194
|
+
export type RoutePathnames = ${R.RoutePathnames};
|
|
194
195
|
|
|
195
196
|
/**
|
|
196
197
|
* Map every SPA path divided by their roots to their actual pathname value for the default locale
|
|
197
198
|
*/
|
|
198
|
-
export type RouteSpa = ${
|
|
199
|
+
export type RouteSpa = ${R.RouteSpa};
|
|
199
200
|
|
|
200
201
|
/**
|
|
201
202
|
* Utility to join two route ids
|
|
202
203
|
*/
|
|
203
|
-
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${
|
|
204
|
+
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${m}\${Tail}\` extends RouteId ? \`\${Root}${m}\${Tail}\` : never;
|
|
204
205
|
|
|
205
206
|
/**
|
|
206
207
|
* Extract all children routes that starts with the given string
|
|
@@ -217,7 +218,7 @@ export namespace I18n {
|
|
|
217
218
|
* The types extracted from the translations JSON files, this is a little
|
|
218
219
|
* more sophisticated than the type result of \`typeof "./en/messages.json"\`
|
|
219
220
|
*/
|
|
220
|
-
export type TranslationsDictionary = ${
|
|
221
|
+
export type TranslationsDictionary = ${R.TranslationsDictionary};
|
|
221
222
|
|
|
222
223
|
/**
|
|
223
224
|
* Any of the available translations dictionary namespaces
|
|
@@ -239,13 +240,13 @@ export namespace I18n {
|
|
|
239
240
|
*
|
|
240
241
|
* \`T\` can be any of all possible paths begininng with a namespace:
|
|
241
242
|
* - \`namespace\` only a namespace
|
|
242
|
-
* - \`namespace${
|
|
243
|
-
* - \`namespace${
|
|
243
|
+
* - \`namespace${I}myKey\` sub dictionaries within a namespace
|
|
244
|
+
* - \`namespace${I}myKey.nested\` whatever nested level of nesting
|
|
244
245
|
*/
|
|
245
246
|
export type TranslationsChildrenOf<T extends TranslationAtGeneric> =
|
|
246
247
|
T extends TranslationsNamespace
|
|
247
248
|
? TranslationsPaths<TranslationsDictionary[T]>
|
|
248
|
-
: T extends \`\${infer Namespace}${
|
|
249
|
+
: T extends \`\${infer Namespace}${I}\${infer Path}\`
|
|
249
250
|
? Namespace extends TranslationsNamespace
|
|
250
251
|
? I18nUtils.Get<TranslationsDictionary[Namespace], Path> extends object
|
|
251
252
|
? TranslationsPaths<I18nUtils.Get<TranslationsDictionary[Namespace], Path>>
|
|
@@ -255,12 +256,12 @@ export namespace I18n {
|
|
|
255
256
|
|
|
256
257
|
/**
|
|
257
258
|
* All translations ancestor partial _paths_ of the given one, e.g. if \`T\` would be
|
|
258
|
-
* \`"area${
|
|
259
|
-
* \`"area${
|
|
259
|
+
* \`"area${f}main${f}[id]${f}edit"\` the generated type would be the union
|
|
260
|
+
* \`"area${f}main${f}[id]" | "area${f}main" | "area"\`.
|
|
260
261
|
*/
|
|
261
262
|
export type TranslationsAncestorsOf<
|
|
262
263
|
T extends string,
|
|
263
|
-
TSeparator extends string = "${
|
|
264
|
+
TSeparator extends string = "${f}",
|
|
264
265
|
> = I18nUtils.BuildRecursiveJoin<Split<T, TSeparator>, TSeparator>;
|
|
265
266
|
|
|
266
267
|
/**
|
|
@@ -268,13 +269,13 @@ export namespace I18n {
|
|
|
268
269
|
*
|
|
269
270
|
* \`T\` can be any of all possible paths begininng with a namespace:
|
|
270
271
|
* - \`namespace\` only a namespace
|
|
271
|
-
* - \`namespace${
|
|
272
|
-
* - \`namespace${
|
|
272
|
+
* - \`namespace${I}myKey\` sub dictionaries within a namespace
|
|
273
|
+
* - \`namespace${I}myKey${f}nested\` whatever nested level of nesting
|
|
273
274
|
*/
|
|
274
275
|
export type TranslationAt<T extends TranslationAtGeneric> =
|
|
275
276
|
T extends TranslationsNamespace
|
|
276
277
|
? TranslationsDictionary[T]
|
|
277
|
-
: T extends \`\${infer Namespace}${
|
|
278
|
+
: T extends \`\${infer Namespace}${I}\${infer Path}\`
|
|
278
279
|
? Namespace extends TranslationsNamespace
|
|
279
280
|
? I18nUtils.Get<TranslationsDictionary[Namespace], Path>
|
|
280
281
|
: never
|
|
@@ -293,7 +294,7 @@ export namespace I18n {
|
|
|
293
294
|
*
|
|
294
295
|
* \`T\` can be any of all possible paths:
|
|
295
296
|
* - \`myKey\` sub dictionaries within a namespace
|
|
296
|
-
* - \`myKey${
|
|
297
|
+
* - \`myKey${f}nested\` whatever nested level of nesting within a namespace
|
|
297
298
|
*/
|
|
298
299
|
export type TranslationAtNamespace<
|
|
299
300
|
TNamespace extends TranslationsNamespace,
|
|
@@ -4,56 +4,55 @@ var utils = require('@koine/utils');
|
|
|
4
4
|
var i18nFormatRoutePathname = require('../../i18nFormatRoutePathname.cjs.js');
|
|
5
5
|
var utils$1 = require('./utils.cjs.js');
|
|
6
6
|
|
|
7
|
-
function
|
|
8
|
-
let { localeSource: t, localeDestination:
|
|
9
|
-
t && (
|
|
10
|
-
let s = i18nFormatRoutePathname.i18nFormatRoutePathname(
|
|
11
|
-
|
|
12
|
-
let p =
|
|
13
|
-
if (s === p) return;
|
|
14
|
-
let u = {
|
|
7
|
+
function generatePathRewrite(e) {
|
|
8
|
+
let { localeSource: t, localeDestination: a, template: o, pathname: i, passLocale: n } = e, l = "";
|
|
9
|
+
t && (l = `/${t}`);
|
|
10
|
+
let s = i18nFormatRoutePathname.i18nFormatRoutePathname(l + i), c = "";
|
|
11
|
+
a && (c = `/${a}`);
|
|
12
|
+
let p = {
|
|
15
13
|
source: s,
|
|
16
|
-
destination:
|
|
14
|
+
destination: i18nFormatRoutePathname.i18nFormatRoutePathname(c + o)
|
|
17
15
|
};
|
|
18
|
-
return false ===
|
|
16
|
+
return false === n && (p.locale = false), p;
|
|
19
17
|
}
|
|
20
|
-
const generateRewriteForPathname = (e, t, r,
|
|
21
|
-
let { defaultLocale: i, hideDefaultLocaleInUrl: n, localeParamName:
|
|
18
|
+
const generateRewriteForPathname = (e, t, r, a, o)=>{
|
|
19
|
+
let { defaultLocale: i, hideDefaultLocaleInUrl: n, localeParamName: l } = e, s = t === i && n, c = {
|
|
22
20
|
template: r,
|
|
23
|
-
pathname:
|
|
21
|
+
pathname: a
|
|
24
22
|
};
|
|
25
|
-
|
|
26
|
-
...
|
|
23
|
+
l ? s ? o.push(generatePathRewrite({
|
|
24
|
+
...c,
|
|
27
25
|
localeDestination: t,
|
|
28
26
|
passLocale: false
|
|
29
|
-
})) :
|
|
30
|
-
...
|
|
27
|
+
})) : o.push(generatePathRewrite({
|
|
28
|
+
...c,
|
|
31
29
|
localeSource: t,
|
|
32
30
|
localeDestination: t,
|
|
33
31
|
passLocale: false
|
|
34
|
-
})) :
|
|
35
|
-
...
|
|
32
|
+
})) : a !== r && (s ? o.push(generatePathRewrite(c)) : o.push(generatePathRewrite({
|
|
33
|
+
...c,
|
|
36
34
|
localeSource: t,
|
|
37
35
|
passLocale: false
|
|
38
36
|
})));
|
|
39
37
|
};
|
|
40
|
-
let generateRewrites = (
|
|
41
|
-
let
|
|
42
|
-
...
|
|
43
|
-
localeParamName:
|
|
44
|
-
for(let e in
|
|
45
|
-
let t =
|
|
46
|
-
for(let
|
|
47
|
-
let
|
|
38
|
+
let generateRewrites = (o, { tokens: i, localeParamName: n, permanentRedirects: l }, s)=>{
|
|
39
|
+
let c = {
|
|
40
|
+
...o,
|
|
41
|
+
localeParamName: n}, p = RegExp(utils.escapeRegExp(i.idDelimiter), "g"), u = [];
|
|
42
|
+
for(let e in s){
|
|
43
|
+
let t = s[e], r = s[e].pathnames;
|
|
44
|
+
for(let o in r){
|
|
45
|
+
let i = r[o], n = e.replace(p, "/");
|
|
48
46
|
if (t.inWildcard) break;
|
|
49
|
-
generateRewriteForPathname(
|
|
47
|
+
generateRewriteForPathname(c, o, utils$1.transformPathname(n), utils$1.transformPathname(i), u), t.wildcard && generateRewriteForPathname(c, o, utils$1.transformPathname(n, t.wildcard), utils$1.transformPathname(i, t.wildcard), u);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
return utils.arrayUniqueByProperties(
|
|
50
|
+
return utils.arrayUniqueByProperties(u.filter(Boolean), [
|
|
53
51
|
"source",
|
|
54
52
|
"destination"
|
|
55
|
-
]).sort((e, t)=>e.source.localeCompare(t.source));
|
|
53
|
+
]).sort((e, t)=>e.destination.indexOf(":") > -1 ? 1 : t.destination.indexOf(":") > -1 ? -1 : 2 === i18nFormatRoutePathname.i18nFormatRoutePathname(e.source).split("/").length ? 2 === i18nFormatRoutePathname.i18nFormatRoutePathname(e.source).split("/").length && e.source.length > t.source.length ? 1 : -1 : e.source.localeCompare(t.source));
|
|
56
54
|
};
|
|
57
55
|
|
|
56
|
+
exports.generatePathRewrite = generatePathRewrite;
|
|
58
57
|
exports.generateRewriteForPathname = generateRewriteForPathname;
|
|
59
58
|
exports.generateRewrites = generateRewrites;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { Rewrite } from "next/dist/lib/load-custom-routes";
|
|
2
2
|
import type { CodeDataRoutesOptions } from "../../compiler/code/data-routes";
|
|
3
3
|
import type { I18nCompiler } from "../../compiler/types";
|
|
4
|
+
export declare function generatePathRewrite(arg: {
|
|
5
|
+
localeSource?: I18nCompiler.Locale;
|
|
6
|
+
localeDestination?: I18nCompiler.Locale;
|
|
7
|
+
template: string;
|
|
8
|
+
pathname: string;
|
|
9
|
+
passLocale?: boolean;
|
|
10
|
+
}): Rewrite;
|
|
4
11
|
export declare const generateRewriteForPathname: (config: Pick<I18nCompiler.Config, "defaultLocale" | "hideDefaultLocaleInUrl" | "trailingSlash"> & Pick<CodeDataRoutesOptions, "localeParamName">, locale: string, template: string, pathname: string, rewrites: (Rewrite | undefined)[]) => void;
|
|
5
12
|
/**
|
|
6
13
|
* TODO: maybe write directly the vercel configuration?
|
|
@@ -2,55 +2,53 @@ import { escapeRegExp, arrayUniqueByProperties } from '@koine/utils';
|
|
|
2
2
|
import { i18nFormatRoutePathname } from '../../i18nFormatRoutePathname.esm.js';
|
|
3
3
|
import { transformPathname } from './utils.esm.js';
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
let { localeSource: t, localeDestination:
|
|
7
|
-
t && (
|
|
8
|
-
let s = i18nFormatRoutePathname(
|
|
9
|
-
|
|
10
|
-
let p =
|
|
11
|
-
if (s === p) return;
|
|
12
|
-
let u = {
|
|
5
|
+
function generatePathRewrite(e) {
|
|
6
|
+
let { localeSource: t, localeDestination: a, template: o, pathname: i, passLocale: n } = e, l = "";
|
|
7
|
+
t && (l = `/${t}`);
|
|
8
|
+
let s = i18nFormatRoutePathname(l + i), c = "";
|
|
9
|
+
a && (c = `/${a}`);
|
|
10
|
+
let p = {
|
|
13
11
|
source: s,
|
|
14
|
-
destination:
|
|
12
|
+
destination: i18nFormatRoutePathname(c + o)
|
|
15
13
|
};
|
|
16
|
-
return false ===
|
|
14
|
+
return false === n && (p.locale = false), p;
|
|
17
15
|
}
|
|
18
|
-
const generateRewriteForPathname = (e, t, r,
|
|
19
|
-
let { defaultLocale: i, hideDefaultLocaleInUrl: n, localeParamName:
|
|
16
|
+
const generateRewriteForPathname = (e, t, r, a, o)=>{
|
|
17
|
+
let { defaultLocale: i, hideDefaultLocaleInUrl: n, localeParamName: l } = e, s = t === i && n, c = {
|
|
20
18
|
template: r,
|
|
21
|
-
pathname:
|
|
19
|
+
pathname: a
|
|
22
20
|
};
|
|
23
|
-
|
|
24
|
-
...
|
|
21
|
+
l ? s ? o.push(generatePathRewrite({
|
|
22
|
+
...c,
|
|
25
23
|
localeDestination: t,
|
|
26
24
|
passLocale: false
|
|
27
|
-
})) :
|
|
28
|
-
...
|
|
25
|
+
})) : o.push(generatePathRewrite({
|
|
26
|
+
...c,
|
|
29
27
|
localeSource: t,
|
|
30
28
|
localeDestination: t,
|
|
31
29
|
passLocale: false
|
|
32
|
-
})) :
|
|
33
|
-
...
|
|
30
|
+
})) : a !== r && (s ? o.push(generatePathRewrite(c)) : o.push(generatePathRewrite({
|
|
31
|
+
...c,
|
|
34
32
|
localeSource: t,
|
|
35
33
|
passLocale: false
|
|
36
34
|
})));
|
|
37
35
|
};
|
|
38
|
-
let generateRewrites = (
|
|
39
|
-
let
|
|
40
|
-
...
|
|
41
|
-
localeParamName:
|
|
42
|
-
for(let e in
|
|
43
|
-
let t =
|
|
44
|
-
for(let
|
|
45
|
-
let
|
|
36
|
+
let generateRewrites = (o, { tokens: i, localeParamName: n, permanentRedirects: l }, s)=>{
|
|
37
|
+
let c = {
|
|
38
|
+
...o,
|
|
39
|
+
localeParamName: n}, p = RegExp(escapeRegExp(i.idDelimiter), "g"), u = [];
|
|
40
|
+
for(let e in s){
|
|
41
|
+
let t = s[e], r = s[e].pathnames;
|
|
42
|
+
for(let o in r){
|
|
43
|
+
let i = r[o], n = e.replace(p, "/");
|
|
46
44
|
if (t.inWildcard) break;
|
|
47
|
-
generateRewriteForPathname(
|
|
45
|
+
generateRewriteForPathname(c, o, transformPathname(n), transformPathname(i), u), t.wildcard && generateRewriteForPathname(c, o, transformPathname(n, t.wildcard), transformPathname(i, t.wildcard), u);
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
|
-
return arrayUniqueByProperties(
|
|
48
|
+
return arrayUniqueByProperties(u.filter(Boolean), [
|
|
51
49
|
"source",
|
|
52
50
|
"destination"
|
|
53
|
-
]).sort((e, t)=>e.source.localeCompare(t.source));
|
|
51
|
+
]).sort((e, t)=>e.destination.indexOf(":") > -1 ? 1 : t.destination.indexOf(":") > -1 ? -1 : 2 === i18nFormatRoutePathname(e.source).split("/").length ? 2 === i18nFormatRoutePathname(e.source).split("/").length && e.source.length > t.source.length ? 1 : -1 : e.source.localeCompare(t.source));
|
|
54
52
|
};
|
|
55
53
|
|
|
56
|
-
export { generateRewriteForPathname, generateRewrites };
|
|
54
|
+
export { generatePathRewrite, generateRewriteForPathname, generateRewrites };
|