@koine/i18n 2.0.0-beta.51 → 2.0.0-beta.52
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/api.cjs.js +168 -29
- package/api.esm.js +167 -30
- package/compiler/code/data.d.ts +2 -1
- package/compiler/code/index.d.ts +1 -1
- package/compiler.cjs.js +1 -1
- package/next.cjs.js +14 -128
- package/next.esm.js +13 -127
- package/package.json +3 -3
package/api.cjs.js
CHANGED
|
@@ -4,8 +4,8 @@ var node_fs = require('node:fs');
|
|
|
4
4
|
var node_path = require('node:path');
|
|
5
5
|
var node = require('@koine/node');
|
|
6
6
|
var utils$1 = require('@koine/utils');
|
|
7
|
-
var t$4 = require('typescript');
|
|
8
7
|
var formatRoutePathname = require('./formatRoutePathname.cjs.js');
|
|
8
|
+
var t$4 = require('typescript');
|
|
9
9
|
var minimatch = require('minimatch');
|
|
10
10
|
var write = require('./write.cjs.js');
|
|
11
11
|
var utils = require('next/dist/shared/lib/utils');
|
|
@@ -64,7 +64,7 @@ let getInputData = async (e)=>{
|
|
|
64
64
|
return utils.isAbsoluteUrl(o) ? await getInputDataRemote(e) : await write.getInputDataLocal(e);
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
var e$
|
|
67
|
+
var e$4 = (({ config: e })=>`
|
|
68
68
|
import { locales } from "./locales";
|
|
69
69
|
import { defaultLocale } from "./defaultLocale";
|
|
70
70
|
|
|
@@ -87,7 +87,7 @@ export const defaultLocale: I18n.Locale = "${e.defaultLocale}";
|
|
|
87
87
|
export default defaultLocale;
|
|
88
88
|
`);
|
|
89
89
|
|
|
90
|
-
var o$
|
|
90
|
+
var o$4 = (()=>`
|
|
91
91
|
import { locales } from "./locales";
|
|
92
92
|
import { to } from "./to";
|
|
93
93
|
import type { I18n } from "./types";
|
|
@@ -198,7 +198,7 @@ export const pathnameToRouteId = (pathname: string) =>
|
|
|
198
198
|
export default pathnameToRouteId;
|
|
199
199
|
`);
|
|
200
200
|
|
|
201
|
-
var r$
|
|
201
|
+
var r$4 = (({ routes: t })=>{
|
|
202
202
|
let e = JSON.stringify(Object.fromEntries(Object.entries(t).map(([t, { pathnames: e }])=>[
|
|
203
203
|
t,
|
|
204
204
|
e
|
|
@@ -313,7 +313,7 @@ export function to<TRoute extends I18n.RouteId>(
|
|
|
313
313
|
export default to;
|
|
314
314
|
`);
|
|
315
315
|
|
|
316
|
-
let r$
|
|
316
|
+
let r$3 = (t, e)=>{
|
|
317
317
|
let { defaultLocale: r } = t, l = "";
|
|
318
318
|
return utils$1.forin(e, (t, o)=>{
|
|
319
319
|
t !== r && o !== e[r] && (l += `locale === "${t}" ? "${o}" : `);
|
|
@@ -330,7 +330,7 @@ import type { I18n } from "./types";
|
|
|
330
330
|
n ? `params: ${i}` : "",
|
|
331
331
|
m ? "" : "locale?: I18n.Locale"
|
|
332
332
|
].filter(Boolean).join(", "), c = m ? '""' : "locale", f = n ? ", params" : "";
|
|
333
|
-
$ += `export let ${p} = (${s}) => `, utils$1.isString(a) ? $ += `toFormat(${c}, "${a}"${f});` : $ += `toFormat(${c}, ${r$
|
|
333
|
+
$ += `export let ${p} = (${s}) => `, utils$1.isString(a) ? $ += `toFormat(${c}, "${a}"${f});` : $ += `toFormat(${c}, ${r$3(l, a)}${f});`, $ += `\n`;
|
|
334
334
|
}), $;
|
|
335
335
|
});
|
|
336
336
|
|
|
@@ -471,7 +471,7 @@ let c$1 = (e, a)=>{
|
|
|
471
471
|
t && a.push(`"${e}": { ${dataParamsToTsInterfaceBody(t)} };`);
|
|
472
472
|
}), a;
|
|
473
473
|
}, d$1 = (e, t)=>Object.keys(e).filter((a)=>t(a, e[a])).sort().map((e)=>`"${e}"`).join(" | ");
|
|
474
|
-
var l$
|
|
474
|
+
var l$2 = (({ config: e, input: t, routes: a })=>{
|
|
475
475
|
let n = d$1(a, (e, { params: t })=>!t), s = d$1(a, (e, { params: t })=>!!t);
|
|
476
476
|
return `
|
|
477
477
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
@@ -719,11 +719,11 @@ export namespace I18n {
|
|
|
719
719
|
`;
|
|
720
720
|
});
|
|
721
721
|
|
|
722
|
-
var e$
|
|
722
|
+
var e$3 = (()=>({
|
|
723
723
|
files: [
|
|
724
724
|
{
|
|
725
725
|
name: "config",
|
|
726
|
-
fn: e$
|
|
726
|
+
fn: e$4,
|
|
727
727
|
ext: "ts",
|
|
728
728
|
index: !0
|
|
729
729
|
},
|
|
@@ -735,7 +735,7 @@ var e$2 = (()=>({
|
|
|
735
735
|
},
|
|
736
736
|
{
|
|
737
737
|
name: "deriveLocalisedPathnames",
|
|
738
|
-
fn: o$
|
|
738
|
+
fn: o$4,
|
|
739
739
|
ext: "ts",
|
|
740
740
|
index: !0
|
|
741
741
|
},
|
|
@@ -759,7 +759,7 @@ var e$2 = (()=>({
|
|
|
759
759
|
},
|
|
760
760
|
{
|
|
761
761
|
name: "routes",
|
|
762
|
-
fn: r$
|
|
762
|
+
fn: r$4,
|
|
763
763
|
ext: "ts",
|
|
764
764
|
index: !0
|
|
765
765
|
},
|
|
@@ -800,14 +800,14 @@ var e$2 = (()=>({
|
|
|
800
800
|
},
|
|
801
801
|
{
|
|
802
802
|
name: "types",
|
|
803
|
-
fn: l$
|
|
803
|
+
fn: l$2,
|
|
804
804
|
ext: "ts",
|
|
805
805
|
index: !0
|
|
806
806
|
}
|
|
807
807
|
]
|
|
808
808
|
}));
|
|
809
809
|
|
|
810
|
-
var e$
|
|
810
|
+
var e$2 = (()=>`
|
|
811
811
|
"use client";
|
|
812
812
|
|
|
813
813
|
import _DynamicNamespaces from "next-translate/DynamicNamespaces";
|
|
@@ -947,7 +947,7 @@ var t$1 = (()=>({
|
|
|
947
947
|
files: [
|
|
948
948
|
{
|
|
949
949
|
name: "DynamicNamespaces",
|
|
950
|
-
fn: e$
|
|
950
|
+
fn: e$2,
|
|
951
951
|
ext: "tsx",
|
|
952
952
|
index: !0
|
|
953
953
|
},
|
|
@@ -983,7 +983,131 @@ var t$1 = (()=>({
|
|
|
983
983
|
]
|
|
984
984
|
}));
|
|
985
985
|
|
|
986
|
-
|
|
986
|
+
function transformPathname(n, e) {
|
|
987
|
+
return "/" + e.split("/").filter(Boolean).map((n)=>n.startsWith("[") ? `:${encodeURIComponent(n.slice(1, -1))}` : `${encodeURIComponent(n)}`).join("/") + (n.wildcard ? "/:wildcard*" : "");
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
function l$1(e) {
|
|
991
|
+
let { localeSource: o, localeDestination: l, template: n, pathname: r, permanent: a } = e, i = formatRoutePathname.formatRoutePathname((o ? `${o}/` : "") + n), c = formatRoutePathname.formatRoutePathname((l ? `${l}/` : "") + r);
|
|
992
|
+
if (i !== c) return {
|
|
993
|
+
source: i,
|
|
994
|
+
destination: c,
|
|
995
|
+
permanent: !!a
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
let generateRedirects = (t, n, r = "", a = !1)=>{
|
|
999
|
+
let { defaultLocale: i, hideDefaultLocaleInUrl: c } = t, s = [];
|
|
1000
|
+
for(let e in n){
|
|
1001
|
+
let t = n[e], p = n[e].pathnames;
|
|
1002
|
+
for(let n in p){
|
|
1003
|
+
let u = p[n], m = transformPathname(t, e.replace(/\./g, "/")), f = transformPathname(t, u);
|
|
1004
|
+
if (t.inWildcard) break;
|
|
1005
|
+
let h = n === i && !c, d = n === i && c;
|
|
1006
|
+
r ? h ? s.push(l$1({
|
|
1007
|
+
localeDestination: n,
|
|
1008
|
+
permanent: a,
|
|
1009
|
+
template: m,
|
|
1010
|
+
pathname: f
|
|
1011
|
+
})) : d ? s.push(l$1({
|
|
1012
|
+
localeSource: n,
|
|
1013
|
+
permanent: a,
|
|
1014
|
+
template: m,
|
|
1015
|
+
pathname: f
|
|
1016
|
+
})) : n !== i ? s.push(l$1({
|
|
1017
|
+
localeSource: n,
|
|
1018
|
+
localeDestination: n,
|
|
1019
|
+
permanent: a,
|
|
1020
|
+
template: m,
|
|
1021
|
+
pathname: f
|
|
1022
|
+
})) : s.push(l$1({
|
|
1023
|
+
permanent: a,
|
|
1024
|
+
template: m,
|
|
1025
|
+
pathname: f
|
|
1026
|
+
})) : f !== m && (h ? s.push(l$1({
|
|
1027
|
+
localeDestination: n,
|
|
1028
|
+
permanent: a,
|
|
1029
|
+
template: m,
|
|
1030
|
+
pathname: f
|
|
1031
|
+
})) : n !== i ? s.push(l$1({
|
|
1032
|
+
localeSource: n,
|
|
1033
|
+
localeDestination: n,
|
|
1034
|
+
permanent: a,
|
|
1035
|
+
template: m,
|
|
1036
|
+
pathname: f
|
|
1037
|
+
})) : s.push(l$1({
|
|
1038
|
+
permanent: a,
|
|
1039
|
+
template: m,
|
|
1040
|
+
pathname: f
|
|
1041
|
+
})));
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
return utils$1.arrayUniqueByProperties(s.filter(Boolean), [
|
|
1045
|
+
"source",
|
|
1046
|
+
"destination"
|
|
1047
|
+
]).map((e)=>r ? e : {
|
|
1048
|
+
...e,
|
|
1049
|
+
locale: !1
|
|
1050
|
+
});
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
var e$1 = (({ config: e, routes: t })=>{
|
|
1054
|
+
let l = JSON.stringify(generateRedirects(e, t), null, 2);
|
|
1055
|
+
return `module.exports = ${l}`;
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
function r$2(e) {
|
|
1059
|
+
let { localeSource: o, localeDestination: r, localeParam: l, template: i, pathname: n } = e, a = "";
|
|
1060
|
+
o ? a = `/${o}` : l && (a = `/:${l}`);
|
|
1061
|
+
let s = formatRoutePathname.formatRoutePathname(a + n), c = "";
|
|
1062
|
+
r ? c = `/${r}` : l && (c = `/:${l}`);
|
|
1063
|
+
let u = formatRoutePathname.formatRoutePathname(c + i);
|
|
1064
|
+
if (s !== u) return {
|
|
1065
|
+
source: s,
|
|
1066
|
+
destination: u
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
let generateRewrites = (t, l, i = "")=>{
|
|
1070
|
+
let { defaultLocale: n, hideDefaultLocaleInUrl: a } = t, s = [];
|
|
1071
|
+
for(let e in l){
|
|
1072
|
+
let t = l[e], c = l[e].pathnames;
|
|
1073
|
+
for(let l in c){
|
|
1074
|
+
let u = c[l], f = l === n && !a, p = l === n && a, m = transformPathname(t, e.replace(/\./g, "/")), h = transformPathname(t, u);
|
|
1075
|
+
if (t.inWildcard) break;
|
|
1076
|
+
i ? p ? s.push(r$2({
|
|
1077
|
+
localeDestination: l,
|
|
1078
|
+
route: t,
|
|
1079
|
+
template: m,
|
|
1080
|
+
pathname: h
|
|
1081
|
+
})) : s.push(r$2({
|
|
1082
|
+
localeDestination: l,
|
|
1083
|
+
localeSource: l,
|
|
1084
|
+
route: t,
|
|
1085
|
+
template: m,
|
|
1086
|
+
pathname: h
|
|
1087
|
+
})) : h !== m && (l !== n || f ? s.push(r$2({
|
|
1088
|
+
localeSource: l,
|
|
1089
|
+
route: t,
|
|
1090
|
+
template: m,
|
|
1091
|
+
pathname: h
|
|
1092
|
+
})) : s.push(r$2({
|
|
1093
|
+
route: t,
|
|
1094
|
+
template: m,
|
|
1095
|
+
pathname: h
|
|
1096
|
+
})));
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
return utils$1.arrayUniqueByProperties(s.filter(Boolean), [
|
|
1100
|
+
"source",
|
|
1101
|
+
"destination"
|
|
1102
|
+
]);
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
var t = (({ config: e, routes: t })=>{
|
|
1106
|
+
let l = JSON.stringify(generateRewrites(e, t), null, 2);
|
|
1107
|
+
return `module.exports = ${l}`;
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
var n$2 = (()=>`
|
|
987
1111
|
"use client";
|
|
988
1112
|
|
|
989
1113
|
import { useEffect, useState } from "react";
|
|
@@ -1004,7 +1128,7 @@ export function useCurrentLocalisedPathnames() {
|
|
|
1004
1128
|
export default useCurrentLocalisedPathnames;
|
|
1005
1129
|
`);
|
|
1006
1130
|
|
|
1007
|
-
var
|
|
1131
|
+
var r$1 = (({ config: e })=>`
|
|
1008
1132
|
import { useRouter } from "next/router";
|
|
1009
1133
|
import type { I18n } from "./types";
|
|
1010
1134
|
|
|
@@ -1024,7 +1148,7 @@ export const useRouteId = () =>
|
|
|
1024
1148
|
export default useRouteId;
|
|
1025
1149
|
`);
|
|
1026
1150
|
|
|
1027
|
-
var
|
|
1151
|
+
var o$3 = (()=>`
|
|
1028
1152
|
"use client";
|
|
1029
1153
|
|
|
1030
1154
|
import { to } from "./to";
|
|
@@ -1057,15 +1181,25 @@ var n$1 = (()=>({
|
|
|
1057
1181
|
"js"
|
|
1058
1182
|
],
|
|
1059
1183
|
files: [
|
|
1184
|
+
{
|
|
1185
|
+
name: "next-redirects",
|
|
1186
|
+
fn: e$1,
|
|
1187
|
+
ext: "js"
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
name: "next-rewrites",
|
|
1191
|
+
fn: t,
|
|
1192
|
+
ext: "js"
|
|
1193
|
+
},
|
|
1060
1194
|
{
|
|
1061
1195
|
name: "useCurrentLocalisedPathnames",
|
|
1062
|
-
fn:
|
|
1196
|
+
fn: n$2,
|
|
1063
1197
|
ext: "ts",
|
|
1064
1198
|
index: !0
|
|
1065
1199
|
},
|
|
1066
1200
|
{
|
|
1067
1201
|
name: "useLocale",
|
|
1068
|
-
fn:
|
|
1202
|
+
fn: r$1,
|
|
1069
1203
|
ext: "ts",
|
|
1070
1204
|
index: !0
|
|
1071
1205
|
},
|
|
@@ -1077,7 +1211,7 @@ var n$1 = (()=>({
|
|
|
1077
1211
|
},
|
|
1078
1212
|
{
|
|
1079
1213
|
name: "useTo",
|
|
1080
|
-
fn:
|
|
1214
|
+
fn: o$3,
|
|
1081
1215
|
ext: "ts",
|
|
1082
1216
|
index: !0
|
|
1083
1217
|
}
|
|
@@ -1085,7 +1219,7 @@ var n$1 = (()=>({
|
|
|
1085
1219
|
}));
|
|
1086
1220
|
|
|
1087
1221
|
let a = {
|
|
1088
|
-
js: e$
|
|
1222
|
+
js: e$3,
|
|
1089
1223
|
next: n$1,
|
|
1090
1224
|
"next-translate": t$1
|
|
1091
1225
|
}, r = (e)=>{
|
|
@@ -1282,18 +1416,21 @@ const codeDataTranslationsOptions = {
|
|
|
1282
1416
|
fnsPrefix: "",
|
|
1283
1417
|
createArrayIndexBasedFns: !1
|
|
1284
1418
|
};
|
|
1285
|
-
|
|
1419
|
+
let e = {
|
|
1286
1420
|
routes: codeDataRoutesOptions,
|
|
1287
1421
|
translations: codeDataTranslationsOptions
|
|
1288
1422
|
};
|
|
1289
|
-
let getCodeData = (s,
|
|
1290
|
-
let
|
|
1291
|
-
return
|
|
1423
|
+
let getCodeData = (s, n, r)=>{
|
|
1424
|
+
let i = utils$1.objectMergeWithDefaults(e, n);
|
|
1425
|
+
return i.translations.ignorePaths.push(i.routes.translationJsonFileName), r = {
|
|
1426
|
+
...r,
|
|
1427
|
+
localesFolders: r.localesFolders.sort((t, o)=>s.defaultLocale ? -1 : t.localeCompare(o))
|
|
1428
|
+
}, {
|
|
1292
1429
|
config: s,
|
|
1293
|
-
options:
|
|
1294
|
-
input:
|
|
1295
|
-
routes: getCodeDataRoutes(s,
|
|
1296
|
-
translations: getCodeDataTranslations(s,
|
|
1430
|
+
options: i,
|
|
1431
|
+
input: r,
|
|
1432
|
+
routes: getCodeDataRoutes(s, i.routes, r),
|
|
1433
|
+
translations: getCodeDataTranslations(s, i.translations, r)
|
|
1297
1434
|
};
|
|
1298
1435
|
};
|
|
1299
1436
|
|
|
@@ -1316,4 +1453,6 @@ let i18nCompiler = async (p)=>{
|
|
|
1316
1453
|
};
|
|
1317
1454
|
};
|
|
1318
1455
|
|
|
1456
|
+
exports.generateRedirects = generateRedirects;
|
|
1457
|
+
exports.generateRewrites = generateRewrites;
|
|
1319
1458
|
exports.i18nCompiler = i18nCompiler;
|
package/api.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import { g as getInputDataLocal, b as getConfig, w as writeInput, a as getSummar
|
|
|
2
2
|
import { isAbsoluteUrl } from 'next/dist/shared/lib/utils';
|
|
3
3
|
import { request } from 'node:https';
|
|
4
4
|
import { minimatch } from 'minimatch';
|
|
5
|
-
import { forin, isPrimitive, isString, isNumber, isBoolean, isArray, areEqual, changeCaseCamel, splitReverse, isNumericLiteral, split, objectPick, isObject, objectFlat, objectSortByKeysMatching, objectMergeWithDefaults } from '@koine/utils';
|
|
5
|
+
import { forin, isPrimitive, isString, isNumber, isBoolean, isArray, areEqual, changeCaseCamel, splitReverse, isNumericLiteral, split, objectPick, isObject, arrayUniqueByProperties, objectFlat, objectSortByKeysMatching, objectMergeWithDefaults } from '@koine/utils';
|
|
6
6
|
import { f as formatRoutePathname } from './formatRoutePathname.esm.js';
|
|
7
7
|
import { join, dirname, basename, extname, sep } from 'node:path';
|
|
8
8
|
import { rmSync } from 'node:fs';
|
|
@@ -40,7 +40,7 @@ let getInputData = async (e)=>{
|
|
|
40
40
|
return isAbsoluteUrl(o) ? await getInputDataRemote(e) : await getInputDataLocal(e);
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
var e$
|
|
43
|
+
var e$4 = (({ config: e })=>`
|
|
44
44
|
import { locales } from "./locales";
|
|
45
45
|
import { defaultLocale } from "./defaultLocale";
|
|
46
46
|
|
|
@@ -63,7 +63,7 @@ export const defaultLocale: I18n.Locale = "${e.defaultLocale}";
|
|
|
63
63
|
export default defaultLocale;
|
|
64
64
|
`);
|
|
65
65
|
|
|
66
|
-
var o$
|
|
66
|
+
var o$4 = (()=>`
|
|
67
67
|
import { locales } from "./locales";
|
|
68
68
|
import { to } from "./to";
|
|
69
69
|
import type { I18n } from "./types";
|
|
@@ -174,7 +174,7 @@ export const pathnameToRouteId = (pathname: string) =>
|
|
|
174
174
|
export default pathnameToRouteId;
|
|
175
175
|
`);
|
|
176
176
|
|
|
177
|
-
var r$
|
|
177
|
+
var r$4 = (({ routes: t })=>{
|
|
178
178
|
let e = JSON.stringify(Object.fromEntries(Object.entries(t).map(([t, { pathnames: e }])=>[
|
|
179
179
|
t,
|
|
180
180
|
e
|
|
@@ -289,7 +289,7 @@ export function to<TRoute extends I18n.RouteId>(
|
|
|
289
289
|
export default to;
|
|
290
290
|
`);
|
|
291
291
|
|
|
292
|
-
let r$
|
|
292
|
+
let r$3 = (t, e)=>{
|
|
293
293
|
let { defaultLocale: r } = t, l = "";
|
|
294
294
|
return forin(e, (t, o)=>{
|
|
295
295
|
t !== r && o !== e[r] && (l += `locale === "${t}" ? "${o}" : `);
|
|
@@ -306,7 +306,7 @@ import type { I18n } from "./types";
|
|
|
306
306
|
n ? `params: ${i}` : "",
|
|
307
307
|
m ? "" : "locale?: I18n.Locale"
|
|
308
308
|
].filter(Boolean).join(", "), c = m ? '""' : "locale", f = n ? ", params" : "";
|
|
309
|
-
$ += `export let ${p} = (${s}) => `, isString(a) ? $ += `toFormat(${c}, "${a}"${f});` : $ += `toFormat(${c}, ${r$
|
|
309
|
+
$ += `export let ${p} = (${s}) => `, isString(a) ? $ += `toFormat(${c}, "${a}"${f});` : $ += `toFormat(${c}, ${r$3(l, a)}${f});`, $ += `\n`;
|
|
310
310
|
}), $;
|
|
311
311
|
});
|
|
312
312
|
|
|
@@ -447,7 +447,7 @@ let c$1 = (e, a)=>{
|
|
|
447
447
|
t && a.push(`"${e}": { ${dataParamsToTsInterfaceBody(t)} };`);
|
|
448
448
|
}), a;
|
|
449
449
|
}, d$1 = (e, t)=>Object.keys(e).filter((a)=>t(a, e[a])).sort().map((e)=>`"${e}"`).join(" | ");
|
|
450
|
-
var l$
|
|
450
|
+
var l$2 = (({ config: e, input: t, routes: a })=>{
|
|
451
451
|
let n = d$1(a, (e, { params: t })=>!t), s = d$1(a, (e, { params: t })=>!!t);
|
|
452
452
|
return `
|
|
453
453
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
@@ -695,11 +695,11 @@ export namespace I18n {
|
|
|
695
695
|
`;
|
|
696
696
|
});
|
|
697
697
|
|
|
698
|
-
var e$
|
|
698
|
+
var e$3 = (()=>({
|
|
699
699
|
files: [
|
|
700
700
|
{
|
|
701
701
|
name: "config",
|
|
702
|
-
fn: e$
|
|
702
|
+
fn: e$4,
|
|
703
703
|
ext: "ts",
|
|
704
704
|
index: !0
|
|
705
705
|
},
|
|
@@ -711,7 +711,7 @@ var e$2 = (()=>({
|
|
|
711
711
|
},
|
|
712
712
|
{
|
|
713
713
|
name: "deriveLocalisedPathnames",
|
|
714
|
-
fn: o$
|
|
714
|
+
fn: o$4,
|
|
715
715
|
ext: "ts",
|
|
716
716
|
index: !0
|
|
717
717
|
},
|
|
@@ -735,7 +735,7 @@ var e$2 = (()=>({
|
|
|
735
735
|
},
|
|
736
736
|
{
|
|
737
737
|
name: "routes",
|
|
738
|
-
fn: r$
|
|
738
|
+
fn: r$4,
|
|
739
739
|
ext: "ts",
|
|
740
740
|
index: !0
|
|
741
741
|
},
|
|
@@ -776,14 +776,14 @@ var e$2 = (()=>({
|
|
|
776
776
|
},
|
|
777
777
|
{
|
|
778
778
|
name: "types",
|
|
779
|
-
fn: l$
|
|
779
|
+
fn: l$2,
|
|
780
780
|
ext: "ts",
|
|
781
781
|
index: !0
|
|
782
782
|
}
|
|
783
783
|
]
|
|
784
784
|
}));
|
|
785
785
|
|
|
786
|
-
var e$
|
|
786
|
+
var e$2 = (()=>`
|
|
787
787
|
"use client";
|
|
788
788
|
|
|
789
789
|
import _DynamicNamespaces from "next-translate/DynamicNamespaces";
|
|
@@ -923,7 +923,7 @@ var t$1 = (()=>({
|
|
|
923
923
|
files: [
|
|
924
924
|
{
|
|
925
925
|
name: "DynamicNamespaces",
|
|
926
|
-
fn: e$
|
|
926
|
+
fn: e$2,
|
|
927
927
|
ext: "tsx",
|
|
928
928
|
index: !0
|
|
929
929
|
},
|
|
@@ -959,7 +959,131 @@ var t$1 = (()=>({
|
|
|
959
959
|
]
|
|
960
960
|
}));
|
|
961
961
|
|
|
962
|
-
|
|
962
|
+
function transformPathname(n, e) {
|
|
963
|
+
return "/" + e.split("/").filter(Boolean).map((n)=>n.startsWith("[") ? `:${encodeURIComponent(n.slice(1, -1))}` : `${encodeURIComponent(n)}`).join("/") + (n.wildcard ? "/:wildcard*" : "");
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function l$1(e) {
|
|
967
|
+
let { localeSource: o, localeDestination: l, template: n, pathname: r, permanent: a } = e, i = formatRoutePathname((o ? `${o}/` : "") + n), c = formatRoutePathname((l ? `${l}/` : "") + r);
|
|
968
|
+
if (i !== c) return {
|
|
969
|
+
source: i,
|
|
970
|
+
destination: c,
|
|
971
|
+
permanent: !!a
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
let generateRedirects = (t, n, r = "", a = !1)=>{
|
|
975
|
+
let { defaultLocale: i, hideDefaultLocaleInUrl: c } = t, s = [];
|
|
976
|
+
for(let e in n){
|
|
977
|
+
let t = n[e], p = n[e].pathnames;
|
|
978
|
+
for(let n in p){
|
|
979
|
+
let u = p[n], m = transformPathname(t, e.replace(/\./g, "/")), f = transformPathname(t, u);
|
|
980
|
+
if (t.inWildcard) break;
|
|
981
|
+
let h = n === i && !c, d = n === i && c;
|
|
982
|
+
r ? h ? s.push(l$1({
|
|
983
|
+
localeDestination: n,
|
|
984
|
+
permanent: a,
|
|
985
|
+
template: m,
|
|
986
|
+
pathname: f
|
|
987
|
+
})) : d ? s.push(l$1({
|
|
988
|
+
localeSource: n,
|
|
989
|
+
permanent: a,
|
|
990
|
+
template: m,
|
|
991
|
+
pathname: f
|
|
992
|
+
})) : n !== i ? s.push(l$1({
|
|
993
|
+
localeSource: n,
|
|
994
|
+
localeDestination: n,
|
|
995
|
+
permanent: a,
|
|
996
|
+
template: m,
|
|
997
|
+
pathname: f
|
|
998
|
+
})) : s.push(l$1({
|
|
999
|
+
permanent: a,
|
|
1000
|
+
template: m,
|
|
1001
|
+
pathname: f
|
|
1002
|
+
})) : f !== m && (h ? s.push(l$1({
|
|
1003
|
+
localeDestination: n,
|
|
1004
|
+
permanent: a,
|
|
1005
|
+
template: m,
|
|
1006
|
+
pathname: f
|
|
1007
|
+
})) : n !== i ? s.push(l$1({
|
|
1008
|
+
localeSource: n,
|
|
1009
|
+
localeDestination: n,
|
|
1010
|
+
permanent: a,
|
|
1011
|
+
template: m,
|
|
1012
|
+
pathname: f
|
|
1013
|
+
})) : s.push(l$1({
|
|
1014
|
+
permanent: a,
|
|
1015
|
+
template: m,
|
|
1016
|
+
pathname: f
|
|
1017
|
+
})));
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return arrayUniqueByProperties(s.filter(Boolean), [
|
|
1021
|
+
"source",
|
|
1022
|
+
"destination"
|
|
1023
|
+
]).map((e)=>r ? e : {
|
|
1024
|
+
...e,
|
|
1025
|
+
locale: !1
|
|
1026
|
+
});
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
var e$1 = (({ config: e, routes: t })=>{
|
|
1030
|
+
let l = JSON.stringify(generateRedirects(e, t), null, 2);
|
|
1031
|
+
return `module.exports = ${l}`;
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
function r$2(e) {
|
|
1035
|
+
let { localeSource: o, localeDestination: r, localeParam: l, template: i, pathname: n } = e, a = "";
|
|
1036
|
+
o ? a = `/${o}` : l && (a = `/:${l}`);
|
|
1037
|
+
let s = formatRoutePathname(a + n), c = "";
|
|
1038
|
+
r ? c = `/${r}` : l && (c = `/:${l}`);
|
|
1039
|
+
let u = formatRoutePathname(c + i);
|
|
1040
|
+
if (s !== u) return {
|
|
1041
|
+
source: s,
|
|
1042
|
+
destination: u
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
let generateRewrites = (t, l, i = "")=>{
|
|
1046
|
+
let { defaultLocale: n, hideDefaultLocaleInUrl: a } = t, s = [];
|
|
1047
|
+
for(let e in l){
|
|
1048
|
+
let t = l[e], c = l[e].pathnames;
|
|
1049
|
+
for(let l in c){
|
|
1050
|
+
let u = c[l], f = l === n && !a, p = l === n && a, m = transformPathname(t, e.replace(/\./g, "/")), h = transformPathname(t, u);
|
|
1051
|
+
if (t.inWildcard) break;
|
|
1052
|
+
i ? p ? s.push(r$2({
|
|
1053
|
+
localeDestination: l,
|
|
1054
|
+
route: t,
|
|
1055
|
+
template: m,
|
|
1056
|
+
pathname: h
|
|
1057
|
+
})) : s.push(r$2({
|
|
1058
|
+
localeDestination: l,
|
|
1059
|
+
localeSource: l,
|
|
1060
|
+
route: t,
|
|
1061
|
+
template: m,
|
|
1062
|
+
pathname: h
|
|
1063
|
+
})) : h !== m && (l !== n || f ? s.push(r$2({
|
|
1064
|
+
localeSource: l,
|
|
1065
|
+
route: t,
|
|
1066
|
+
template: m,
|
|
1067
|
+
pathname: h
|
|
1068
|
+
})) : s.push(r$2({
|
|
1069
|
+
route: t,
|
|
1070
|
+
template: m,
|
|
1071
|
+
pathname: h
|
|
1072
|
+
})));
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return arrayUniqueByProperties(s.filter(Boolean), [
|
|
1076
|
+
"source",
|
|
1077
|
+
"destination"
|
|
1078
|
+
]);
|
|
1079
|
+
};
|
|
1080
|
+
|
|
1081
|
+
var t = (({ config: e, routes: t })=>{
|
|
1082
|
+
let l = JSON.stringify(generateRewrites(e, t), null, 2);
|
|
1083
|
+
return `module.exports = ${l}`;
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
var n$2 = (()=>`
|
|
963
1087
|
"use client";
|
|
964
1088
|
|
|
965
1089
|
import { useEffect, useState } from "react";
|
|
@@ -980,7 +1104,7 @@ export function useCurrentLocalisedPathnames() {
|
|
|
980
1104
|
export default useCurrentLocalisedPathnames;
|
|
981
1105
|
`);
|
|
982
1106
|
|
|
983
|
-
var
|
|
1107
|
+
var r$1 = (({ config: e })=>`
|
|
984
1108
|
import { useRouter } from "next/router";
|
|
985
1109
|
import type { I18n } from "./types";
|
|
986
1110
|
|
|
@@ -1000,7 +1124,7 @@ export const useRouteId = () =>
|
|
|
1000
1124
|
export default useRouteId;
|
|
1001
1125
|
`);
|
|
1002
1126
|
|
|
1003
|
-
var
|
|
1127
|
+
var o$3 = (()=>`
|
|
1004
1128
|
"use client";
|
|
1005
1129
|
|
|
1006
1130
|
import { to } from "./to";
|
|
@@ -1033,15 +1157,25 @@ var n$1 = (()=>({
|
|
|
1033
1157
|
"js"
|
|
1034
1158
|
],
|
|
1035
1159
|
files: [
|
|
1160
|
+
{
|
|
1161
|
+
name: "next-redirects",
|
|
1162
|
+
fn: e$1,
|
|
1163
|
+
ext: "js"
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
name: "next-rewrites",
|
|
1167
|
+
fn: t,
|
|
1168
|
+
ext: "js"
|
|
1169
|
+
},
|
|
1036
1170
|
{
|
|
1037
1171
|
name: "useCurrentLocalisedPathnames",
|
|
1038
|
-
fn:
|
|
1172
|
+
fn: n$2,
|
|
1039
1173
|
ext: "ts",
|
|
1040
1174
|
index: !0
|
|
1041
1175
|
},
|
|
1042
1176
|
{
|
|
1043
1177
|
name: "useLocale",
|
|
1044
|
-
fn:
|
|
1178
|
+
fn: r$1,
|
|
1045
1179
|
ext: "ts",
|
|
1046
1180
|
index: !0
|
|
1047
1181
|
},
|
|
@@ -1053,7 +1187,7 @@ var n$1 = (()=>({
|
|
|
1053
1187
|
},
|
|
1054
1188
|
{
|
|
1055
1189
|
name: "useTo",
|
|
1056
|
-
fn:
|
|
1190
|
+
fn: o$3,
|
|
1057
1191
|
ext: "ts",
|
|
1058
1192
|
index: !0
|
|
1059
1193
|
}
|
|
@@ -1061,7 +1195,7 @@ var n$1 = (()=>({
|
|
|
1061
1195
|
}));
|
|
1062
1196
|
|
|
1063
1197
|
let a = {
|
|
1064
|
-
js: e$
|
|
1198
|
+
js: e$3,
|
|
1065
1199
|
next: n$1,
|
|
1066
1200
|
"next-translate": t$1
|
|
1067
1201
|
}, r = (e)=>{
|
|
@@ -1258,18 +1392,21 @@ const codeDataTranslationsOptions = {
|
|
|
1258
1392
|
fnsPrefix: "",
|
|
1259
1393
|
createArrayIndexBasedFns: !1
|
|
1260
1394
|
};
|
|
1261
|
-
|
|
1395
|
+
let e = {
|
|
1262
1396
|
routes: codeDataRoutesOptions,
|
|
1263
1397
|
translations: codeDataTranslationsOptions
|
|
1264
1398
|
};
|
|
1265
|
-
let getCodeData = (s,
|
|
1266
|
-
let
|
|
1267
|
-
return
|
|
1399
|
+
let getCodeData = (s, n, r)=>{
|
|
1400
|
+
let i = objectMergeWithDefaults(e, n);
|
|
1401
|
+
return i.translations.ignorePaths.push(i.routes.translationJsonFileName), r = {
|
|
1402
|
+
...r,
|
|
1403
|
+
localesFolders: r.localesFolders.sort((t, o)=>s.defaultLocale ? -1 : t.localeCompare(o))
|
|
1404
|
+
}, {
|
|
1268
1405
|
config: s,
|
|
1269
|
-
options:
|
|
1270
|
-
input:
|
|
1271
|
-
routes: getCodeDataRoutes(s,
|
|
1272
|
-
translations: getCodeDataTranslations(s,
|
|
1406
|
+
options: i,
|
|
1407
|
+
input: r,
|
|
1408
|
+
routes: getCodeDataRoutes(s, i.routes, r),
|
|
1409
|
+
translations: getCodeDataTranslations(s, i.translations, r)
|
|
1273
1410
|
};
|
|
1274
1411
|
};
|
|
1275
1412
|
|
|
@@ -1292,4 +1429,4 @@ let i18nCompiler = async (p)=>{
|
|
|
1292
1429
|
};
|
|
1293
1430
|
};
|
|
1294
1431
|
|
|
1295
|
-
export { i18nCompiler as i };
|
|
1432
|
+
export { generateRewrites as a, generateRedirects as g, i18nCompiler as i };
|
package/compiler/code/data.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const codeDataTranslationsOptions: {
|
|
|
20
20
|
createArrayIndexBasedFns: boolean;
|
|
21
21
|
};
|
|
22
22
|
export type CodeDataTranslationsOptions = typeof codeDataTranslationsOptions;
|
|
23
|
-
|
|
23
|
+
declare const codeDataOptions: {
|
|
24
24
|
routes: {
|
|
25
25
|
translationJsonFileName: string;
|
|
26
26
|
tokens: {
|
|
@@ -42,3 +42,4 @@ export declare const codeDataOptions: {
|
|
|
42
42
|
};
|
|
43
43
|
export type CodeDataOptions = typeof codeDataOptions;
|
|
44
44
|
export declare let getCodeData: (config: I18nCompiler.Config, options: PartialDeep<CodeDataOptions>, input: I18nCompiler.DataInput) => I18nCompiler.DataCode;
|
|
45
|
+
export {};
|
package/compiler/code/index.d.ts
CHANGED
package/compiler.cjs.js
CHANGED
|
@@ -7,8 +7,8 @@ require('node:fs');
|
|
|
7
7
|
require('node:path');
|
|
8
8
|
require('@koine/node');
|
|
9
9
|
require('@koine/utils');
|
|
10
|
-
require('typescript');
|
|
11
10
|
require('./formatRoutePathname.cjs.js');
|
|
11
|
+
require('typescript');
|
|
12
12
|
require('minimatch');
|
|
13
13
|
require('./write.cjs.js');
|
|
14
14
|
require('node:fs/promises');
|
package/next.cjs.js
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
var webpack = require('webpack');
|
|
7
|
-
var formatRoutePathname = require('./formatRoutePathname.cjs.js');
|
|
8
7
|
var api = require('./api.cjs.js');
|
|
9
8
|
require('node:fs');
|
|
10
9
|
require('node:path');
|
|
11
10
|
require('@koine/node');
|
|
11
|
+
require('./formatRoutePathname.cjs.js');
|
|
12
12
|
require('typescript');
|
|
13
13
|
require('minimatch');
|
|
14
14
|
require('./write.cjs.js');
|
|
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
|
|
|
35
35
|
return Object.freeze(n);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function l
|
|
38
|
+
function l(e, t) {
|
|
39
39
|
let { [t]: l, ...n } = e;
|
|
40
40
|
return {
|
|
41
41
|
[t]: l,
|
|
@@ -76,7 +76,7 @@ function i(e = {}, t, l = "", n = "") {
|
|
|
76
76
|
function a(e) {
|
|
77
77
|
return e.replace(/\/index$/, "");
|
|
78
78
|
}
|
|
79
|
-
function r
|
|
79
|
+
function r(e) {
|
|
80
80
|
let { localeSource: l, localeDestination: i, route: r, usePathnameAsSource: o, permanent: s } = e, { template: c, pathname: u } = n(r), f = l ? `${l}/` : "", p = a(`/${utils.normaliseUrlPathname(f + (o ? u : c))}`), h = i ? `${i}/` : "", m = `/${utils.normaliseUrlPathname(h + u)}`;
|
|
81
81
|
if (p !== m) return {
|
|
82
82
|
source: p,
|
|
@@ -112,39 +112,39 @@ let withI18nLegacy = (t)=>{
|
|
|
112
112
|
let { redirects: t, rewrites: c } = h;
|
|
113
113
|
h.redirects = async ()=>{
|
|
114
114
|
let o = function(t) {
|
|
115
|
-
let { routes: n, defaultLocale: o, hideDefaultLocaleInUrl: s, localeParam: c, permanent: u, debug: f } = t, p = l
|
|
115
|
+
let { routes: n, defaultLocale: o, hideDefaultLocaleInUrl: s, localeParam: c, permanent: u, debug: f } = t, p = l(n, o), h = [];
|
|
116
116
|
for(let e in p){
|
|
117
117
|
let t = i({}, n[e]);
|
|
118
118
|
for(let l in t){
|
|
119
119
|
let n = t[l];
|
|
120
120
|
if (n.pathname !== a(l)) {
|
|
121
121
|
let t = e === o && !s, l = e === o && s;
|
|
122
|
-
c ? t ? h.push(r
|
|
122
|
+
c ? t ? h.push(r({
|
|
123
123
|
localeDestination: e,
|
|
124
124
|
route: n,
|
|
125
125
|
permanent: u
|
|
126
|
-
})) : l ? h.push(r
|
|
126
|
+
})) : l ? h.push(r({
|
|
127
127
|
localeSource: e,
|
|
128
128
|
route: n,
|
|
129
129
|
permanent: u
|
|
130
|
-
})) : e !== o ? h.push(r
|
|
130
|
+
})) : e !== o ? h.push(r({
|
|
131
131
|
localeSource: e,
|
|
132
132
|
localeDestination: e,
|
|
133
133
|
route: n,
|
|
134
134
|
permanent: u
|
|
135
|
-
})) : h.push(r
|
|
135
|
+
})) : h.push(r({
|
|
136
136
|
route: n,
|
|
137
137
|
permanent: u
|
|
138
|
-
})) : t ? h.push(r
|
|
138
|
+
})) : t ? h.push(r({
|
|
139
139
|
localeDestination: e,
|
|
140
140
|
route: n,
|
|
141
141
|
permanent: u
|
|
142
|
-
})) : e !== o ? h.push(r
|
|
142
|
+
})) : e !== o ? h.push(r({
|
|
143
143
|
localeSource: e,
|
|
144
144
|
localeDestination: e,
|
|
145
145
|
route: n,
|
|
146
146
|
permanent: u
|
|
147
|
-
})) : h.push(r
|
|
147
|
+
})) : h.push(r({
|
|
148
148
|
route: n,
|
|
149
149
|
permanent: u
|
|
150
150
|
}));
|
|
@@ -171,7 +171,7 @@ let withI18nLegacy = (t)=>{
|
|
|
171
171
|
] : o;
|
|
172
172
|
}, h.rewrites = async ()=>{
|
|
173
173
|
let t = function(t) {
|
|
174
|
-
let { routes: n, defaultLocale: r, hideDefaultLocaleInUrl: s, localeParam: c, debug: u } = t, f = l
|
|
174
|
+
let { routes: n, defaultLocale: r, hideDefaultLocaleInUrl: s, localeParam: c, debug: u } = t, f = l(n, r), p = [];
|
|
175
175
|
for(let e in f){
|
|
176
176
|
let t = i({}, n[e]);
|
|
177
177
|
for(let l in t){
|
|
@@ -224,120 +224,6 @@ let withI18nLegacy = (t)=>{
|
|
|
224
224
|
return h;
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
-
function transformPathname(n, e) {
|
|
228
|
-
return "/" + e.split("/").filter(Boolean).map((n)=>n.startsWith("[") ? `:${encodeURIComponent(n.slice(1, -1))}` : `${encodeURIComponent(n)}`).join("/") + (n.wildcard ? "/:wildcard*" : "");
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function l(e) {
|
|
232
|
-
let { localeSource: o, localeDestination: l, template: n, pathname: r, permanent: a } = e, i = formatRoutePathname.formatRoutePathname((o ? `${o}/` : "") + n), c = formatRoutePathname.formatRoutePathname((l ? `${l}/` : "") + r);
|
|
233
|
-
if (i !== c) return {
|
|
234
|
-
source: i,
|
|
235
|
-
destination: c,
|
|
236
|
-
permanent: !!a
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
let generateRedirects = (t, n, r = "", a = !1)=>{
|
|
240
|
-
let { defaultLocale: i, hideDefaultLocaleInUrl: c } = t, s = [];
|
|
241
|
-
for(let e in n){
|
|
242
|
-
let t = n[e], p = n[e].pathnames;
|
|
243
|
-
for(let n in p){
|
|
244
|
-
let u = p[n], m = transformPathname(t, e.replace(/\./g, "/")), f = transformPathname(t, u);
|
|
245
|
-
if (t.inWildcard) break;
|
|
246
|
-
let h = n === i && !c, d = n === i && c;
|
|
247
|
-
r ? h ? s.push(l({
|
|
248
|
-
localeDestination: n,
|
|
249
|
-
permanent: a,
|
|
250
|
-
template: m,
|
|
251
|
-
pathname: f
|
|
252
|
-
})) : d ? s.push(l({
|
|
253
|
-
localeSource: n,
|
|
254
|
-
permanent: a,
|
|
255
|
-
template: m,
|
|
256
|
-
pathname: f
|
|
257
|
-
})) : n !== i ? s.push(l({
|
|
258
|
-
localeSource: n,
|
|
259
|
-
localeDestination: n,
|
|
260
|
-
permanent: a,
|
|
261
|
-
template: m,
|
|
262
|
-
pathname: f
|
|
263
|
-
})) : s.push(l({
|
|
264
|
-
permanent: a,
|
|
265
|
-
template: m,
|
|
266
|
-
pathname: f
|
|
267
|
-
})) : f !== m && (h ? s.push(l({
|
|
268
|
-
localeDestination: n,
|
|
269
|
-
permanent: a,
|
|
270
|
-
template: m,
|
|
271
|
-
pathname: f
|
|
272
|
-
})) : n !== i ? s.push(l({
|
|
273
|
-
localeSource: n,
|
|
274
|
-
localeDestination: n,
|
|
275
|
-
permanent: a,
|
|
276
|
-
template: m,
|
|
277
|
-
pathname: f
|
|
278
|
-
})) : s.push(l({
|
|
279
|
-
permanent: a,
|
|
280
|
-
template: m,
|
|
281
|
-
pathname: f
|
|
282
|
-
})));
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return utils.arrayUniqueByProperties(s.filter(Boolean), [
|
|
286
|
-
"source",
|
|
287
|
-
"destination"
|
|
288
|
-
]).map((e)=>r ? e : {
|
|
289
|
-
...e,
|
|
290
|
-
locale: !1
|
|
291
|
-
});
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
function r(e) {
|
|
295
|
-
let { localeSource: o, localeDestination: r, localeParam: l, template: i, pathname: n } = e, a = "";
|
|
296
|
-
o ? a = `/${o}` : l && (a = `/:${l}`);
|
|
297
|
-
let s = formatRoutePathname.formatRoutePathname(a + n), c = "";
|
|
298
|
-
r ? c = `/${r}` : l && (c = `/:${l}`);
|
|
299
|
-
let u = formatRoutePathname.formatRoutePathname(c + i);
|
|
300
|
-
if (s !== u) return {
|
|
301
|
-
source: s,
|
|
302
|
-
destination: u
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
let generateRewrites = (t, l, i = "")=>{
|
|
306
|
-
let { defaultLocale: n, hideDefaultLocaleInUrl: a } = t, s = [];
|
|
307
|
-
for(let e in l){
|
|
308
|
-
let t = l[e], c = l[e].pathnames;
|
|
309
|
-
for(let l in c){
|
|
310
|
-
let u = c[l], f = l === n && !a, p = l === n && a, m = transformPathname(t, e.replace(/\./g, "/")), h = transformPathname(t, u);
|
|
311
|
-
if (t.inWildcard) break;
|
|
312
|
-
i ? p ? s.push(r({
|
|
313
|
-
localeDestination: l,
|
|
314
|
-
route: t,
|
|
315
|
-
template: m,
|
|
316
|
-
pathname: h
|
|
317
|
-
})) : s.push(r({
|
|
318
|
-
localeDestination: l,
|
|
319
|
-
localeSource: l,
|
|
320
|
-
route: t,
|
|
321
|
-
template: m,
|
|
322
|
-
pathname: h
|
|
323
|
-
})) : h !== m && (l !== n || f ? s.push(r({
|
|
324
|
-
localeSource: l,
|
|
325
|
-
route: t,
|
|
326
|
-
template: m,
|
|
327
|
-
pathname: h
|
|
328
|
-
})) : s.push(r({
|
|
329
|
-
route: t,
|
|
330
|
-
template: m,
|
|
331
|
-
pathname: h
|
|
332
|
-
})));
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return utils.arrayUniqueByProperties(s.filter(Boolean), [
|
|
336
|
-
"source",
|
|
337
|
-
"destination"
|
|
338
|
-
]);
|
|
339
|
-
};
|
|
340
|
-
|
|
341
227
|
let tweakNextConfig = (r, t)=>{
|
|
342
228
|
let { defaultLocale: i, locales: l, appRouterLocaleParamName: o } = r;
|
|
343
229
|
return o ? delete t.i18n : (t.i18n = t.i18n || {
|
|
@@ -346,14 +232,14 @@ let tweakNextConfig = (r, t)=>{
|
|
|
346
232
|
}, t.i18n.locales = l, t.i18n.defaultLocale = i), t.webpack = (r)=>(r.plugins.push(new webpack.ContextReplacementPlugin(/^date-fns[/\\]locale$/, RegExp(`\\.[/\\\\](${l.join("|")})[/\\\\]index\\.js$`))), r), t;
|
|
347
233
|
};
|
|
348
234
|
let getRedirects = async (e, { appRouterLocaleParamName: t, permanentRedirects: i }, l)=>{
|
|
349
|
-
let o = generateRedirects(l.config, l.code.routes, t, i);
|
|
235
|
+
let o = api.generateRedirects(l.config, l.code.routes, t, i);
|
|
350
236
|
return e ? [
|
|
351
237
|
...o,
|
|
352
238
|
...await e()
|
|
353
239
|
] : o;
|
|
354
240
|
};
|
|
355
241
|
let getRewrites = async (e, { appRouterLocaleParamName: r }, i)=>{
|
|
356
|
-
let l = generateRewrites(i.config, i.code.routes, r);
|
|
242
|
+
let l = api.generateRewrites(i.config, i.code.routes, r);
|
|
357
243
|
if (e) {
|
|
358
244
|
let r = await e();
|
|
359
245
|
return Array.isArray(r) ? {
|
package/next.esm.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { arrayUniqueByProperties, normaliseUrlPathname } from '@koine/utils';
|
|
2
2
|
import { ContextReplacementPlugin } from 'webpack';
|
|
3
|
-
import {
|
|
4
|
-
import { i as i18nCompiler } from './api.esm.js';
|
|
3
|
+
import { g as generateRedirects, a as generateRewrites, i as i18nCompiler } from './api.esm.js';
|
|
5
4
|
import './write.esm.js';
|
|
6
5
|
import 'node:path';
|
|
7
6
|
import '@koine/node';
|
|
@@ -10,10 +9,11 @@ import 'glob';
|
|
|
10
9
|
import 'next/dist/shared/lib/utils';
|
|
11
10
|
import 'node:https';
|
|
12
11
|
import 'minimatch';
|
|
12
|
+
import './formatRoutePathname.esm.js';
|
|
13
13
|
import 'node:fs';
|
|
14
14
|
import 'typescript';
|
|
15
15
|
|
|
16
|
-
function l
|
|
16
|
+
function l(e, t) {
|
|
17
17
|
let { [t]: l, ...n } = e;
|
|
18
18
|
return {
|
|
19
19
|
[t]: l,
|
|
@@ -54,7 +54,7 @@ function i(e = {}, t, l = "", n = "") {
|
|
|
54
54
|
function a(e) {
|
|
55
55
|
return e.replace(/\/index$/, "");
|
|
56
56
|
}
|
|
57
|
-
function r
|
|
57
|
+
function r(e) {
|
|
58
58
|
let { localeSource: l, localeDestination: i, route: r, usePathnameAsSource: o, permanent: s } = e, { template: c, pathname: u } = n(r), f = l ? `${l}/` : "", p = a(`/${normaliseUrlPathname(f + (o ? u : c))}`), h = i ? `${i}/` : "", m = `/${normaliseUrlPathname(h + u)}`;
|
|
59
59
|
if (p !== m) return {
|
|
60
60
|
source: p,
|
|
@@ -90,39 +90,39 @@ let withI18nLegacy = (t)=>{
|
|
|
90
90
|
let { redirects: t, rewrites: c } = h;
|
|
91
91
|
h.redirects = async ()=>{
|
|
92
92
|
let o = function(t) {
|
|
93
|
-
let { routes: n, defaultLocale: o, hideDefaultLocaleInUrl: s, localeParam: c, permanent: u, debug: f } = t, p = l
|
|
93
|
+
let { routes: n, defaultLocale: o, hideDefaultLocaleInUrl: s, localeParam: c, permanent: u, debug: f } = t, p = l(n, o), h = [];
|
|
94
94
|
for(let e in p){
|
|
95
95
|
let t = i({}, n[e]);
|
|
96
96
|
for(let l in t){
|
|
97
97
|
let n = t[l];
|
|
98
98
|
if (n.pathname !== a(l)) {
|
|
99
99
|
let t = e === o && !s, l = e === o && s;
|
|
100
|
-
c ? t ? h.push(r
|
|
100
|
+
c ? t ? h.push(r({
|
|
101
101
|
localeDestination: e,
|
|
102
102
|
route: n,
|
|
103
103
|
permanent: u
|
|
104
|
-
})) : l ? h.push(r
|
|
104
|
+
})) : l ? h.push(r({
|
|
105
105
|
localeSource: e,
|
|
106
106
|
route: n,
|
|
107
107
|
permanent: u
|
|
108
|
-
})) : e !== o ? h.push(r
|
|
108
|
+
})) : e !== o ? h.push(r({
|
|
109
109
|
localeSource: e,
|
|
110
110
|
localeDestination: e,
|
|
111
111
|
route: n,
|
|
112
112
|
permanent: u
|
|
113
|
-
})) : h.push(r
|
|
113
|
+
})) : h.push(r({
|
|
114
114
|
route: n,
|
|
115
115
|
permanent: u
|
|
116
|
-
})) : t ? h.push(r
|
|
116
|
+
})) : t ? h.push(r({
|
|
117
117
|
localeDestination: e,
|
|
118
118
|
route: n,
|
|
119
119
|
permanent: u
|
|
120
|
-
})) : e !== o ? h.push(r
|
|
120
|
+
})) : e !== o ? h.push(r({
|
|
121
121
|
localeSource: e,
|
|
122
122
|
localeDestination: e,
|
|
123
123
|
route: n,
|
|
124
124
|
permanent: u
|
|
125
|
-
})) : h.push(r
|
|
125
|
+
})) : h.push(r({
|
|
126
126
|
route: n,
|
|
127
127
|
permanent: u
|
|
128
128
|
}));
|
|
@@ -149,7 +149,7 @@ let withI18nLegacy = (t)=>{
|
|
|
149
149
|
] : o;
|
|
150
150
|
}, h.rewrites = async ()=>{
|
|
151
151
|
let t = function(t) {
|
|
152
|
-
let { routes: n, defaultLocale: r, hideDefaultLocaleInUrl: s, localeParam: c, debug: u } = t, f = l
|
|
152
|
+
let { routes: n, defaultLocale: r, hideDefaultLocaleInUrl: s, localeParam: c, debug: u } = t, f = l(n, r), p = [];
|
|
153
153
|
for(let e in f){
|
|
154
154
|
let t = i({}, n[e]);
|
|
155
155
|
for(let l in t){
|
|
@@ -202,120 +202,6 @@ let withI18nLegacy = (t)=>{
|
|
|
202
202
|
return h;
|
|
203
203
|
};
|
|
204
204
|
|
|
205
|
-
function transformPathname(n, e) {
|
|
206
|
-
return "/" + e.split("/").filter(Boolean).map((n)=>n.startsWith("[") ? `:${encodeURIComponent(n.slice(1, -1))}` : `${encodeURIComponent(n)}`).join("/") + (n.wildcard ? "/:wildcard*" : "");
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function l(e) {
|
|
210
|
-
let { localeSource: o, localeDestination: l, template: n, pathname: r, permanent: a } = e, i = formatRoutePathname((o ? `${o}/` : "") + n), c = formatRoutePathname((l ? `${l}/` : "") + r);
|
|
211
|
-
if (i !== c) return {
|
|
212
|
-
source: i,
|
|
213
|
-
destination: c,
|
|
214
|
-
permanent: !!a
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
let generateRedirects = (t, n, r = "", a = !1)=>{
|
|
218
|
-
let { defaultLocale: i, hideDefaultLocaleInUrl: c } = t, s = [];
|
|
219
|
-
for(let e in n){
|
|
220
|
-
let t = n[e], p = n[e].pathnames;
|
|
221
|
-
for(let n in p){
|
|
222
|
-
let u = p[n], m = transformPathname(t, e.replace(/\./g, "/")), f = transformPathname(t, u);
|
|
223
|
-
if (t.inWildcard) break;
|
|
224
|
-
let h = n === i && !c, d = n === i && c;
|
|
225
|
-
r ? h ? s.push(l({
|
|
226
|
-
localeDestination: n,
|
|
227
|
-
permanent: a,
|
|
228
|
-
template: m,
|
|
229
|
-
pathname: f
|
|
230
|
-
})) : d ? s.push(l({
|
|
231
|
-
localeSource: n,
|
|
232
|
-
permanent: a,
|
|
233
|
-
template: m,
|
|
234
|
-
pathname: f
|
|
235
|
-
})) : n !== i ? s.push(l({
|
|
236
|
-
localeSource: n,
|
|
237
|
-
localeDestination: n,
|
|
238
|
-
permanent: a,
|
|
239
|
-
template: m,
|
|
240
|
-
pathname: f
|
|
241
|
-
})) : s.push(l({
|
|
242
|
-
permanent: a,
|
|
243
|
-
template: m,
|
|
244
|
-
pathname: f
|
|
245
|
-
})) : f !== m && (h ? s.push(l({
|
|
246
|
-
localeDestination: n,
|
|
247
|
-
permanent: a,
|
|
248
|
-
template: m,
|
|
249
|
-
pathname: f
|
|
250
|
-
})) : n !== i ? s.push(l({
|
|
251
|
-
localeSource: n,
|
|
252
|
-
localeDestination: n,
|
|
253
|
-
permanent: a,
|
|
254
|
-
template: m,
|
|
255
|
-
pathname: f
|
|
256
|
-
})) : s.push(l({
|
|
257
|
-
permanent: a,
|
|
258
|
-
template: m,
|
|
259
|
-
pathname: f
|
|
260
|
-
})));
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return arrayUniqueByProperties(s.filter(Boolean), [
|
|
264
|
-
"source",
|
|
265
|
-
"destination"
|
|
266
|
-
]).map((e)=>r ? e : {
|
|
267
|
-
...e,
|
|
268
|
-
locale: !1
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
function r(e) {
|
|
273
|
-
let { localeSource: o, localeDestination: r, localeParam: l, template: i, pathname: n } = e, a = "";
|
|
274
|
-
o ? a = `/${o}` : l && (a = `/:${l}`);
|
|
275
|
-
let s = formatRoutePathname(a + n), c = "";
|
|
276
|
-
r ? c = `/${r}` : l && (c = `/:${l}`);
|
|
277
|
-
let u = formatRoutePathname(c + i);
|
|
278
|
-
if (s !== u) return {
|
|
279
|
-
source: s,
|
|
280
|
-
destination: u
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
let generateRewrites = (t, l, i = "")=>{
|
|
284
|
-
let { defaultLocale: n, hideDefaultLocaleInUrl: a } = t, s = [];
|
|
285
|
-
for(let e in l){
|
|
286
|
-
let t = l[e], c = l[e].pathnames;
|
|
287
|
-
for(let l in c){
|
|
288
|
-
let u = c[l], f = l === n && !a, p = l === n && a, m = transformPathname(t, e.replace(/\./g, "/")), h = transformPathname(t, u);
|
|
289
|
-
if (t.inWildcard) break;
|
|
290
|
-
i ? p ? s.push(r({
|
|
291
|
-
localeDestination: l,
|
|
292
|
-
route: t,
|
|
293
|
-
template: m,
|
|
294
|
-
pathname: h
|
|
295
|
-
})) : s.push(r({
|
|
296
|
-
localeDestination: l,
|
|
297
|
-
localeSource: l,
|
|
298
|
-
route: t,
|
|
299
|
-
template: m,
|
|
300
|
-
pathname: h
|
|
301
|
-
})) : h !== m && (l !== n || f ? s.push(r({
|
|
302
|
-
localeSource: l,
|
|
303
|
-
route: t,
|
|
304
|
-
template: m,
|
|
305
|
-
pathname: h
|
|
306
|
-
})) : s.push(r({
|
|
307
|
-
route: t,
|
|
308
|
-
template: m,
|
|
309
|
-
pathname: h
|
|
310
|
-
})));
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return arrayUniqueByProperties(s.filter(Boolean), [
|
|
314
|
-
"source",
|
|
315
|
-
"destination"
|
|
316
|
-
]);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
205
|
let tweakNextConfig = (r, t)=>{
|
|
320
206
|
let { defaultLocale: i, locales: l, appRouterLocaleParamName: o } = r;
|
|
321
207
|
return o ? delete t.i18n : (t.i18n = t.i18n || {
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@koine/i18n",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@koine/node": "2.0.0-beta.
|
|
6
|
-
"@koine/utils": "2.0.0-beta.
|
|
5
|
+
"@koine/node": "2.0.0-beta.52",
|
|
6
|
+
"@koine/utils": "2.0.0-beta.52",
|
|
7
7
|
"glob": "^10.3.10",
|
|
8
8
|
"webpack": "^5.90.1",
|
|
9
9
|
"minimatch": "^9.0.3",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
},
|
|
53
53
|
"module": "./index.esm.js",
|
|
54
54
|
"main": "./index.cjs.js",
|
|
55
|
-
"version": "2.0.0-beta.
|
|
55
|
+
"version": "2.0.0-beta.52"
|
|
56
56
|
}
|