@koine/i18n 2.0.0-beta.51 → 2.0.0-beta.53
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 +169 -29
- package/api.esm.js +168 -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$5 = (()=>`
|
|
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$3 = (({ 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$2 = (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$2(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$5,
|
|
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$3,
|
|
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,132 @@ 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 o$4(e) {
|
|
1059
|
+
let { localeSource: l, localeDestination: o, localeParam: r, template: i, pathname: n } = e, a = "";
|
|
1060
|
+
l ? a = `/${l}` : r && (a = `/:${r}`);
|
|
1061
|
+
let c = formatRoutePathname.formatRoutePathname(a + n), s = "";
|
|
1062
|
+
o ? s = `/${o}` : r && (s = `/:${r}`);
|
|
1063
|
+
let u = formatRoutePathname.formatRoutePathname(s + i);
|
|
1064
|
+
if (c !== u) return {
|
|
1065
|
+
source: c,
|
|
1066
|
+
destination: u,
|
|
1067
|
+
locale: !1
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
let generateRewrites = (t, r, i = "")=>{
|
|
1071
|
+
let { defaultLocale: n, hideDefaultLocaleInUrl: a } = t, c = [];
|
|
1072
|
+
for(let e in r){
|
|
1073
|
+
let t = r[e], s = r[e].pathnames;
|
|
1074
|
+
for(let r in s){
|
|
1075
|
+
let u = s[r], f = r === n && !a, p = r === n && a, m = transformPathname(t, e.replace(/\./g, "/")), h = transformPathname(t, u);
|
|
1076
|
+
if (t.inWildcard) break;
|
|
1077
|
+
i ? p ? c.push(o$4({
|
|
1078
|
+
localeDestination: r,
|
|
1079
|
+
route: t,
|
|
1080
|
+
template: m,
|
|
1081
|
+
pathname: h
|
|
1082
|
+
})) : c.push(o$4({
|
|
1083
|
+
localeDestination: r,
|
|
1084
|
+
localeSource: r,
|
|
1085
|
+
route: t,
|
|
1086
|
+
template: m,
|
|
1087
|
+
pathname: h
|
|
1088
|
+
})) : h !== m && (r !== n || f ? c.push(o$4({
|
|
1089
|
+
localeSource: r,
|
|
1090
|
+
route: t,
|
|
1091
|
+
template: m,
|
|
1092
|
+
pathname: h
|
|
1093
|
+
})) : c.push(o$4({
|
|
1094
|
+
route: t,
|
|
1095
|
+
template: m,
|
|
1096
|
+
pathname: h
|
|
1097
|
+
})));
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
return utils$1.arrayUniqueByProperties(c.filter(Boolean), [
|
|
1101
|
+
"source",
|
|
1102
|
+
"destination"
|
|
1103
|
+
]);
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
var t = (({ config: e, routes: t })=>{
|
|
1107
|
+
let l = JSON.stringify(generateRewrites(e, t), null, 2);
|
|
1108
|
+
return `module.exports = ${l}`;
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
var n$2 = (()=>`
|
|
987
1112
|
"use client";
|
|
988
1113
|
|
|
989
1114
|
import { useEffect, useState } from "react";
|
|
@@ -1004,7 +1129,7 @@ export function useCurrentLocalisedPathnames() {
|
|
|
1004
1129
|
export default useCurrentLocalisedPathnames;
|
|
1005
1130
|
`);
|
|
1006
1131
|
|
|
1007
|
-
var
|
|
1132
|
+
var r$1 = (({ config: e })=>`
|
|
1008
1133
|
import { useRouter } from "next/router";
|
|
1009
1134
|
import type { I18n } from "./types";
|
|
1010
1135
|
|
|
@@ -1024,7 +1149,7 @@ export const useRouteId = () =>
|
|
|
1024
1149
|
export default useRouteId;
|
|
1025
1150
|
`);
|
|
1026
1151
|
|
|
1027
|
-
var
|
|
1152
|
+
var o$3 = (()=>`
|
|
1028
1153
|
"use client";
|
|
1029
1154
|
|
|
1030
1155
|
import { to } from "./to";
|
|
@@ -1057,15 +1182,25 @@ var n$1 = (()=>({
|
|
|
1057
1182
|
"js"
|
|
1058
1183
|
],
|
|
1059
1184
|
files: [
|
|
1185
|
+
{
|
|
1186
|
+
name: "next-redirects",
|
|
1187
|
+
fn: e$1,
|
|
1188
|
+
ext: "js"
|
|
1189
|
+
},
|
|
1190
|
+
{
|
|
1191
|
+
name: "next-rewrites",
|
|
1192
|
+
fn: t,
|
|
1193
|
+
ext: "js"
|
|
1194
|
+
},
|
|
1060
1195
|
{
|
|
1061
1196
|
name: "useCurrentLocalisedPathnames",
|
|
1062
|
-
fn:
|
|
1197
|
+
fn: n$2,
|
|
1063
1198
|
ext: "ts",
|
|
1064
1199
|
index: !0
|
|
1065
1200
|
},
|
|
1066
1201
|
{
|
|
1067
1202
|
name: "useLocale",
|
|
1068
|
-
fn:
|
|
1203
|
+
fn: r$1,
|
|
1069
1204
|
ext: "ts",
|
|
1070
1205
|
index: !0
|
|
1071
1206
|
},
|
|
@@ -1077,7 +1212,7 @@ var n$1 = (()=>({
|
|
|
1077
1212
|
},
|
|
1078
1213
|
{
|
|
1079
1214
|
name: "useTo",
|
|
1080
|
-
fn:
|
|
1215
|
+
fn: o$3,
|
|
1081
1216
|
ext: "ts",
|
|
1082
1217
|
index: !0
|
|
1083
1218
|
}
|
|
@@ -1085,7 +1220,7 @@ var n$1 = (()=>({
|
|
|
1085
1220
|
}));
|
|
1086
1221
|
|
|
1087
1222
|
let a = {
|
|
1088
|
-
js: e$
|
|
1223
|
+
js: e$3,
|
|
1089
1224
|
next: n$1,
|
|
1090
1225
|
"next-translate": t$1
|
|
1091
1226
|
}, r = (e)=>{
|
|
@@ -1282,18 +1417,21 @@ const codeDataTranslationsOptions = {
|
|
|
1282
1417
|
fnsPrefix: "",
|
|
1283
1418
|
createArrayIndexBasedFns: !1
|
|
1284
1419
|
};
|
|
1285
|
-
|
|
1420
|
+
let e = {
|
|
1286
1421
|
routes: codeDataRoutesOptions,
|
|
1287
1422
|
translations: codeDataTranslationsOptions
|
|
1288
1423
|
};
|
|
1289
|
-
let getCodeData = (s,
|
|
1290
|
-
let
|
|
1291
|
-
return
|
|
1424
|
+
let getCodeData = (s, n, r)=>{
|
|
1425
|
+
let i = utils$1.objectMergeWithDefaults(e, n);
|
|
1426
|
+
return i.translations.ignorePaths.push(i.routes.translationJsonFileName), r = {
|
|
1427
|
+
...r,
|
|
1428
|
+
localesFolders: r.localesFolders.sort((t, o)=>s.defaultLocale ? -1 : t.localeCompare(o))
|
|
1429
|
+
}, {
|
|
1292
1430
|
config: s,
|
|
1293
|
-
options:
|
|
1294
|
-
input:
|
|
1295
|
-
routes: getCodeDataRoutes(s,
|
|
1296
|
-
translations: getCodeDataTranslations(s,
|
|
1431
|
+
options: i,
|
|
1432
|
+
input: r,
|
|
1433
|
+
routes: getCodeDataRoutes(s, i.routes, r),
|
|
1434
|
+
translations: getCodeDataTranslations(s, i.translations, r)
|
|
1297
1435
|
};
|
|
1298
1436
|
};
|
|
1299
1437
|
|
|
@@ -1316,4 +1454,6 @@ let i18nCompiler = async (p)=>{
|
|
|
1316
1454
|
};
|
|
1317
1455
|
};
|
|
1318
1456
|
|
|
1457
|
+
exports.generateRedirects = generateRedirects;
|
|
1458
|
+
exports.generateRewrites = generateRewrites;
|
|
1319
1459
|
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$5 = (()=>`
|
|
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$3 = (({ 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$2 = (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$2(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$5,
|
|
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$3,
|
|
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,132 @@ 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 o$4(e) {
|
|
1035
|
+
let { localeSource: l, localeDestination: o, localeParam: r, template: i, pathname: n } = e, a = "";
|
|
1036
|
+
l ? a = `/${l}` : r && (a = `/:${r}`);
|
|
1037
|
+
let c = formatRoutePathname(a + n), s = "";
|
|
1038
|
+
o ? s = `/${o}` : r && (s = `/:${r}`);
|
|
1039
|
+
let u = formatRoutePathname(s + i);
|
|
1040
|
+
if (c !== u) return {
|
|
1041
|
+
source: c,
|
|
1042
|
+
destination: u,
|
|
1043
|
+
locale: !1
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
let generateRewrites = (t, r, i = "")=>{
|
|
1047
|
+
let { defaultLocale: n, hideDefaultLocaleInUrl: a } = t, c = [];
|
|
1048
|
+
for(let e in r){
|
|
1049
|
+
let t = r[e], s = r[e].pathnames;
|
|
1050
|
+
for(let r in s){
|
|
1051
|
+
let u = s[r], f = r === n && !a, p = r === n && a, m = transformPathname(t, e.replace(/\./g, "/")), h = transformPathname(t, u);
|
|
1052
|
+
if (t.inWildcard) break;
|
|
1053
|
+
i ? p ? c.push(o$4({
|
|
1054
|
+
localeDestination: r,
|
|
1055
|
+
route: t,
|
|
1056
|
+
template: m,
|
|
1057
|
+
pathname: h
|
|
1058
|
+
})) : c.push(o$4({
|
|
1059
|
+
localeDestination: r,
|
|
1060
|
+
localeSource: r,
|
|
1061
|
+
route: t,
|
|
1062
|
+
template: m,
|
|
1063
|
+
pathname: h
|
|
1064
|
+
})) : h !== m && (r !== n || f ? c.push(o$4({
|
|
1065
|
+
localeSource: r,
|
|
1066
|
+
route: t,
|
|
1067
|
+
template: m,
|
|
1068
|
+
pathname: h
|
|
1069
|
+
})) : c.push(o$4({
|
|
1070
|
+
route: t,
|
|
1071
|
+
template: m,
|
|
1072
|
+
pathname: h
|
|
1073
|
+
})));
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return arrayUniqueByProperties(c.filter(Boolean), [
|
|
1077
|
+
"source",
|
|
1078
|
+
"destination"
|
|
1079
|
+
]);
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
var t = (({ config: e, routes: t })=>{
|
|
1083
|
+
let l = JSON.stringify(generateRewrites(e, t), null, 2);
|
|
1084
|
+
return `module.exports = ${l}`;
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
var n$2 = (()=>`
|
|
963
1088
|
"use client";
|
|
964
1089
|
|
|
965
1090
|
import { useEffect, useState } from "react";
|
|
@@ -980,7 +1105,7 @@ export function useCurrentLocalisedPathnames() {
|
|
|
980
1105
|
export default useCurrentLocalisedPathnames;
|
|
981
1106
|
`);
|
|
982
1107
|
|
|
983
|
-
var
|
|
1108
|
+
var r$1 = (({ config: e })=>`
|
|
984
1109
|
import { useRouter } from "next/router";
|
|
985
1110
|
import type { I18n } from "./types";
|
|
986
1111
|
|
|
@@ -1000,7 +1125,7 @@ export const useRouteId = () =>
|
|
|
1000
1125
|
export default useRouteId;
|
|
1001
1126
|
`);
|
|
1002
1127
|
|
|
1003
|
-
var
|
|
1128
|
+
var o$3 = (()=>`
|
|
1004
1129
|
"use client";
|
|
1005
1130
|
|
|
1006
1131
|
import { to } from "./to";
|
|
@@ -1033,15 +1158,25 @@ var n$1 = (()=>({
|
|
|
1033
1158
|
"js"
|
|
1034
1159
|
],
|
|
1035
1160
|
files: [
|
|
1161
|
+
{
|
|
1162
|
+
name: "next-redirects",
|
|
1163
|
+
fn: e$1,
|
|
1164
|
+
ext: "js"
|
|
1165
|
+
},
|
|
1166
|
+
{
|
|
1167
|
+
name: "next-rewrites",
|
|
1168
|
+
fn: t,
|
|
1169
|
+
ext: "js"
|
|
1170
|
+
},
|
|
1036
1171
|
{
|
|
1037
1172
|
name: "useCurrentLocalisedPathnames",
|
|
1038
|
-
fn:
|
|
1173
|
+
fn: n$2,
|
|
1039
1174
|
ext: "ts",
|
|
1040
1175
|
index: !0
|
|
1041
1176
|
},
|
|
1042
1177
|
{
|
|
1043
1178
|
name: "useLocale",
|
|
1044
|
-
fn:
|
|
1179
|
+
fn: r$1,
|
|
1045
1180
|
ext: "ts",
|
|
1046
1181
|
index: !0
|
|
1047
1182
|
},
|
|
@@ -1053,7 +1188,7 @@ var n$1 = (()=>({
|
|
|
1053
1188
|
},
|
|
1054
1189
|
{
|
|
1055
1190
|
name: "useTo",
|
|
1056
|
-
fn:
|
|
1191
|
+
fn: o$3,
|
|
1057
1192
|
ext: "ts",
|
|
1058
1193
|
index: !0
|
|
1059
1194
|
}
|
|
@@ -1061,7 +1196,7 @@ var n$1 = (()=>({
|
|
|
1061
1196
|
}));
|
|
1062
1197
|
|
|
1063
1198
|
let a = {
|
|
1064
|
-
js: e$
|
|
1199
|
+
js: e$3,
|
|
1065
1200
|
next: n$1,
|
|
1066
1201
|
"next-translate": t$1
|
|
1067
1202
|
}, r = (e)=>{
|
|
@@ -1258,18 +1393,21 @@ const codeDataTranslationsOptions = {
|
|
|
1258
1393
|
fnsPrefix: "",
|
|
1259
1394
|
createArrayIndexBasedFns: !1
|
|
1260
1395
|
};
|
|
1261
|
-
|
|
1396
|
+
let e = {
|
|
1262
1397
|
routes: codeDataRoutesOptions,
|
|
1263
1398
|
translations: codeDataTranslationsOptions
|
|
1264
1399
|
};
|
|
1265
|
-
let getCodeData = (s,
|
|
1266
|
-
let
|
|
1267
|
-
return
|
|
1400
|
+
let getCodeData = (s, n, r)=>{
|
|
1401
|
+
let i = objectMergeWithDefaults(e, n);
|
|
1402
|
+
return i.translations.ignorePaths.push(i.routes.translationJsonFileName), r = {
|
|
1403
|
+
...r,
|
|
1404
|
+
localesFolders: r.localesFolders.sort((t, o)=>s.defaultLocale ? -1 : t.localeCompare(o))
|
|
1405
|
+
}, {
|
|
1268
1406
|
config: s,
|
|
1269
|
-
options:
|
|
1270
|
-
input:
|
|
1271
|
-
routes: getCodeDataRoutes(s,
|
|
1272
|
-
translations: getCodeDataTranslations(s,
|
|
1407
|
+
options: i,
|
|
1408
|
+
input: r,
|
|
1409
|
+
routes: getCodeDataRoutes(s, i.routes, r),
|
|
1410
|
+
translations: getCodeDataTranslations(s, i.translations, r)
|
|
1273
1411
|
};
|
|
1274
1412
|
};
|
|
1275
1413
|
|
|
@@ -1292,4 +1430,4 @@ let i18nCompiler = async (p)=>{
|
|
|
1292
1430
|
};
|
|
1293
1431
|
};
|
|
1294
1432
|
|
|
1295
|
-
export { i18nCompiler as i };
|
|
1433
|
+
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.53",
|
|
6
|
+
"@koine/utils": "2.0.0-beta.53",
|
|
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.53"
|
|
56
56
|
}
|