@koine/i18n 2.0.0-beta.68 → 2.0.0-beta.70
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 +71 -60
- package/api.esm.js +71 -60
- package/package.json +3 -3
package/api.cjs.js
CHANGED
|
@@ -62,7 +62,7 @@ exports.config = config;
|
|
|
62
62
|
module.exports = config;
|
|
63
63
|
`);
|
|
64
64
|
|
|
65
|
-
var o$
|
|
65
|
+
var o$7 = (({ config: e })=>`
|
|
66
66
|
import type { I18n } from "./types";
|
|
67
67
|
|
|
68
68
|
export const defaultLocale: I18n.Locale = "${e.defaultLocale}";
|
|
@@ -159,7 +159,7 @@ export const isLocale = (payload: any): payload is I18n.Locale => locales.includ
|
|
|
159
159
|
export default isLocale;
|
|
160
160
|
`);
|
|
161
161
|
|
|
162
|
-
var r$
|
|
162
|
+
var r$4 = (({ config: e })=>{
|
|
163
163
|
let l = `[${e.locales.map((e)=>`"${e}"`).join(", ")}]`;
|
|
164
164
|
return `
|
|
165
165
|
export const locales = ${l} as const;
|
|
@@ -212,7 +212,7 @@ export default routesSlim;
|
|
|
212
212
|
`;
|
|
213
213
|
});
|
|
214
214
|
|
|
215
|
-
var i$
|
|
215
|
+
var i$5 = (({ routes: t })=>{
|
|
216
216
|
let e = JSON.stringify(Object.fromEntries(Object.entries(t.byId).filter(([, { pathnamesSpa: t }])=>!!t).map(([t, { pathnamesSpa: e }])=>[
|
|
217
217
|
t,
|
|
218
218
|
e
|
|
@@ -239,13 +239,13 @@ let dataParamsToTsInterfaceBody = (e)=>Object.keys(e).reduce((r, t)=>{
|
|
|
239
239
|
return r.push(`${t}: ${s};`), r;
|
|
240
240
|
}, []).join(" ");
|
|
241
241
|
|
|
242
|
-
let i$
|
|
242
|
+
let i$4 = (t)=>utils.isString(t) || utils.isNumber(t) ? `"${t}"` : utils.isBoolean(t) ? `${t}` : utils.isArray(t) ? JSON.stringify(t) : `(${JSON.stringify(t)})`, s$6 = (e, r)=>utils.areEqual(e, r), p$2 = (t, e)=>{
|
|
243
243
|
let { defaultLocale: r } = t, l = "";
|
|
244
244
|
for(let t in e){
|
|
245
245
|
let o = e[t];
|
|
246
|
-
t === r || s$6(o, e[r]) || (l += `locale === "${t}" ? ${i$
|
|
246
|
+
t === r || s$6(o, e[r]) || (l += `locale === "${t}" ? ${i$4(o)} : `);
|
|
247
247
|
}
|
|
248
|
-
return l + i$
|
|
248
|
+
return l + i$4(e[r]);
|
|
249
249
|
};
|
|
250
250
|
var x$1 = (({ config: t, options: e, translations: r })=>{
|
|
251
251
|
let l = `
|
|
@@ -267,7 +267,7 @@ import { tPluralise } from "./tPluralise";
|
|
|
267
267
|
].filter(Boolean).join(", ");
|
|
268
268
|
l += `export let ${u} = (${$}) => `;
|
|
269
269
|
let c = "";
|
|
270
|
-
utils.isPrimitive(s) ? c += i$
|
|
270
|
+
utils.isPrimitive(s) ? c += i$4(s) : c += p$2(t, s), f && (c = `tPluralise(${c}, params.count)`), l += (c = m ? `tInterpolateParams(${c}, params);` : `${c};`) + `\n`;
|
|
271
271
|
}
|
|
272
272
|
return l;
|
|
273
273
|
});
|
|
@@ -297,7 +297,7 @@ let pluralRules = new Intl.PluralRules();
|
|
|
297
297
|
|
|
298
298
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
299
299
|
export let tPluralise = (values: any, count: number) =>
|
|
300
|
-
values[count] || values[pluralRules.select(count)] || values["other"];
|
|
300
|
+
values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"]);
|
|
301
301
|
|
|
302
302
|
export default tPluralise;
|
|
303
303
|
`);
|
|
@@ -335,7 +335,7 @@ export function to<Id extends I18n.RouteId>(
|
|
|
335
335
|
export default to;
|
|
336
336
|
`);
|
|
337
337
|
|
|
338
|
-
let o$
|
|
338
|
+
let o$6 = (t, e)=>{
|
|
339
339
|
let { defaultLocale: o } = t, r = "";
|
|
340
340
|
for(let t in e){
|
|
341
341
|
let l = e[t];
|
|
@@ -355,7 +355,7 @@ import type { I18n } from "./types";
|
|
|
355
355
|
s ? `params: ${p}` : "",
|
|
356
356
|
n ? "" : "locale?: I18n.Locale"
|
|
357
357
|
].filter(Boolean).join(", "), u = n ? '""' : "locale", I = s ? ", params" : "";
|
|
358
|
-
$ += `export let ${f} = (${c}) => `, utils.isString(i) ? $ += `toFormat(${u}, "${i}"${I});` : $ += `toFormat(${u}, ${o$
|
|
358
|
+
$ += `export let ${f} = (${c}) => `, utils.isString(i) ? $ += `toFormat(${u}, "${i}"${I});` : $ += `toFormat(${u}, ${o$6(r, i)}${I});`, $ += `\n`;
|
|
359
359
|
}
|
|
360
360
|
return $;
|
|
361
361
|
});
|
|
@@ -448,6 +448,11 @@ export function toSpa<
|
|
|
448
448
|
// FIXME: actually the locale will be prepended if hideDefaultLocaleInUrl will be false
|
|
449
449
|
"", // do not pass the locale so that won't be prepended
|
|
450
450
|
(routesSpa[fullId] as Record<string, string>)[locale],
|
|
451
|
+
args.length === 2
|
|
452
|
+
? args[0]
|
|
453
|
+
: args[0] && !isLocale(args[0])
|
|
454
|
+
? args[0]
|
|
455
|
+
: void 0,
|
|
451
456
|
) as I18n.RouteSpa[Root][Path];
|
|
452
457
|
}
|
|
453
458
|
|
|
@@ -462,7 +467,7 @@ let s$5 = [
|
|
|
462
467
|
"few",
|
|
463
468
|
"many",
|
|
464
469
|
"other"
|
|
465
|
-
], i$
|
|
470
|
+
], i$3 = "other";
|
|
466
471
|
let isPluralSuffix = (e)=>s$5.includes(e) || utils.isNumericLiteral(e);
|
|
467
472
|
let removePluralSuffix = (e)=>{
|
|
468
473
|
let [l] = utils.splitReverse(e, "_");
|
|
@@ -481,7 +486,7 @@ let a$3 = (e)=>{
|
|
|
481
486
|
}), l;
|
|
482
487
|
};
|
|
483
488
|
let transformKeysForPlurals = (l)=>{
|
|
484
|
-
if (l.includes(i$
|
|
489
|
+
if (l.includes(i$3)) {
|
|
485
490
|
let r = l.filter(isPluralKey);
|
|
486
491
|
if (r.length) {
|
|
487
492
|
let t = [
|
|
@@ -496,7 +501,7 @@ let transformKeysForPlurals = (l)=>{
|
|
|
496
501
|
}
|
|
497
502
|
return l;
|
|
498
503
|
};
|
|
499
|
-
let hasPlurals = (e)=>Object.keys(e).includes(i$
|
|
504
|
+
let hasPlurals = (e)=>Object.keys(e).includes(i$3);
|
|
500
505
|
let hasOnlyPluralKeys = (e)=>!!hasPlurals(e) && 0 === pickNonPluralKeys(e).length;
|
|
501
506
|
let pickNonPluralKeys = (e)=>Object.keys(e).filter((e)=>!isPluralSuffix(e));
|
|
502
507
|
let pickNonPluralValue = (e)=>hasPlurals(e) ? utils.objectPick(e, pickNonPluralKeys(e)) : e;
|
|
@@ -841,7 +846,7 @@ var t$2 = (()=>({
|
|
|
841
846
|
},
|
|
842
847
|
{
|
|
843
848
|
name: "defaultLocale",
|
|
844
|
-
fn: o$
|
|
849
|
+
fn: o$7,
|
|
845
850
|
ext: "ts",
|
|
846
851
|
index: !0
|
|
847
852
|
},
|
|
@@ -859,7 +864,7 @@ var t$2 = (()=>({
|
|
|
859
864
|
},
|
|
860
865
|
{
|
|
861
866
|
name: "locales",
|
|
862
|
-
fn: r$
|
|
867
|
+
fn: r$4,
|
|
863
868
|
ext: "ts",
|
|
864
869
|
index: !0
|
|
865
870
|
},
|
|
@@ -881,7 +886,7 @@ var t$2 = (()=>({
|
|
|
881
886
|
},
|
|
882
887
|
{
|
|
883
888
|
name: "routesSpa",
|
|
884
|
-
fn: i$
|
|
889
|
+
fn: i$5,
|
|
885
890
|
ext: "ts"
|
|
886
891
|
},
|
|
887
892
|
{
|
|
@@ -1112,7 +1117,7 @@ function transformPathname(e, t) {
|
|
|
1112
1117
|
return "/" + e.split("/").filter(Boolean).map((e)=>e.startsWith("[[...") ? `:${encodeURIComponent(e.slice(5, -2))}` : e.startsWith("[[") ? `:${encodeURIComponent(e.slice(2, -2))}` : e.startsWith("[") ? `:${encodeURIComponent(e.slice(1, -1))}` : `${encodeURIComponent(e)}`).join("/") + (t ? "/:wildcard*" : "");
|
|
1113
1118
|
}
|
|
1114
1119
|
|
|
1115
|
-
function r$
|
|
1120
|
+
function r$3(e) {
|
|
1116
1121
|
let { localeSource: o, localeDestination: l, template: r, pathname: i, permanent: a } = e, n = formatRoutePathname.formatRoutePathname((o ? `${o}/` : "") + r), c = formatRoutePathname.formatRoutePathname((l ? `${l}/` : "") + i);
|
|
1117
1122
|
if (n !== c) return {
|
|
1118
1123
|
source: n,
|
|
@@ -1132,20 +1137,20 @@ let generateRedirects = (t, i, a, n = "", c = !1)=>{
|
|
|
1132
1137
|
pathname: d,
|
|
1133
1138
|
permanent: c
|
|
1134
1139
|
};
|
|
1135
|
-
n ? D ? m.push(r$
|
|
1140
|
+
n ? D ? m.push(r$3({
|
|
1136
1141
|
...k,
|
|
1137
1142
|
localeDestination: i
|
|
1138
|
-
})) : g ? m.push(r$
|
|
1143
|
+
})) : g ? m.push(r$3({
|
|
1139
1144
|
...k,
|
|
1140
1145
|
localeSource: i
|
|
1141
|
-
})) : h ? m.push(r$
|
|
1146
|
+
})) : h ? m.push(r$3(k)) : m.push(r$3({
|
|
1142
1147
|
...k,
|
|
1143
1148
|
localeSource: i,
|
|
1144
1149
|
localeDestination: i
|
|
1145
|
-
})) : d !== f && (D ? m.push(r$
|
|
1150
|
+
})) : d !== f && (D ? m.push(r$3({
|
|
1146
1151
|
...k,
|
|
1147
1152
|
localeDestination: i
|
|
1148
|
-
})) : h ? m.push(r$
|
|
1153
|
+
})) : h ? m.push(r$3(k)) : m.push(r$3({
|
|
1149
1154
|
...k,
|
|
1150
1155
|
localeSource: i,
|
|
1151
1156
|
localeDestination: i
|
|
@@ -1166,46 +1171,49 @@ var e$1 = (({ config: e, routes: t, options: o })=>{
|
|
|
1166
1171
|
return `module.exports = ${l}`;
|
|
1167
1172
|
});
|
|
1168
1173
|
|
|
1169
|
-
function
|
|
1170
|
-
let { localeSource: t, localeDestination:
|
|
1174
|
+
function o$5(e) {
|
|
1175
|
+
let { localeSource: t, localeDestination: r, template: o, pathname: i } = e, a = "";
|
|
1171
1176
|
t && (a = `/${t}`);
|
|
1172
1177
|
let n = formatRoutePathname.formatRoutePathname(a + i), c = "";
|
|
1173
|
-
|
|
1174
|
-
let s = formatRoutePathname.formatRoutePathname(c +
|
|
1178
|
+
r && (c = `/${r}`);
|
|
1179
|
+
let s = formatRoutePathname.formatRoutePathname(c + o);
|
|
1175
1180
|
if (n !== s) return {
|
|
1176
1181
|
source: n,
|
|
1177
1182
|
destination: s
|
|
1178
1183
|
};
|
|
1179
1184
|
}
|
|
1180
|
-
let
|
|
1181
|
-
let { defaultLocale:
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1185
|
+
let i$2 = (e, t = "", l, r, i, a)=>{
|
|
1186
|
+
let { defaultLocale: n, hideDefaultLocaleInUrl: c } = e, s = l === n && c, u = {
|
|
1187
|
+
config: e,
|
|
1188
|
+
template: r,
|
|
1189
|
+
pathname: i
|
|
1190
|
+
};
|
|
1191
|
+
t ? s ? a.push(o$5({
|
|
1192
|
+
...u,
|
|
1193
|
+
localeDestination: l
|
|
1194
|
+
})) : a.push(o$5({
|
|
1195
|
+
...u,
|
|
1196
|
+
localeSource: l,
|
|
1197
|
+
localeDestination: l
|
|
1198
|
+
})) : i !== r && (s ? a.push(o$5(u)) : a.push({
|
|
1199
|
+
...o$5({
|
|
1200
|
+
...u,
|
|
1201
|
+
localeSource: l
|
|
1202
|
+
}),
|
|
1203
|
+
locale: !1
|
|
1204
|
+
}));
|
|
1205
|
+
};
|
|
1206
|
+
let generateRewrites = (l, o, a, n = "")=>{
|
|
1207
|
+
let c = RegExp(utils.escapeRegExp(a.tokens.idDelimiter), "g"), s = [];
|
|
1208
|
+
for(let e in o){
|
|
1209
|
+
let t = o[e], a = o[e].pathnames;
|
|
1210
|
+
for(let o in a){
|
|
1211
|
+
let u = a[o], p = e.replace(c, "/");
|
|
1186
1212
|
if (t.inWildcard) break;
|
|
1187
|
-
|
|
1188
|
-
config: l,
|
|
1189
|
-
template: d,
|
|
1190
|
-
pathname: h
|
|
1191
|
-
};
|
|
1192
|
-
n ? f ? p.push(r$3({
|
|
1193
|
-
...g,
|
|
1194
|
-
localeDestination: i
|
|
1195
|
-
})) : p.push(r$3({
|
|
1196
|
-
...g,
|
|
1197
|
-
localeSource: i,
|
|
1198
|
-
localeDestination: i
|
|
1199
|
-
})) : h !== d && (f ? p.push(r$3(g)) : p.push({
|
|
1200
|
-
...r$3({
|
|
1201
|
-
...g,
|
|
1202
|
-
localeSource: i
|
|
1203
|
-
}),
|
|
1204
|
-
locale: !1
|
|
1205
|
-
}));
|
|
1213
|
+
i$2(l, n, o, transformPathname(p), transformPathname(u), s), t.wildcard && i$2(l, n, o, transformPathname(p, t.wildcard), transformPathname(u, t.wildcard), s);
|
|
1206
1214
|
}
|
|
1207
1215
|
}
|
|
1208
|
-
return utils.arrayUniqueByProperties(
|
|
1216
|
+
return utils.arrayUniqueByProperties(s.filter(Boolean), [
|
|
1209
1217
|
"source",
|
|
1210
1218
|
"destination"
|
|
1211
1219
|
]).sort((e, t)=>e.source.localeCompare(t.source));
|
|
@@ -1297,19 +1305,22 @@ export const useToSpa = () => {
|
|
|
1297
1305
|
const locale = useLocale();
|
|
1298
1306
|
return <
|
|
1299
1307
|
Root extends keyof I18n.RouteSpa,
|
|
1300
|
-
Path extends Extract<keyof I18n.RouteSpa[Root], string
|
|
1308
|
+
Path extends Extract<keyof I18n.RouteSpa[Root], string>,
|
|
1301
1309
|
>(
|
|
1310
|
+
root: Root,
|
|
1311
|
+
path: Path,
|
|
1302
1312
|
...args: I18n.RouteJoinedId<Root, Path> extends I18n.RouteIdDynamic
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1313
|
+
? [params: I18n.RouteParams[I18n.RouteJoinedId<Root, Path>]]
|
|
1314
|
+
: I18n.RouteJoinedId<Root, Path> extends I18n.RouteIdStatic
|
|
1315
|
+
? []
|
|
1316
|
+
: never
|
|
1307
1317
|
) => {
|
|
1308
|
-
const [
|
|
1318
|
+
const [params] = args;
|
|
1309
1319
|
return (
|
|
1320
|
+
// prettier-ignore
|
|
1310
1321
|
// @ts-expect-error FIXME: types
|
|
1311
|
-
params ? toSpa(root, path, params, locale) : toSpa(root, path, locale)
|
|
1312
|
-
)
|
|
1322
|
+
(params ? toSpa(root, path, params, locale) : toSpa(root, path, locale)) as I18n.RouteSpa[Root][Path]
|
|
1323
|
+
);
|
|
1313
1324
|
};
|
|
1314
1325
|
};
|
|
1315
1326
|
|
package/api.esm.js
CHANGED
|
@@ -40,7 +40,7 @@ exports.config = config;
|
|
|
40
40
|
module.exports = config;
|
|
41
41
|
`);
|
|
42
42
|
|
|
43
|
-
var o$
|
|
43
|
+
var o$7 = (({ config: e })=>`
|
|
44
44
|
import type { I18n } from "./types";
|
|
45
45
|
|
|
46
46
|
export const defaultLocale: I18n.Locale = "${e.defaultLocale}";
|
|
@@ -137,7 +137,7 @@ export const isLocale = (payload: any): payload is I18n.Locale => locales.includ
|
|
|
137
137
|
export default isLocale;
|
|
138
138
|
`);
|
|
139
139
|
|
|
140
|
-
var r$
|
|
140
|
+
var r$4 = (({ config: e })=>{
|
|
141
141
|
let l = `[${e.locales.map((e)=>`"${e}"`).join(", ")}]`;
|
|
142
142
|
return `
|
|
143
143
|
export const locales = ${l} as const;
|
|
@@ -190,7 +190,7 @@ export default routesSlim;
|
|
|
190
190
|
`;
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
var i$
|
|
193
|
+
var i$5 = (({ routes: t })=>{
|
|
194
194
|
let e = JSON.stringify(Object.fromEntries(Object.entries(t.byId).filter(([, { pathnamesSpa: t }])=>!!t).map(([t, { pathnamesSpa: e }])=>[
|
|
195
195
|
t,
|
|
196
196
|
e
|
|
@@ -217,13 +217,13 @@ let dataParamsToTsInterfaceBody = (e)=>Object.keys(e).reduce((r, t)=>{
|
|
|
217
217
|
return r.push(`${t}: ${s};`), r;
|
|
218
218
|
}, []).join(" ");
|
|
219
219
|
|
|
220
|
-
let i$
|
|
220
|
+
let i$4 = (t)=>isString(t) || isNumber(t) ? `"${t}"` : isBoolean(t) ? `${t}` : isArray(t) ? JSON.stringify(t) : `(${JSON.stringify(t)})`, s$6 = (e, r)=>areEqual(e, r), p$2 = (t, e)=>{
|
|
221
221
|
let { defaultLocale: r } = t, l = "";
|
|
222
222
|
for(let t in e){
|
|
223
223
|
let o = e[t];
|
|
224
|
-
t === r || s$6(o, e[r]) || (l += `locale === "${t}" ? ${i$
|
|
224
|
+
t === r || s$6(o, e[r]) || (l += `locale === "${t}" ? ${i$4(o)} : `);
|
|
225
225
|
}
|
|
226
|
-
return l + i$
|
|
226
|
+
return l + i$4(e[r]);
|
|
227
227
|
};
|
|
228
228
|
var x$1 = (({ config: t, options: e, translations: r })=>{
|
|
229
229
|
let l = `
|
|
@@ -245,7 +245,7 @@ import { tPluralise } from "./tPluralise";
|
|
|
245
245
|
].filter(Boolean).join(", ");
|
|
246
246
|
l += `export let ${u} = (${$}) => `;
|
|
247
247
|
let c = "";
|
|
248
|
-
isPrimitive(s) ? c += i$
|
|
248
|
+
isPrimitive(s) ? c += i$4(s) : c += p$2(t, s), f && (c = `tPluralise(${c}, params.count)`), l += (c = m ? `tInterpolateParams(${c}, params);` : `${c};`) + `\n`;
|
|
249
249
|
}
|
|
250
250
|
return l;
|
|
251
251
|
});
|
|
@@ -275,7 +275,7 @@ let pluralRules = new Intl.PluralRules();
|
|
|
275
275
|
|
|
276
276
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
277
277
|
export let tPluralise = (values: any, count: number) =>
|
|
278
|
-
values[count] || values[pluralRules.select(count)] || values["other"];
|
|
278
|
+
values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"]);
|
|
279
279
|
|
|
280
280
|
export default tPluralise;
|
|
281
281
|
`);
|
|
@@ -313,7 +313,7 @@ export function to<Id extends I18n.RouteId>(
|
|
|
313
313
|
export default to;
|
|
314
314
|
`);
|
|
315
315
|
|
|
316
|
-
let o$
|
|
316
|
+
let o$6 = (t, e)=>{
|
|
317
317
|
let { defaultLocale: o } = t, r = "";
|
|
318
318
|
for(let t in e){
|
|
319
319
|
let l = e[t];
|
|
@@ -333,7 +333,7 @@ import type { I18n } from "./types";
|
|
|
333
333
|
s ? `params: ${p}` : "",
|
|
334
334
|
n ? "" : "locale?: I18n.Locale"
|
|
335
335
|
].filter(Boolean).join(", "), u = n ? '""' : "locale", I = s ? ", params" : "";
|
|
336
|
-
$ += `export let ${f} = (${c}) => `, isString(i) ? $ += `toFormat(${u}, "${i}"${I});` : $ += `toFormat(${u}, ${o$
|
|
336
|
+
$ += `export let ${f} = (${c}) => `, isString(i) ? $ += `toFormat(${u}, "${i}"${I});` : $ += `toFormat(${u}, ${o$6(r, i)}${I});`, $ += `\n`;
|
|
337
337
|
}
|
|
338
338
|
return $;
|
|
339
339
|
});
|
|
@@ -426,6 +426,11 @@ export function toSpa<
|
|
|
426
426
|
// FIXME: actually the locale will be prepended if hideDefaultLocaleInUrl will be false
|
|
427
427
|
"", // do not pass the locale so that won't be prepended
|
|
428
428
|
(routesSpa[fullId] as Record<string, string>)[locale],
|
|
429
|
+
args.length === 2
|
|
430
|
+
? args[0]
|
|
431
|
+
: args[0] && !isLocale(args[0])
|
|
432
|
+
? args[0]
|
|
433
|
+
: void 0,
|
|
429
434
|
) as I18n.RouteSpa[Root][Path];
|
|
430
435
|
}
|
|
431
436
|
|
|
@@ -440,7 +445,7 @@ let s$5 = [
|
|
|
440
445
|
"few",
|
|
441
446
|
"many",
|
|
442
447
|
"other"
|
|
443
|
-
], i$
|
|
448
|
+
], i$3 = "other";
|
|
444
449
|
let isPluralSuffix = (e)=>s$5.includes(e) || isNumericLiteral(e);
|
|
445
450
|
let removePluralSuffix = (e)=>{
|
|
446
451
|
let [l] = splitReverse(e, "_");
|
|
@@ -459,7 +464,7 @@ let a$3 = (e)=>{
|
|
|
459
464
|
}), l;
|
|
460
465
|
};
|
|
461
466
|
let transformKeysForPlurals = (l)=>{
|
|
462
|
-
if (l.includes(i$
|
|
467
|
+
if (l.includes(i$3)) {
|
|
463
468
|
let r = l.filter(isPluralKey);
|
|
464
469
|
if (r.length) {
|
|
465
470
|
let t = [
|
|
@@ -474,7 +479,7 @@ let transformKeysForPlurals = (l)=>{
|
|
|
474
479
|
}
|
|
475
480
|
return l;
|
|
476
481
|
};
|
|
477
|
-
let hasPlurals = (e)=>Object.keys(e).includes(i$
|
|
482
|
+
let hasPlurals = (e)=>Object.keys(e).includes(i$3);
|
|
478
483
|
let hasOnlyPluralKeys = (e)=>!!hasPlurals(e) && 0 === pickNonPluralKeys(e).length;
|
|
479
484
|
let pickNonPluralKeys = (e)=>Object.keys(e).filter((e)=>!isPluralSuffix(e));
|
|
480
485
|
let pickNonPluralValue = (e)=>hasPlurals(e) ? objectPick(e, pickNonPluralKeys(e)) : e;
|
|
@@ -819,7 +824,7 @@ var t$2 = (()=>({
|
|
|
819
824
|
},
|
|
820
825
|
{
|
|
821
826
|
name: "defaultLocale",
|
|
822
|
-
fn: o$
|
|
827
|
+
fn: o$7,
|
|
823
828
|
ext: "ts",
|
|
824
829
|
index: !0
|
|
825
830
|
},
|
|
@@ -837,7 +842,7 @@ var t$2 = (()=>({
|
|
|
837
842
|
},
|
|
838
843
|
{
|
|
839
844
|
name: "locales",
|
|
840
|
-
fn: r$
|
|
845
|
+
fn: r$4,
|
|
841
846
|
ext: "ts",
|
|
842
847
|
index: !0
|
|
843
848
|
},
|
|
@@ -859,7 +864,7 @@ var t$2 = (()=>({
|
|
|
859
864
|
},
|
|
860
865
|
{
|
|
861
866
|
name: "routesSpa",
|
|
862
|
-
fn: i$
|
|
867
|
+
fn: i$5,
|
|
863
868
|
ext: "ts"
|
|
864
869
|
},
|
|
865
870
|
{
|
|
@@ -1090,7 +1095,7 @@ function transformPathname(e, t) {
|
|
|
1090
1095
|
return "/" + e.split("/").filter(Boolean).map((e)=>e.startsWith("[[...") ? `:${encodeURIComponent(e.slice(5, -2))}` : e.startsWith("[[") ? `:${encodeURIComponent(e.slice(2, -2))}` : e.startsWith("[") ? `:${encodeURIComponent(e.slice(1, -1))}` : `${encodeURIComponent(e)}`).join("/") + (t ? "/:wildcard*" : "");
|
|
1091
1096
|
}
|
|
1092
1097
|
|
|
1093
|
-
function r$
|
|
1098
|
+
function r$3(e) {
|
|
1094
1099
|
let { localeSource: o, localeDestination: l, template: r, pathname: i, permanent: a } = e, n = formatRoutePathname((o ? `${o}/` : "") + r), c = formatRoutePathname((l ? `${l}/` : "") + i);
|
|
1095
1100
|
if (n !== c) return {
|
|
1096
1101
|
source: n,
|
|
@@ -1110,20 +1115,20 @@ let generateRedirects = (t, i, a, n = "", c = !1)=>{
|
|
|
1110
1115
|
pathname: d,
|
|
1111
1116
|
permanent: c
|
|
1112
1117
|
};
|
|
1113
|
-
n ? D ? m.push(r$
|
|
1118
|
+
n ? D ? m.push(r$3({
|
|
1114
1119
|
...k,
|
|
1115
1120
|
localeDestination: i
|
|
1116
|
-
})) : g ? m.push(r$
|
|
1121
|
+
})) : g ? m.push(r$3({
|
|
1117
1122
|
...k,
|
|
1118
1123
|
localeSource: i
|
|
1119
|
-
})) : h ? m.push(r$
|
|
1124
|
+
})) : h ? m.push(r$3(k)) : m.push(r$3({
|
|
1120
1125
|
...k,
|
|
1121
1126
|
localeSource: i,
|
|
1122
1127
|
localeDestination: i
|
|
1123
|
-
})) : d !== f && (D ? m.push(r$
|
|
1128
|
+
})) : d !== f && (D ? m.push(r$3({
|
|
1124
1129
|
...k,
|
|
1125
1130
|
localeDestination: i
|
|
1126
|
-
})) : h ? m.push(r$
|
|
1131
|
+
})) : h ? m.push(r$3(k)) : m.push(r$3({
|
|
1127
1132
|
...k,
|
|
1128
1133
|
localeSource: i,
|
|
1129
1134
|
localeDestination: i
|
|
@@ -1144,46 +1149,49 @@ var e$1 = (({ config: e, routes: t, options: o })=>{
|
|
|
1144
1149
|
return `module.exports = ${l}`;
|
|
1145
1150
|
});
|
|
1146
1151
|
|
|
1147
|
-
function
|
|
1148
|
-
let { localeSource: t, localeDestination:
|
|
1152
|
+
function o$5(e) {
|
|
1153
|
+
let { localeSource: t, localeDestination: r, template: o, pathname: i } = e, a = "";
|
|
1149
1154
|
t && (a = `/${t}`);
|
|
1150
1155
|
let n = formatRoutePathname(a + i), c = "";
|
|
1151
|
-
|
|
1152
|
-
let s = formatRoutePathname(c +
|
|
1156
|
+
r && (c = `/${r}`);
|
|
1157
|
+
let s = formatRoutePathname(c + o);
|
|
1153
1158
|
if (n !== s) return {
|
|
1154
1159
|
source: n,
|
|
1155
1160
|
destination: s
|
|
1156
1161
|
};
|
|
1157
1162
|
}
|
|
1158
|
-
let
|
|
1159
|
-
let { defaultLocale:
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1163
|
+
let i$2 = (e, t = "", l, r, i, a)=>{
|
|
1164
|
+
let { defaultLocale: n, hideDefaultLocaleInUrl: c } = e, s = l === n && c, u = {
|
|
1165
|
+
config: e,
|
|
1166
|
+
template: r,
|
|
1167
|
+
pathname: i
|
|
1168
|
+
};
|
|
1169
|
+
t ? s ? a.push(o$5({
|
|
1170
|
+
...u,
|
|
1171
|
+
localeDestination: l
|
|
1172
|
+
})) : a.push(o$5({
|
|
1173
|
+
...u,
|
|
1174
|
+
localeSource: l,
|
|
1175
|
+
localeDestination: l
|
|
1176
|
+
})) : i !== r && (s ? a.push(o$5(u)) : a.push({
|
|
1177
|
+
...o$5({
|
|
1178
|
+
...u,
|
|
1179
|
+
localeSource: l
|
|
1180
|
+
}),
|
|
1181
|
+
locale: !1
|
|
1182
|
+
}));
|
|
1183
|
+
};
|
|
1184
|
+
let generateRewrites = (l, o, a, n = "")=>{
|
|
1185
|
+
let c = RegExp(escapeRegExp(a.tokens.idDelimiter), "g"), s = [];
|
|
1186
|
+
for(let e in o){
|
|
1187
|
+
let t = o[e], a = o[e].pathnames;
|
|
1188
|
+
for(let o in a){
|
|
1189
|
+
let u = a[o], p = e.replace(c, "/");
|
|
1164
1190
|
if (t.inWildcard) break;
|
|
1165
|
-
|
|
1166
|
-
config: l,
|
|
1167
|
-
template: d,
|
|
1168
|
-
pathname: h
|
|
1169
|
-
};
|
|
1170
|
-
n ? f ? p.push(r$3({
|
|
1171
|
-
...g,
|
|
1172
|
-
localeDestination: i
|
|
1173
|
-
})) : p.push(r$3({
|
|
1174
|
-
...g,
|
|
1175
|
-
localeSource: i,
|
|
1176
|
-
localeDestination: i
|
|
1177
|
-
})) : h !== d && (f ? p.push(r$3(g)) : p.push({
|
|
1178
|
-
...r$3({
|
|
1179
|
-
...g,
|
|
1180
|
-
localeSource: i
|
|
1181
|
-
}),
|
|
1182
|
-
locale: !1
|
|
1183
|
-
}));
|
|
1191
|
+
i$2(l, n, o, transformPathname(p), transformPathname(u), s), t.wildcard && i$2(l, n, o, transformPathname(p, t.wildcard), transformPathname(u, t.wildcard), s);
|
|
1184
1192
|
}
|
|
1185
1193
|
}
|
|
1186
|
-
return arrayUniqueByProperties(
|
|
1194
|
+
return arrayUniqueByProperties(s.filter(Boolean), [
|
|
1187
1195
|
"source",
|
|
1188
1196
|
"destination"
|
|
1189
1197
|
]).sort((e, t)=>e.source.localeCompare(t.source));
|
|
@@ -1275,19 +1283,22 @@ export const useToSpa = () => {
|
|
|
1275
1283
|
const locale = useLocale();
|
|
1276
1284
|
return <
|
|
1277
1285
|
Root extends keyof I18n.RouteSpa,
|
|
1278
|
-
Path extends Extract<keyof I18n.RouteSpa[Root], string
|
|
1286
|
+
Path extends Extract<keyof I18n.RouteSpa[Root], string>,
|
|
1279
1287
|
>(
|
|
1288
|
+
root: Root,
|
|
1289
|
+
path: Path,
|
|
1280
1290
|
...args: I18n.RouteJoinedId<Root, Path> extends I18n.RouteIdDynamic
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1291
|
+
? [params: I18n.RouteParams[I18n.RouteJoinedId<Root, Path>]]
|
|
1292
|
+
: I18n.RouteJoinedId<Root, Path> extends I18n.RouteIdStatic
|
|
1293
|
+
? []
|
|
1294
|
+
: never
|
|
1285
1295
|
) => {
|
|
1286
|
-
const [
|
|
1296
|
+
const [params] = args;
|
|
1287
1297
|
return (
|
|
1298
|
+
// prettier-ignore
|
|
1288
1299
|
// @ts-expect-error FIXME: types
|
|
1289
|
-
params ? toSpa(root, path, params, locale) : toSpa(root, path, locale)
|
|
1290
|
-
)
|
|
1300
|
+
(params ? toSpa(root, path, params, locale) : toSpa(root, path, locale)) as I18n.RouteSpa[Root][Path]
|
|
1301
|
+
);
|
|
1291
1302
|
};
|
|
1292
1303
|
};
|
|
1293
1304
|
|
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.70",
|
|
6
|
+
"@koine/utils": "2.0.0-beta.70",
|
|
7
7
|
"glob": "^10.3.10",
|
|
8
8
|
"webpack": "^5.90.1",
|
|
9
9
|
"minimatch": "^9.0.3",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
},
|
|
59
59
|
"module": "./index.esm.js",
|
|
60
60
|
"main": "./index.cjs.js",
|
|
61
|
-
"version": "2.0.0-beta.
|
|
61
|
+
"version": "2.0.0-beta.70"
|
|
62
62
|
}
|