@koine/i18n 2.0.0-beta.76 → 2.0.0-beta.78
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/README.md +1 -0
- package/api.cjs.js +2203 -0
- package/api.esm.js +2179 -0
- package/compiler-sync.cjs.d.ts +1 -0
- package/compiler-sync.cjs.default.js +1 -0
- package/compiler-sync.cjs.js +20 -0
- package/compiler-sync.cjs.mjs +2 -0
- package/compiler-sync.esm.js +16 -0
- package/compiler-worker.cjs.d.ts +1 -0
- package/compiler-worker.cjs.default.js +1 -0
- package/compiler-worker.cjs.js +18 -0
- package/compiler-worker.cjs.mjs +2 -0
- package/compiler-worker.esm.js +16 -0
- package/compiler.cjs.d.ts +1 -0
- package/compiler.cjs.default.js +1 -0
- package/compiler.cjs.js +21 -0
- package/compiler.cjs.mjs +2 -0
- package/compiler.esm.js +13 -0
- package/formatRoutePathname.cjs.js +12 -0
- package/formatRoutePathname.esm.js +10 -0
- package/index.cjs.d.ts +1 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +47 -0
- package/index.cjs.mjs +2 -0
- package/index.esm.js +42 -0
- package/next.cjs.d.ts +1 -0
- package/next.cjs.default.js +1 -0
- package/next.cjs.js +377 -0
- package/next.cjs.mjs +2 -0
- package/next.esm.js +353 -0
- package/package.json +22 -305
- package/actions/helpers-git.js +0 -45
- package/actions/helpers-i18n.js +0 -27
- package/actions/i18n.js +0 -17
- package/adapter-js/code/config.cjs.js +0 -14
- package/adapter-js/code/config.js +0 -14
- package/adapter-js/code/defaultLocale.js +0 -7
- package/adapter-js/code/deriveLocalisedPathnames.js +0 -78
- package/adapter-js/code/index.js +0 -123
- package/adapter-js/code/isLocale.js +0 -9
- package/adapter-js/code/locales.js +0 -8
- package/adapter-js/code/pathnameToRouteId.js +0 -20
- package/adapter-js/code/routes.js +0 -11
- package/adapter-js/code/routesSlim.js +0 -11
- package/adapter-js/code/routesSpa.js +0 -11
- package/adapter-js/code/tFns.js +0 -34
- package/adapter-js/code/tInterpolateParams.js +0 -18
- package/adapter-js/code/tPluralise.js +0 -10
- package/adapter-js/code/to.js +0 -32
- package/adapter-js/code/toFns.js +0 -25
- package/adapter-js/code/toFormat.js +0 -56
- package/adapter-js/code/toSpa.js +0 -42
- package/adapter-js/code/types.js +0 -327
- package/adapter-next/code/index.js +0 -54
- package/adapter-next/code/next-redirects.js +0 -5
- package/adapter-next/code/next-rewrites.js +0 -5
- package/adapter-next/code/useCurrentLocalisedPathnames.js +0 -20
- package/adapter-next/code/useLocale.js +0 -8
- package/adapter-next/code/useRouteId.js +0 -10
- package/adapter-next/code/useTo.js +0 -26
- package/adapter-next/code/useToSpa.js +0 -34
- package/adapter-next/plugin-async.js +0 -11
- package/adapter-next/plugin-legacy.js +0 -187
- package/adapter-next/plugin-shared.js +0 -39
- package/adapter-next/plugin.js +0 -13
- package/adapter-next/redirects.js +0 -51
- package/adapter-next/rewrites.js +0 -50
- package/adapter-next/transformPathname.js +0 -3
- package/adapter-next/webpackPluginI18n.js +0 -11
- package/adapter-next-translate/code/DynamicNamespaces.js +0 -9
- package/adapter-next-translate/code/T.js +0 -31
- package/adapter-next-translate/code/TransText.js +0 -9
- package/adapter-next-translate/code/getT.js +0 -15
- package/adapter-next-translate/code/index.js +0 -49
- package/adapter-next-translate/code/nextTranslateI18n.js +0 -19
- package/adapter-next-translate/code/useT.js +0 -43
- package/cjs/adapter-js/code/config.cjs.d.ts +0 -3
- package/cjs/adapter-js/code/config.d.ts +0 -3
- package/cjs/adapter-js/code/defaultLocale.d.ts +0 -3
- package/cjs/adapter-js/code/deriveLocalisedPathnames.d.ts +0 -2
- package/cjs/adapter-js/code/index.d.ts +0 -3
- package/cjs/adapter-js/code/isLocale.d.ts +0 -2
- package/cjs/adapter-js/code/locales.d.ts +0 -3
- package/cjs/adapter-js/code/pathnameToRouteId.d.ts +0 -3
- package/cjs/adapter-js/code/routes.d.ts +0 -3
- package/cjs/adapter-js/code/routesSlim.d.ts +0 -3
- package/cjs/adapter-js/code/routesSpa.d.ts +0 -3
- package/cjs/adapter-js/code/tFns.d.ts +0 -3
- package/cjs/adapter-js/code/tInterpolateParams.d.ts +0 -3
- package/cjs/adapter-js/code/tPluralise.d.ts +0 -2
- package/cjs/adapter-js/code/to.d.ts +0 -3
- package/cjs/adapter-js/code/toFns.d.ts +0 -3
- package/cjs/adapter-js/code/toFormat.d.ts +0 -3
- package/cjs/adapter-js/code/toSpa.d.ts +0 -3
- package/cjs/adapter-js/code/types.d.ts +0 -3
- package/cjs/adapter-next/code/index.d.ts +0 -3
- package/cjs/adapter-next/code/next-redirects.d.ts +0 -3
- package/cjs/adapter-next/code/next-rewrites.d.ts +0 -3
- package/cjs/adapter-next/code/useCurrentLocalisedPathnames.d.ts +0 -2
- package/cjs/adapter-next/code/useLocale.d.ts +0 -3
- package/cjs/adapter-next/code/useRouteId.d.ts +0 -2
- package/cjs/adapter-next/code/useTo.d.ts +0 -2
- package/cjs/adapter-next/code/useToSpa.d.ts +0 -2
- package/cjs/adapter-next/plugin-async.d.ts +0 -9
- package/cjs/adapter-next/plugin-legacy.d.ts +0 -22
- package/cjs/adapter-next/plugin-shared.d.ts +0 -13
- package/cjs/adapter-next/plugin.d.ts +0 -7
- package/cjs/adapter-next/redirects.d.ts +0 -4
- package/cjs/adapter-next/rewrites.d.ts +0 -4
- package/cjs/adapter-next/transformPathname.d.ts +0 -1
- package/cjs/adapter-next/webpackPluginI18n.d.ts +0 -7
- package/cjs/adapter-next-translate/code/DynamicNamespaces.d.ts +0 -2
- package/cjs/adapter-next-translate/code/T.d.ts +0 -2
- package/cjs/adapter-next-translate/code/TransText.d.ts +0 -2
- package/cjs/adapter-next-translate/code/getT.d.ts +0 -2
- package/cjs/adapter-next-translate/code/index.d.ts +0 -3
- package/cjs/adapter-next-translate/code/nextTranslateI18n.d.ts +0 -3
- package/cjs/adapter-next-translate/code/useT.d.ts +0 -2
- package/cjs/client/formatRoutePathname.d.ts +0 -4
- package/cjs/client/index.d.ts +0 -3
- package/cjs/client/interpolateTo.d.ts +0 -4
- package/cjs/client/routeHasDynamicPortion.d.ts +0 -2
- package/cjs/compiler/api.d.ts +0 -30
- package/cjs/compiler/code/data-routes.d.ts +0 -19
- package/cjs/compiler/code/data-translations.d.ts +0 -13
- package/cjs/compiler/code/data.d.ts +0 -33
- package/cjs/compiler/code/generate.d.ts +0 -14
- package/cjs/compiler/code/index.d.ts +0 -3
- package/cjs/compiler/code/tsCompile.d.ts +0 -2
- package/cjs/compiler/code/write.d.ts +0 -11
- package/cjs/compiler/config.d.ts +0 -12
- package/cjs/compiler/helpers.d.ts +0 -2
- package/cjs/compiler/input/data-local.d.ts +0 -4
- package/cjs/compiler/input/data-remote.d.ts +0 -7
- package/cjs/compiler/input/data.d.ts +0 -4
- package/cjs/compiler/input/index.d.ts +0 -4
- package/cjs/compiler/input/types.d.ts +0 -14
- package/cjs/compiler/input/write.d.ts +0 -8
- package/cjs/compiler/pluralisation.d.ts +0 -37
- package/cjs/compiler/summary/data.d.ts +0 -6
- package/cjs/compiler/summary/generate.d.ts +0 -4
- package/cjs/compiler/summary/index.d.ts +0 -3
- package/cjs/compiler/summary/write.d.ts +0 -10
- package/cjs/compiler/types.d.ts +0 -82
- package/cjs/compiler-sync.d.ts +0 -4
- package/cjs/compiler-worker.d.ts +0 -1
- package/cjs/compiler.d.ts +0 -2
- package/cjs/i18n/actions/helpers-git.js +0 -45
- package/cjs/i18n/actions/helpers-i18n.js +0 -27
- package/cjs/i18n/actions/i18n.js +0 -17
- package/cjs/i18n/adapter-js/code/config.cjs.js +0 -14
- package/cjs/i18n/adapter-js/code/config.js +0 -14
- package/cjs/i18n/adapter-js/code/defaultLocale.js +0 -7
- package/cjs/i18n/adapter-js/code/deriveLocalisedPathnames.js +0 -78
- package/cjs/i18n/adapter-js/code/index.js +0 -123
- package/cjs/i18n/adapter-js/code/isLocale.js +0 -9
- package/cjs/i18n/adapter-js/code/locales.js +0 -8
- package/cjs/i18n/adapter-js/code/pathnameToRouteId.js +0 -20
- package/cjs/i18n/adapter-js/code/routes.js +0 -11
- package/cjs/i18n/adapter-js/code/routesSlim.js +0 -11
- package/cjs/i18n/adapter-js/code/routesSpa.js +0 -11
- package/cjs/i18n/adapter-js/code/tFns.js +0 -34
- package/cjs/i18n/adapter-js/code/tInterpolateParams.js +0 -18
- package/cjs/i18n/adapter-js/code/tPluralise.js +0 -10
- package/cjs/i18n/adapter-js/code/to.js +0 -32
- package/cjs/i18n/adapter-js/code/toFns.js +0 -25
- package/cjs/i18n/adapter-js/code/toFormat.js +0 -56
- package/cjs/i18n/adapter-js/code/toSpa.js +0 -42
- package/cjs/i18n/adapter-js/code/types.js +0 -327
- package/cjs/i18n/adapter-next/code/index.js +0 -54
- package/cjs/i18n/adapter-next/code/next-redirects.js +0 -5
- package/cjs/i18n/adapter-next/code/next-rewrites.js +0 -5
- package/cjs/i18n/adapter-next/code/useCurrentLocalisedPathnames.js +0 -20
- package/cjs/i18n/adapter-next/code/useLocale.js +0 -8
- package/cjs/i18n/adapter-next/code/useRouteId.js +0 -10
- package/cjs/i18n/adapter-next/code/useTo.js +0 -26
- package/cjs/i18n/adapter-next/code/useToSpa.js +0 -34
- package/cjs/i18n/adapter-next/plugin-async.js +0 -11
- package/cjs/i18n/adapter-next/plugin-legacy.js +0 -187
- package/cjs/i18n/adapter-next/plugin-shared.js +0 -39
- package/cjs/i18n/adapter-next/plugin.js +0 -13
- package/cjs/i18n/adapter-next/redirects.js +0 -51
- package/cjs/i18n/adapter-next/rewrites.js +0 -50
- package/cjs/i18n/adapter-next/transformPathname.js +0 -3
- package/cjs/i18n/adapter-next/webpackPluginI18n.js +0 -11
- package/cjs/i18n/adapter-next-translate/code/DynamicNamespaces.js +0 -9
- package/cjs/i18n/adapter-next-translate/code/T.js +0 -31
- package/cjs/i18n/adapter-next-translate/code/TransText.js +0 -9
- package/cjs/i18n/adapter-next-translate/code/getT.js +0 -15
- package/cjs/i18n/adapter-next-translate/code/index.js +0 -49
- package/cjs/i18n/adapter-next-translate/code/nextTranslateI18n.js +0 -19
- package/cjs/i18n/adapter-next-translate/code/useT.js +0 -43
- package/cjs/i18n/client/formatRoutePathname.js +0 -5
- package/cjs/i18n/client/index.js +0 -3
- package/cjs/i18n/client/interpolateTo.js +0 -14
- package/cjs/i18n/client/routeHasDynamicPortion.js +0 -2
- package/cjs/i18n/compiler/api.js +0 -18
- package/cjs/i18n/compiler/code/data-routes.js +0 -99
- package/cjs/i18n/compiler/code/data-translations.js +0 -86
- package/cjs/i18n/compiler/code/data.js +0 -20
- package/cjs/i18n/compiler/code/generate.js +0 -46
- package/cjs/i18n/compiler/code/index.js +0 -2
- package/cjs/i18n/compiler/code/tsCompile.js +0 -27
- package/cjs/i18n/compiler/code/write.js +0 -39
- package/cjs/i18n/compiler/config.js +0 -13
- package/cjs/i18n/compiler/helpers.js +0 -14
- package/cjs/i18n/compiler/input/data-local.js +0 -60
- package/cjs/i18n/compiler/input/data-remote.js +0 -41
- package/cjs/i18n/compiler/input/data.js +0 -11
- package/cjs/i18n/compiler/input/index.js +0 -3
- package/cjs/i18n/compiler/input/types.js +0 -1
- package/cjs/i18n/compiler/input/write.js +0 -15
- package/cjs/i18n/compiler/pluralisation.js +0 -59
- package/cjs/i18n/compiler/summary/data.js +0 -28
- package/cjs/i18n/compiler/summary/generate.js +0 -27
- package/cjs/i18n/compiler/summary/index.js +0 -2
- package/cjs/i18n/compiler/summary/write.js +0 -18
- package/cjs/i18n/compiler/types.js +0 -1
- package/cjs/i18n/compiler-sync.js +0 -2
- package/cjs/i18n/compiler-worker.js +0 -3
- package/cjs/i18n/compiler.js +0 -1
- package/cjs/i18n/index.js +0 -2
- package/cjs/i18n/next.js +0 -3
- package/cjs/i18n/types.js +0 -1
- package/cjs/index.d.ts +0 -2
- package/cjs/next.d.ts +0 -3
- package/cjs/package.json +0 -34
- package/cjs/types.d.ts +0 -48
- package/client/formatRoutePathname.js +0 -5
- package/client/index.js +0 -3
- package/client/interpolateTo.js +0 -14
- package/client/routeHasDynamicPortion.js +0 -2
- package/compiler/api.js +0 -18
- package/compiler/code/data-routes.js +0 -99
- package/compiler/code/data-translations.js +0 -86
- package/compiler/code/data.js +0 -20
- package/compiler/code/generate.js +0 -46
- package/compiler/code/index.js +0 -2
- package/compiler/code/tsCompile.js +0 -27
- package/compiler/code/write.js +0 -39
- package/compiler/config.js +0 -13
- package/compiler/helpers.js +0 -14
- package/compiler/input/data-local.js +0 -60
- package/compiler/input/data-remote.js +0 -41
- package/compiler/input/data.js +0 -11
- package/compiler/input/index.js +0 -3
- package/compiler/input/types.js +0 -1
- package/compiler/input/write.js +0 -15
- package/compiler/pluralisation.js +0 -59
- package/compiler/summary/data.js +0 -28
- package/compiler/summary/generate.js +0 -27
- package/compiler/summary/index.js +0 -2
- package/compiler/summary/write.js +0 -18
- package/compiler/types.js +0 -1
- package/compiler-sync.js +0 -2
- package/compiler-worker.js +0 -3
- package/compiler.js +0 -1
- package/index.js +0 -2
- package/next.js +0 -3
- package/types.js +0 -1
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { arrayUniqueByProperties as e, normaliseUrlPathname as t } from "@koine/utils";
|
|
2
|
-
function n(e, t) {
|
|
3
|
-
let { [t]: n, ...l } = e;
|
|
4
|
-
return {
|
|
5
|
-
[t]: n,
|
|
6
|
-
...l
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
function l(e) {
|
|
10
|
-
let { pathname: t, template: n } = e, l = t.split("/").filter((e)=>!!e), i = n.split("/").filter((e)=>!!e), r = {};
|
|
11
|
-
return {
|
|
12
|
-
pathname: l.map((e)=>{
|
|
13
|
-
let t = e.endsWith("*"), n = (e = e.replace("*", "")).startsWith("{{") && e.endsWith("}}"), l = n ? e.match(/{{(.+)}}/)?.[1].trim() ?? "" : e.trim(), i = encodeURIComponent(l) + (t ? "*" : "");
|
|
14
|
-
return r[l] = {
|
|
15
|
-
isDynamic: n,
|
|
16
|
-
hasWildcard: t
|
|
17
|
-
}, n ? `:${i}` : i;
|
|
18
|
-
}).join("/"),
|
|
19
|
-
template: i.map((e)=>{
|
|
20
|
-
let t = e.startsWith("[") && e.endsWith("]"), n = t ? e.match(/\[(.+)\]/)?.[1].trim() ?? "" : e.trim(), l = r[n]?.hasWildcard, i = encodeURIComponent(n) + (l ? "*" : "");
|
|
21
|
-
return t ? `:${i}` : i;
|
|
22
|
-
}).join("/")
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function i(e = {}, t, n = "", l = "") {
|
|
26
|
-
let r = Object.keys(t).includes("[spa]");
|
|
27
|
-
for(let a in t){
|
|
28
|
-
let o = t[a], s = `${l}/${a}`;
|
|
29
|
-
"string" == typeof o ? (!r || r && [
|
|
30
|
-
"[spa]",
|
|
31
|
-
"index"
|
|
32
|
-
].includes(a)) && (e[s] = {
|
|
33
|
-
template: s,
|
|
34
|
-
pathname: o,
|
|
35
|
-
wildcard: o.includes("*")
|
|
36
|
-
}) : r || i(e, o, n, s);
|
|
37
|
-
}
|
|
38
|
-
return e;
|
|
39
|
-
}
|
|
40
|
-
function r(e) {
|
|
41
|
-
return e.replace(/\/index$/, "");
|
|
42
|
-
}
|
|
43
|
-
function a(e) {
|
|
44
|
-
let { localeSource: n, localeDestination: i, route: a, usePathnameAsSource: o, permanent: s } = e, { template: c, pathname: u } = l(a), f = n ? `${n}/` : "", p = r(`/${t(f + (o ? u : c))}`), h = i ? `${i}/` : "", m = `/${t(h + u)}`;
|
|
45
|
-
if (p !== m) return {
|
|
46
|
-
source: p,
|
|
47
|
-
destination: m,
|
|
48
|
-
permanent: !!s
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function o(e) {
|
|
52
|
-
let { localeSource: n, localeDestination: i, localeParam: a, route: o } = e, { pathname: s, template: c } = l(o), u = "";
|
|
53
|
-
n ? u = `${n}/` : a && (u = `:${a}/`);
|
|
54
|
-
let f = `/${t(u + s)}`, p = "";
|
|
55
|
-
i ? p = `${i}/` : a && (p = `:${a}/`);
|
|
56
|
-
let h = r(`/${t(p + c)}`);
|
|
57
|
-
if (f !== h) return {
|
|
58
|
-
source: f,
|
|
59
|
-
destination: h
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
export let withI18nLegacy = (t)=>{
|
|
63
|
-
let { i18nRoutes: l, ...s } = t;
|
|
64
|
-
if (!l) return s;
|
|
65
|
-
let { locales: c = [
|
|
66
|
-
"en"
|
|
67
|
-
], defaultLocale: u = "en", ...f } = t.i18n || {};
|
|
68
|
-
s.i18n = {
|
|
69
|
-
...f,
|
|
70
|
-
locales: c,
|
|
71
|
-
defaultLocale: u
|
|
72
|
-
};
|
|
73
|
-
let p = {
|
|
74
|
-
hideDefaultLocaleInUrl: !0,
|
|
75
|
-
localeParam: "",
|
|
76
|
-
...l,
|
|
77
|
-
locales: c,
|
|
78
|
-
defaultLocale: u
|
|
79
|
-
}, h = {
|
|
80
|
-
...s
|
|
81
|
-
};
|
|
82
|
-
if (p.routes) {
|
|
83
|
-
let { redirects: t, rewrites: l } = h;
|
|
84
|
-
h.redirects = async ()=>{
|
|
85
|
-
let l = function(t) {
|
|
86
|
-
let { routes: l, defaultLocale: o, hideDefaultLocaleInUrl: s, localeParam: c, permanent: u, debug: f } = t, p = n(l, o), h = [];
|
|
87
|
-
for(let e in p){
|
|
88
|
-
let t = i({}, l[e]);
|
|
89
|
-
for(let n in t){
|
|
90
|
-
let l = t[n];
|
|
91
|
-
if (l.pathname !== r(n)) {
|
|
92
|
-
let t = e === o && !s, n = e === o && s;
|
|
93
|
-
c ? t ? h.push(a({
|
|
94
|
-
localeDestination: e,
|
|
95
|
-
route: l,
|
|
96
|
-
permanent: u
|
|
97
|
-
})) : n ? h.push(a({
|
|
98
|
-
localeSource: e,
|
|
99
|
-
route: l,
|
|
100
|
-
permanent: u
|
|
101
|
-
})) : e !== o ? h.push(a({
|
|
102
|
-
localeSource: e,
|
|
103
|
-
localeDestination: e,
|
|
104
|
-
route: l,
|
|
105
|
-
permanent: u
|
|
106
|
-
})) : h.push(a({
|
|
107
|
-
route: l,
|
|
108
|
-
permanent: u
|
|
109
|
-
})) : t ? h.push(a({
|
|
110
|
-
localeDestination: e,
|
|
111
|
-
route: l,
|
|
112
|
-
permanent: u
|
|
113
|
-
})) : e !== o ? h.push(a({
|
|
114
|
-
localeSource: e,
|
|
115
|
-
localeDestination: e,
|
|
116
|
-
route: l,
|
|
117
|
-
permanent: u
|
|
118
|
-
})) : h.push(a({
|
|
119
|
-
route: l,
|
|
120
|
-
permanent: u
|
|
121
|
-
}));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
let m = e(h.filter(Boolean), [
|
|
126
|
-
"source",
|
|
127
|
-
"destination"
|
|
128
|
-
]).map((e)=>c ? e : {
|
|
129
|
-
...e,
|
|
130
|
-
locale: !1
|
|
131
|
-
});
|
|
132
|
-
return f && console.info("[@koine/next/plugin-legacy:generateRedirects]", m), m;
|
|
133
|
-
}(p);
|
|
134
|
-
return t ? [
|
|
135
|
-
...l,
|
|
136
|
-
...await t()
|
|
137
|
-
] : l;
|
|
138
|
-
}, h.rewrites = async ()=>{
|
|
139
|
-
let t = function(t) {
|
|
140
|
-
let { routes: l, defaultLocale: a, hideDefaultLocaleInUrl: s, localeParam: c, debug: u } = t, f = n(l, a), p = [];
|
|
141
|
-
for(let e in f){
|
|
142
|
-
let t = i({}, l[e]);
|
|
143
|
-
for(let n in t){
|
|
144
|
-
let l = t[n], i = e === a && !s, u = e === a && s;
|
|
145
|
-
c ? u ? p.push(o({
|
|
146
|
-
localeDestination: e,
|
|
147
|
-
route: l
|
|
148
|
-
})) : p.push(o({
|
|
149
|
-
localeParam: c,
|
|
150
|
-
route: l
|
|
151
|
-
})) : l.pathname !== r(n) && (e !== a || i ? p.push(o({
|
|
152
|
-
localeSource: e,
|
|
153
|
-
route: l
|
|
154
|
-
})) : p.push(o({
|
|
155
|
-
route: l
|
|
156
|
-
})));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
let h = e(p.filter(Boolean), [
|
|
160
|
-
"source",
|
|
161
|
-
"destination"
|
|
162
|
-
]);
|
|
163
|
-
return u && console.info("[@koine/next/plugin-legacy:generateRewrites]", h), h;
|
|
164
|
-
}(p);
|
|
165
|
-
if (l) {
|
|
166
|
-
let e = await l();
|
|
167
|
-
return Array.isArray(e) ? {
|
|
168
|
-
beforeFiles: t,
|
|
169
|
-
afterFiles: e,
|
|
170
|
-
fallback: []
|
|
171
|
-
} : {
|
|
172
|
-
...e,
|
|
173
|
-
beforeFiles: [
|
|
174
|
-
...t,
|
|
175
|
-
...e.beforeFiles || []
|
|
176
|
-
]
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
beforeFiles: t,
|
|
181
|
-
afterFiles: [],
|
|
182
|
-
fallback: []
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
return h;
|
|
187
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ContextReplacementPlugin as e } from "webpack";
|
|
2
|
-
import { generateRedirects as t } from "./redirects";
|
|
3
|
-
import { generateRewrites as r } from "./rewrites";
|
|
4
|
-
export let tweakNextConfig = (t, r)=>{
|
|
5
|
-
let { defaultLocale: o, locales: i, appRouterLocaleParamName: l } = t;
|
|
6
|
-
return l ? delete r.i18n : (r.i18n = r.i18n || {
|
|
7
|
-
locales: i,
|
|
8
|
-
defaultLocale: o
|
|
9
|
-
}, r.i18n.locales = i, r.i18n.defaultLocale = o), r.webpack = (t)=>(t.plugins.push(new e(/^date-fns[/\\]locale$/, RegExp(`\\.[/\\\\](${i.join("|")})[/\\\\]index\\.js$`))), t), r;
|
|
10
|
-
};
|
|
11
|
-
export let getRedirects = async (e, { appRouterLocaleParamName: r, permanentRedirects: o }, i)=>{
|
|
12
|
-
let l = t(i.config, i.code.routes.byId, i.code.options.routes, r, o);
|
|
13
|
-
return e ? [
|
|
14
|
-
...l,
|
|
15
|
-
...await e()
|
|
16
|
-
] : l;
|
|
17
|
-
};
|
|
18
|
-
export let getRewrites = async (e, { appRouterLocaleParamName: t }, o)=>{
|
|
19
|
-
let i = r(o.config, o.code.routes.byId, o.code.options.routes, t);
|
|
20
|
-
if (e) {
|
|
21
|
-
let t = await e();
|
|
22
|
-
return Array.isArray(t) ? {
|
|
23
|
-
beforeFiles: i,
|
|
24
|
-
afterFiles: t,
|
|
25
|
-
fallback: []
|
|
26
|
-
} : {
|
|
27
|
-
...t,
|
|
28
|
-
beforeFiles: [
|
|
29
|
-
...i,
|
|
30
|
-
...t.beforeFiles || []
|
|
31
|
-
]
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
beforeFiles: i,
|
|
36
|
-
afterFiles: [],
|
|
37
|
-
fallback: []
|
|
38
|
-
};
|
|
39
|
-
};
|
package/adapter-next/plugin.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createRequire as r } from "node:module";
|
|
2
|
-
import { i18nCompilerSync as t } from "../compiler-sync";
|
|
3
|
-
import { getRedirects as e, getRewrites as i, tweakNextConfig as o } from "./plugin-shared";
|
|
4
|
-
let n = r(import.meta.url);
|
|
5
|
-
export let withI18n = (r = {})=>{
|
|
6
|
-
let { i18nCompiler: l, redirects: m, rewrites: p, ...a } = r, c = a;
|
|
7
|
-
if (!l) return c;
|
|
8
|
-
let d = t(l);
|
|
9
|
-
if ((c = o(d.config, c)).redirects = ()=>e(m, l, d), c.rewrites = ()=>i(p, l, d), "next-translate" === l.code.adapter) try {
|
|
10
|
-
c = n("next-translate-plugin")(c);
|
|
11
|
-
} catch (r) {}
|
|
12
|
-
return c;
|
|
13
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { arrayUniqueByProperties as e, escapeRegExp as o } from "@koine/utils";
|
|
2
|
-
import { formatRoutePathname as t } from "../client";
|
|
3
|
-
import { transformPathname as l } from "./transformPathname";
|
|
4
|
-
function r(e) {
|
|
5
|
-
let { localeSource: o, localeDestination: l, template: r, pathname: i, permanent: a } = e, n = t((o ? `${o}/` : "") + r), c = t((l ? `${l}/` : "") + i);
|
|
6
|
-
if (n !== c) return {
|
|
7
|
-
source: n,
|
|
8
|
-
destination: c,
|
|
9
|
-
permanent: !!a
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export let generateRedirects = (t, i, a, n = "", c = !1)=>{
|
|
13
|
-
let { defaultLocale: s, hideDefaultLocaleInUrl: p } = t, u = RegExp(o(a.tokens.idDelimiter), "g"), m = [];
|
|
14
|
-
for(let e in i){
|
|
15
|
-
let o = i[e], t = i[e].pathnames;
|
|
16
|
-
for(let i in t){
|
|
17
|
-
let a = t[i], f = l(e.replace(u, "/"), o.wildcard), d = l(a, o.wildcard);
|
|
18
|
-
if (o.inWildcard) break;
|
|
19
|
-
let h = i === s, D = h && !p, g = h && p, k = {
|
|
20
|
-
template: f,
|
|
21
|
-
pathname: d,
|
|
22
|
-
permanent: c
|
|
23
|
-
};
|
|
24
|
-
n ? D ? m.push(r({
|
|
25
|
-
...k,
|
|
26
|
-
localeDestination: i
|
|
27
|
-
})) : g ? m.push(r({
|
|
28
|
-
...k,
|
|
29
|
-
localeSource: i
|
|
30
|
-
})) : h ? m.push(r(k)) : m.push(r({
|
|
31
|
-
...k,
|
|
32
|
-
localeSource: i,
|
|
33
|
-
localeDestination: i
|
|
34
|
-
})) : d !== f && (D ? m.push(r({
|
|
35
|
-
...k,
|
|
36
|
-
localeDestination: i
|
|
37
|
-
})) : h ? m.push(r(k)) : m.push(r({
|
|
38
|
-
...k,
|
|
39
|
-
localeSource: i,
|
|
40
|
-
localeDestination: i
|
|
41
|
-
})));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return e(m.filter(Boolean), [
|
|
45
|
-
"source",
|
|
46
|
-
"destination"
|
|
47
|
-
]).sort((e, o)=>e.source.localeCompare(o.source)).map((e)=>n ? e : {
|
|
48
|
-
...e,
|
|
49
|
-
locale: !1
|
|
50
|
-
});
|
|
51
|
-
};
|
package/adapter-next/rewrites.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { arrayUniqueByProperties as e, escapeRegExp as t } from "@koine/utils";
|
|
2
|
-
import { formatRoutePathname as l } from "../client";
|
|
3
|
-
import { transformPathname as r } from "./transformPathname";
|
|
4
|
-
function o(e) {
|
|
5
|
-
let { localeSource: t, localeDestination: r, template: o, pathname: i } = e, a = "";
|
|
6
|
-
t && (a = `/${t}`);
|
|
7
|
-
let n = l(a + i), c = "";
|
|
8
|
-
r && (c = `/${r}`);
|
|
9
|
-
let s = l(c + o);
|
|
10
|
-
if (n !== s) return {
|
|
11
|
-
source: n,
|
|
12
|
-
destination: s
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
let i = (e, t = "", l, r, i, a)=>{
|
|
16
|
-
let { defaultLocale: n, hideDefaultLocaleInUrl: c } = e, s = l === n && c, u = {
|
|
17
|
-
config: e,
|
|
18
|
-
template: r,
|
|
19
|
-
pathname: i
|
|
20
|
-
};
|
|
21
|
-
t ? s ? a.push(o({
|
|
22
|
-
...u,
|
|
23
|
-
localeDestination: l
|
|
24
|
-
})) : a.push(o({
|
|
25
|
-
...u,
|
|
26
|
-
localeSource: l,
|
|
27
|
-
localeDestination: l
|
|
28
|
-
})) : i !== r && (s ? a.push(o(u)) : a.push({
|
|
29
|
-
...o({
|
|
30
|
-
...u,
|
|
31
|
-
localeSource: l
|
|
32
|
-
}),
|
|
33
|
-
locale: !1
|
|
34
|
-
}));
|
|
35
|
-
};
|
|
36
|
-
export let generateRewrites = (l, o, a, n = "")=>{
|
|
37
|
-
let c = RegExp(t(a.tokens.idDelimiter), "g"), s = [];
|
|
38
|
-
for(let e in o){
|
|
39
|
-
let t = o[e], a = o[e].pathnames;
|
|
40
|
-
for(let o in a){
|
|
41
|
-
let u = a[o], p = e.replace(c, "/");
|
|
42
|
-
if (t.inWildcard) break;
|
|
43
|
-
i(l, n, o, r(p), r(u), s), t.wildcard && i(l, n, o, r(p, t.wildcard), r(u, t.wildcard), s);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return e(s.filter(Boolean), [
|
|
47
|
-
"source",
|
|
48
|
-
"destination"
|
|
49
|
-
]).sort((e, t)=>e.source.localeCompare(t.source));
|
|
50
|
-
};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export function transformPathname(e, t) {
|
|
2
|
-
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*" : "");
|
|
3
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { i18nCompiler as o } from "../compiler";
|
|
2
|
-
export class I18nWebpackPlugin {
|
|
3
|
-
constructor(o){
|
|
4
|
-
this.opts = o;
|
|
5
|
-
}
|
|
6
|
-
apply(s) {
|
|
7
|
-
s.hooks && s.hooks.beforeCompile.tapPromise("I18nWebpackPlugin", async (s, p)=>{
|
|
8
|
-
await o(this.opts), console.log("done async!!!!!!!!!!!!!!!!!!!!!!!", this.opts), p();
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
"use client";
|
|
3
|
-
|
|
4
|
-
import type { TransProps } from "next-translate";
|
|
5
|
-
import Trans from "next-translate/Trans";
|
|
6
|
-
import type { I18n } from "./types";
|
|
7
|
-
|
|
8
|
-
export type TProps<
|
|
9
|
-
TNamespace extends I18n.TranslateNamespace | undefined = undefined,
|
|
10
|
-
> =
|
|
11
|
-
| (Omit<TransProps, "i18nKey" | "ns"> & {
|
|
12
|
-
i18nKey: I18n.TranslationsAllPaths;
|
|
13
|
-
})
|
|
14
|
-
| (Omit<TransProps, "i18nKey" | "ns"> & {
|
|
15
|
-
ns: TNamespace;
|
|
16
|
-
i18nKey: I18n.TranslationsPaths<TNamespace>;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const TypedT = <
|
|
20
|
-
TNamespace extends I18n.TranslateNamespace | undefined = undefined,
|
|
21
|
-
>(
|
|
22
|
-
props: TProps<TNamespace>,
|
|
23
|
-
) =>
|
|
24
|
-
(<Trans {...(props as TransProps)} />) as React.ReactElement<
|
|
25
|
-
TProps<TNamespace>
|
|
26
|
-
>;
|
|
27
|
-
|
|
28
|
-
export const T = Trans as typeof TypedT;
|
|
29
|
-
|
|
30
|
-
export default T;
|
|
31
|
-
`);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
import _getT from "next-translate/getT";
|
|
3
|
-
import type { I18n } from "./types";
|
|
4
|
-
|
|
5
|
-
export type GetT = <
|
|
6
|
-
TNamespace extends I18n.TranslateNamespace | undefined = undefined,
|
|
7
|
-
>(
|
|
8
|
-
locale?: I18n.Locale,
|
|
9
|
-
namespace?: TNamespace,
|
|
10
|
-
) => Promise<I18n.Translate<TNamespace>>;
|
|
11
|
-
|
|
12
|
-
export const getT = _getT as GetT;
|
|
13
|
-
|
|
14
|
-
export default getT;
|
|
15
|
-
`);
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import e from "./DynamicNamespaces";
|
|
2
|
-
import n from "./T";
|
|
3
|
-
import t from "./TransText";
|
|
4
|
-
import m from "./getT";
|
|
5
|
-
import s from "./nextTranslateI18n";
|
|
6
|
-
import a from "./useT";
|
|
7
|
-
export default (()=>({
|
|
8
|
-
dependsOn: [
|
|
9
|
-
"next"
|
|
10
|
-
],
|
|
11
|
-
needsTranslationsFiles: !0,
|
|
12
|
-
files: [
|
|
13
|
-
{
|
|
14
|
-
name: "DynamicNamespaces",
|
|
15
|
-
fn: e,
|
|
16
|
-
ext: "tsx",
|
|
17
|
-
index: !0
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
name: "getT",
|
|
21
|
-
fn: m,
|
|
22
|
-
ext: "ts",
|
|
23
|
-
index: !0
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "nextTranslateI18n",
|
|
27
|
-
fn: s,
|
|
28
|
-
ext: "js"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: "T",
|
|
32
|
-
fn: n,
|
|
33
|
-
ext: "tsx",
|
|
34
|
-
index: !0
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: "TransText",
|
|
38
|
-
fn: t,
|
|
39
|
-
ext: "tsx",
|
|
40
|
-
index: !0
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "useT",
|
|
44
|
-
fn: a,
|
|
45
|
-
ext: "ts",
|
|
46
|
-
index: !0
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}));
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default (({ config: a })=>`
|
|
2
|
-
/**
|
|
3
|
-
* Get 'next-translate' configuration
|
|
4
|
-
*
|
|
5
|
-
* @see https://github.com/vinissimus/next-translate#how-are-translations-loaded
|
|
6
|
-
*
|
|
7
|
-
* @param {Omit<Partial<import("next-translate").I18nConfig>, "pages"> & { pages: Record<string, import("./types").I18n.TranslateNamespace[]> }} config
|
|
8
|
-
*/
|
|
9
|
-
module.exports = (config = { pages: {} }) => {
|
|
10
|
-
return {
|
|
11
|
-
locales: [${a.locales.map((a)=>`"${a}"`).join(", ")}],
|
|
12
|
-
defaultLocale: "${a.defaultLocale}",
|
|
13
|
-
logBuild: false,
|
|
14
|
-
// logger: () => void 0,
|
|
15
|
-
loadLocaleFrom: (locale, namespace) => import(\`./translations/\${locale}/\${namespace}.json\`).then((m) => m.default),
|
|
16
|
-
...config,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
`);
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
"use client";
|
|
3
|
-
|
|
4
|
-
import { useMemo } from "react";
|
|
5
|
-
import useTranslation from "next-translate/useTranslation";
|
|
6
|
-
import type { I18n } from "./types";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Wrap next-translate useTranslations for type safety and adds TranslationShortcut
|
|
10
|
-
* as second/thir argument.
|
|
11
|
-
*
|
|
12
|
-
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
13
|
-
*
|
|
14
|
-
* About the typescript support for translation strings see:
|
|
15
|
-
* - https://github.com/vinissimus/next-translate/issues/721
|
|
16
|
-
*/
|
|
17
|
-
export const useT = <TNamespace extends I18n.TranslateNamespace>(namespace: TNamespace) => {
|
|
18
|
-
const t = useTranslation().t;
|
|
19
|
-
const tMemoized = useMemo(
|
|
20
|
-
() =>
|
|
21
|
-
function <
|
|
22
|
-
TPath extends I18n.TranslationsPaths<I18n.TranslationsDictionary[TNamespace]>,
|
|
23
|
-
TReturn = I18n.TranslationAtPathFromNamespace<TNamespace, TPath>,
|
|
24
|
-
>(s: TPath, q?: I18n.TranslationQuery, o?: I18n.TranslationOptions): TReturn {
|
|
25
|
-
return t(
|
|
26
|
-
(namespace ? namespace + ":" + s : s) as string,
|
|
27
|
-
q === "obj" || q === "" ? null : q,
|
|
28
|
-
q === "obj" || o === "obj"
|
|
29
|
-
? { returnObjects: true }
|
|
30
|
-
: q === "" || o === ""
|
|
31
|
-
? { fallback: "" }
|
|
32
|
-
: o,
|
|
33
|
-
) as TReturn;
|
|
34
|
-
// ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<I18n.TranslationQuery, I18n.TranslationOptions> : TReturn;
|
|
35
|
-
// );
|
|
36
|
-
},
|
|
37
|
-
[t, namespace],
|
|
38
|
-
);
|
|
39
|
-
return tMemoized;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default useT;
|
|
43
|
-
`);
|