@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
package/adapter-js/code/types.js
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import { forin as e, isArray as t, isBoolean as a, isObject as s, isString as n } from "@koine/utils";
|
|
2
|
-
import { dataParamsToTsInterfaceBody as o } from "../../compiler/helpers";
|
|
3
|
-
import { hasOnlyPluralKeys as i, hasPlurals as r, pickNonPluralValue as l, transformKeysForPlurals as p } from "../../compiler/pluralisation";
|
|
4
|
-
let c = (e, a)=>!t(a) && s(a) && r(a) ? i(a) ? `"${e}": string;` : `"${e}": ${h(l(a))}` : `"${e}": ${h(a)}`, h = (e)=>{
|
|
5
|
-
let o = "", i = "";
|
|
6
|
-
if (a(e) ? i = "boolean" : n(e) && (i = "string"), i) o += i + ";";
|
|
7
|
-
else if (e) {
|
|
8
|
-
if (t(e)) {
|
|
9
|
-
let t = e[0];
|
|
10
|
-
o += `${h(t)}[];`;
|
|
11
|
-
} else if (s(e)) {
|
|
12
|
-
o += "{";
|
|
13
|
-
let t = p(Object.keys(e));
|
|
14
|
-
for(let a = 0; a < t.length; a++){
|
|
15
|
-
let s = t[a], n = e[s] || "";
|
|
16
|
-
o += c(s, n);
|
|
17
|
-
}
|
|
18
|
-
o += "};";
|
|
19
|
-
}
|
|
20
|
-
} else o += "";
|
|
21
|
-
return (o = o.replace(/;\[\];/g, "[];")).replace(/;+/g, ";");
|
|
22
|
-
}, d = (e, t)=>{
|
|
23
|
-
let { translationFiles: a } = t, { defaultLocale: s } = e, n = a.filter((e)=>e.locale === s), o = [];
|
|
24
|
-
for(let e = 0; e < n.length; e++){
|
|
25
|
-
let { path: t, data: a } = n[e], s = t.replace(".json", "");
|
|
26
|
-
o.push(`"${s}": ${h(a)}`);
|
|
27
|
-
}
|
|
28
|
-
return o.sort();
|
|
29
|
-
}, u = (t)=>{
|
|
30
|
-
let a = [];
|
|
31
|
-
return e(t.byId, (e, { params: t })=>{
|
|
32
|
-
t && a.push(`"${e}": { ${o(t)} };`);
|
|
33
|
-
}), a;
|
|
34
|
-
}, T = (e)=>e.sort().map((e)=>`"${e}"`).join(" | "), y = (e, t)=>T(Object.keys(e.byId).filter((a)=>t(a, e.byId[a]))), m = (e)=>Object.keys(e.byId).reduce((t, a)=>{
|
|
35
|
-
if (e.byId[a].inWildcard) for(let s = 0; s < e.wildcardIds.length; s++){
|
|
36
|
-
let n = e.wildcardIds[s];
|
|
37
|
-
a.startsWith(n) && (t[n] = t[n] || [], t[n].push(a));
|
|
38
|
-
}
|
|
39
|
-
return t;
|
|
40
|
-
}, {}), f = (e, t, a)=>{
|
|
41
|
-
let s = m(t), n = [];
|
|
42
|
-
for(let o in s){
|
|
43
|
-
let i = s[o].map((e)=>e.split(o)[1].slice(1)), r = t.byId[o].pathnames[e.defaultLocale], l = [];
|
|
44
|
-
for(let s = 0; s < i.length; s++){
|
|
45
|
-
let n = i[s], p = `${o}${a.routes.tokens.idDelimiter}${n}`, c = t.byId[p].pathnames[e.defaultLocale].split(r)[1];
|
|
46
|
-
l.push(`"${n}": "${c}";`);
|
|
47
|
-
}
|
|
48
|
-
n.push(`"${o}": { ${l.join(" ")} }`);
|
|
49
|
-
}
|
|
50
|
-
return n;
|
|
51
|
-
}, b = (e, t)=>{
|
|
52
|
-
let a = [];
|
|
53
|
-
for(let s in t.byId){
|
|
54
|
-
let n = t.byId[s];
|
|
55
|
-
a.push(`"${n.id}": "${n.pathnames[e.defaultLocale]}";`);
|
|
56
|
-
}
|
|
57
|
-
return a;
|
|
58
|
-
};
|
|
59
|
-
export default (({ config: e, input: t, routes: a, options: s })=>{
|
|
60
|
-
let n = y(a, (e, { params: t })=>!t), o = y(a, (e, { params: t })=>!!t), { idDelimiter: i } = s.routes.tokens;
|
|
61
|
-
return `
|
|
62
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
63
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
64
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
65
|
-
import type { Split } from "@koine/utils";
|
|
66
|
-
import type { I18nUtils } from "@koine/i18n";
|
|
67
|
-
|
|
68
|
-
export namespace I18n {
|
|
69
|
-
/**
|
|
70
|
-
* Any of the available locale code
|
|
71
|
-
*/
|
|
72
|
-
export type Locale = ${e.locales.map((e)=>`"${e}"`).join(" | ")};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Utility to map values by all available locales
|
|
76
|
-
*
|
|
77
|
-
* @usecase I need to map zendesk URLs to my project's locales
|
|
78
|
-
*/
|
|
79
|
-
export type LocalesMap<T = any> = Record<Locale, T>;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Any of the available route id
|
|
83
|
-
*/
|
|
84
|
-
export type RouteId = RouteIdStatic | RouteIdDynamic;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* The static routes available ids
|
|
88
|
-
*/
|
|
89
|
-
export type RouteIdStatic = ${n};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* The dynamic routes available ids
|
|
93
|
-
*/
|
|
94
|
-
export type RouteIdDynamic = ${o};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* SPA routes ids map
|
|
98
|
-
*/
|
|
99
|
-
/**
|
|
100
|
-
* Map every SPA path divided by their roots to their actual pathname value for the default locale
|
|
101
|
-
*/
|
|
102
|
-
export type RouteSpa = {
|
|
103
|
-
${f(e, a, s).join("\n ")}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Map every route id to its actual pathanem value for the default locale
|
|
108
|
-
*/
|
|
109
|
-
export type RoutePathnames = {
|
|
110
|
-
${b(e, a).join("\n ")}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Route dynamic params dictionary for each dynamic route id
|
|
115
|
-
*/
|
|
116
|
-
export type RouteParams = {
|
|
117
|
-
${u(a).join("\n ")}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Utility to join two route ids
|
|
122
|
-
*/
|
|
123
|
-
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${i}\${Tail}\` extends RouteId ? \`\${Root}${i}\${Tail}\` : never;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Extract all children routes that starts with the given string
|
|
127
|
-
*
|
|
128
|
-
* This is useful to get the subroutes of an application area, e.g. all subroutes
|
|
129
|
-
* of a dashboard, using it with: \` type DashboardRoutes = RoutesChildrenOf<"dashboard">;\`
|
|
130
|
-
*/
|
|
131
|
-
export type RoutesChildrenOf<
|
|
132
|
-
TStarts extends string,
|
|
133
|
-
T extends string = RouteId,
|
|
134
|
-
> = T extends \`\${TStarts}.\${infer First}\` ? \`\${TStarts}.\${First}\` : never;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* The types extracted from the translations JSON files, this is a little
|
|
138
|
-
* more sophisticated than the type result of \`typeof "./en/messages.json"\`
|
|
139
|
-
*/
|
|
140
|
-
export type TranslationsDictionary = {
|
|
141
|
-
${d(e, t).join("\n ")}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Any of the available translations namespaces
|
|
146
|
-
*/
|
|
147
|
-
export type TranslateNamespace = Extract<keyof TranslationsDictionary, string>;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Translation **value** found at a specific _path_ in the given _namespace_
|
|
151
|
-
*
|
|
152
|
-
* \`TPath\` can be any of all possible paths:
|
|
153
|
-
* - \`myKey\` sub dictionaries within a namespace
|
|
154
|
-
* - \`myKey.nested\` whatever nested level of nesting within a namespace
|
|
155
|
-
*/
|
|
156
|
-
export type TranslationAtPathFromNamespace<
|
|
157
|
-
TNamespace extends TranslateNamespace,
|
|
158
|
-
TPath extends TranslationsPaths<TranslationsDictionary[TNamespace]>,
|
|
159
|
-
> = TNamespace extends TranslateNamespace
|
|
160
|
-
? TPath extends string // TranslationsPaths<TranslationsDictionary[TNamespace]>
|
|
161
|
-
? I18nUtils.Get<TranslationsDictionary[TNamespace], TPath>
|
|
162
|
-
: TranslationsDictionary[TNamespace]
|
|
163
|
-
: never;
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* The generic type passed and to use with {@link TranslationAtPath} when you
|
|
167
|
-
* want to build a type extending that
|
|
168
|
-
*/
|
|
169
|
-
export type TranslationAtPathGeneric =
|
|
170
|
-
| TranslateNamespace
|
|
171
|
-
| TranslationsAllPaths;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Translation **value** found at a _path_
|
|
175
|
-
*
|
|
176
|
-
* \`TPath\` can be any of all possible paths begininng with a namespace:
|
|
177
|
-
* - \`namespace\` only a namespace
|
|
178
|
-
* - \`namespace:myKey\` sub dictionaries within a namespace
|
|
179
|
-
* - \`namespace:myKey.nested\` whatever nested level of nesting
|
|
180
|
-
*/
|
|
181
|
-
export type TranslationAtPath<TPath extends TranslationAtPathGeneric> =
|
|
182
|
-
TPath extends TranslateNamespace
|
|
183
|
-
? TranslationsDictionary[TPath]
|
|
184
|
-
: TPath extends \`\${infer Namespace}:\${infer Path}\`
|
|
185
|
-
? Namespace extends TranslateNamespace
|
|
186
|
-
? I18nUtils.Get<TranslationsDictionary[Namespace], Path>
|
|
187
|
-
: never
|
|
188
|
-
: never;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* All translations paths from the given _path_
|
|
192
|
-
*
|
|
193
|
-
* \`TPath\` can be any of all possible paths begininng with a namespace:
|
|
194
|
-
* - \`namespace\` only a namespace
|
|
195
|
-
* - \`namespace:myKey\` sub dictionaries within a namespace
|
|
196
|
-
* - \`namespace:myKey.nested\` whatever nested level of nesting
|
|
197
|
-
*/
|
|
198
|
-
export type TranslationsPathsFrom<TPath extends TranslationAtPathGeneric> =
|
|
199
|
-
TPath extends TranslateNamespace
|
|
200
|
-
? TranslationsPaths<TranslationsDictionary[TPath]>
|
|
201
|
-
: TPath extends \`\${infer Namespace}:\${infer Path}\`
|
|
202
|
-
? Namespace extends TranslateNamespace
|
|
203
|
-
? I18nUtils.Get<TranslationsDictionary[Namespace], Path> extends object
|
|
204
|
-
? TranslationsPaths<I18nUtils.Get<TranslationsDictionary[Namespace], Path>>
|
|
205
|
-
: TranslationsPaths<TranslationsDictionary[Namespace]>
|
|
206
|
-
: never
|
|
207
|
-
: never;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* All translations _paths_ of the given one, e.g. if \`TPath\` would be
|
|
211
|
-
* \`"dashboard.users.[id].edit"\` the generated type would be the union
|
|
212
|
-
* \`"dashboard.users.[id]" | "dashboard.users" | "dashboard"\`.
|
|
213
|
-
*/
|
|
214
|
-
export type TranslationsPathsAncestors<
|
|
215
|
-
TPath extends string,
|
|
216
|
-
TSeparator extends string = ".",
|
|
217
|
-
> = I18nUtils.BuildRecursiveJoin<Split<TPath, TSeparator>, TSeparator>;
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Recursive mapped type to extract all usable string paths from a translation
|
|
221
|
-
* definition object (usually from a JSON file).
|
|
222
|
-
*/
|
|
223
|
-
export type TranslationsPaths<T, TAsObj extends boolean = true> = I18nUtils.Paths<T, TAsObj>;
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Recursive mapped type of all usable string paths from the whole translations
|
|
227
|
-
* dictionary.
|
|
228
|
-
*/
|
|
229
|
-
export type TranslationsAllPaths = I18nUtils.AllPaths<TranslationsDictionary>;
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Unlike in \`next-translate\` we allow passing some predefined arguments as
|
|
233
|
-
* shortcuts for common use cases:
|
|
234
|
-
* - \`"obj"\` as a shortcut for \`{ returnObjects: true }\`
|
|
235
|
-
* - \`""\` as a shortcut for \`{ fallback: "" }\`
|
|
236
|
-
*
|
|
237
|
-
*/
|
|
238
|
-
export type TranslationShortcut = "obj" | "";
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Query object to populate the returned translated string interpolating data
|
|
242
|
-
* or a TranslationShortcut.
|
|
243
|
-
*
|
|
244
|
-
* NOTE: when using a shortcut passing TranslationOptions to \`t()\` is not supported
|
|
245
|
-
* TODO: type safe this behaviour of the third argument (options).
|
|
246
|
-
*/
|
|
247
|
-
export type TranslationQuery =
|
|
248
|
-
| undefined
|
|
249
|
-
| null
|
|
250
|
-
| TranslationShortcut
|
|
251
|
-
| {
|
|
252
|
-
[key: string]: string | number | boolean;
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Opions of the translate function or a TranslationShortcut.
|
|
257
|
-
*
|
|
258
|
-
* NOTE: when using a shortcut passing TranslationOptions to \`t()\` is not supported
|
|
259
|
-
* TODO: type safe this behaviour of the third argument (options).
|
|
260
|
-
*/
|
|
261
|
-
export type TranslationOptions =
|
|
262
|
-
| undefined
|
|
263
|
-
| TranslationShortcut
|
|
264
|
-
| {
|
|
265
|
-
returnObjects?: boolean;
|
|
266
|
-
fallback?: string | string[];
|
|
267
|
-
default?: string;
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Translate function which optionally accept a namespace as first argument
|
|
272
|
-
*/
|
|
273
|
-
export type Translate<
|
|
274
|
-
TNamespace extends TranslateNamespace | undefined = TranslateNamespace,
|
|
275
|
-
> = TNamespace extends TranslateNamespace
|
|
276
|
-
? TranslateNamespaced<TNamespace>
|
|
277
|
-
: TranslateDefault;
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Translate function **without** namespace, it allows to select any of the all
|
|
281
|
-
* available strings in _all_ namespaces.
|
|
282
|
-
*/
|
|
283
|
-
export type TranslateDefault = <
|
|
284
|
-
TPath extends TranslationsAllPaths,
|
|
285
|
-
TReturn = TranslationAtPath<TPath>,
|
|
286
|
-
>(
|
|
287
|
-
s: TPath,
|
|
288
|
-
q?: TranslationQuery,
|
|
289
|
-
o?: TranslationOptions,
|
|
290
|
-
) => TReturn;
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Translate function **with** namespace, it allows to select all available
|
|
294
|
-
* strings _only_ in the given namespace.
|
|
295
|
-
*/
|
|
296
|
-
export type TranslateNamespaced<TNamespace extends TranslateNamespace> = <
|
|
297
|
-
TPath extends TranslationsPaths<TranslationsDictionary[TNamespace]>,
|
|
298
|
-
TReturn = TranslationAtPathFromNamespace<TNamespace, TPath>,
|
|
299
|
-
>(
|
|
300
|
-
s: TPath,
|
|
301
|
-
q?: TranslationQuery,
|
|
302
|
-
o?: TranslationOptions,
|
|
303
|
-
) => TReturn;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Translate function _loose_ type, to use only in implementations that uses
|
|
307
|
-
* the \`t\` function indirectly without needng knowledge of the string it needs
|
|
308
|
-
* to output.
|
|
309
|
-
*/
|
|
310
|
-
export type TranslateLoose<TReturn = string> = (
|
|
311
|
-
s?: any,
|
|
312
|
-
q?: TranslationQuery,
|
|
313
|
-
o?: TranslationOptions,
|
|
314
|
-
) => TReturn;
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Translate function _loosest_ type it allows to return string or object or array
|
|
318
|
-
* or whatever basically.
|
|
319
|
-
*/
|
|
320
|
-
export type TranslateLoosest<TReturn = any> = (
|
|
321
|
-
s?: any,
|
|
322
|
-
q?: TranslationQuery,
|
|
323
|
-
o?: TranslationOptions,
|
|
324
|
-
) => TReturn;
|
|
325
|
-
}
|
|
326
|
-
`;
|
|
327
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import e from "./next-redirects";
|
|
2
|
-
import t from "./next-rewrites";
|
|
3
|
-
import n from "./useCurrentLocalisedPathnames";
|
|
4
|
-
import s from "./useLocale";
|
|
5
|
-
import r from "./useRouteId";
|
|
6
|
-
import o from "./useTo";
|
|
7
|
-
import m from "./useToSpa";
|
|
8
|
-
export default (()=>({
|
|
9
|
-
dependsOn: [
|
|
10
|
-
"js"
|
|
11
|
-
],
|
|
12
|
-
files: [
|
|
13
|
-
{
|
|
14
|
-
name: "next-redirects",
|
|
15
|
-
fn: e,
|
|
16
|
-
ext: "js"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: "next-rewrites",
|
|
20
|
-
fn: t,
|
|
21
|
-
ext: "js"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: "useCurrentLocalisedPathnames",
|
|
25
|
-
fn: n,
|
|
26
|
-
ext: "ts",
|
|
27
|
-
index: !0
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: "useLocale",
|
|
31
|
-
fn: s,
|
|
32
|
-
ext: "ts",
|
|
33
|
-
index: !0
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: "useRouteId",
|
|
37
|
-
fn: r,
|
|
38
|
-
ext: "ts",
|
|
39
|
-
index: !0
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: "useTo",
|
|
43
|
-
fn: o,
|
|
44
|
-
ext: "ts",
|
|
45
|
-
index: !0
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: "useToSpa",
|
|
49
|
-
fn: m,
|
|
50
|
-
ext: "ts",
|
|
51
|
-
index: !0
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
}));
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
"use client";
|
|
3
|
-
|
|
4
|
-
import { useEffect, useState } from "react";
|
|
5
|
-
import { deriveLocalisedPathnames, type LocalisedPathnames } from "./deriveLocalisedPathnames";
|
|
6
|
-
import { useRouteId } from "./useRouteId";
|
|
7
|
-
|
|
8
|
-
export function useCurrentLocalisedPathnames() {
|
|
9
|
-
const routeId = useRouteId();
|
|
10
|
-
const [urls, setUrls] = useState<LocalisedPathnames>({} as LocalisedPathnames);
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
setUrls(deriveLocalisedPathnames(routeId, location));
|
|
14
|
-
}, [routeId]);
|
|
15
|
-
|
|
16
|
-
return urls;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default useCurrentLocalisedPathnames;
|
|
20
|
-
`);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
import { useRouter } from "next/router";
|
|
3
|
-
import type { I18n } from "./types";
|
|
4
|
-
import { pathnameToRouteId } from "./pathnameToRouteId";
|
|
5
|
-
|
|
6
|
-
export const useRouteId = () =>
|
|
7
|
-
pathnameToRouteId(useRouter().pathname) as I18n.RouteId;
|
|
8
|
-
|
|
9
|
-
export default useRouteId;
|
|
10
|
-
`);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
"use client";
|
|
3
|
-
|
|
4
|
-
import { to } from "./to";
|
|
5
|
-
import type { I18n } from "./types";
|
|
6
|
-
import { useLocale } from "./useLocale";
|
|
7
|
-
|
|
8
|
-
export type UseToReturn = ReturnType<typeof useTo>;
|
|
9
|
-
|
|
10
|
-
export const useTo = () => {
|
|
11
|
-
const locale = useLocale();
|
|
12
|
-
return <Id extends I18n.RouteId>(
|
|
13
|
-
routeId: Id,
|
|
14
|
-
...args: Id extends I18n.RouteIdDynamic
|
|
15
|
-
? [params: I18n.RouteParams[Id]]
|
|
16
|
-
: []
|
|
17
|
-
) =>
|
|
18
|
-
args[0]
|
|
19
|
-
? // @ts-expect-error nevermind
|
|
20
|
-
(to(routeId, args[0], locale) as I18n.RoutePathnames[Id])
|
|
21
|
-
: // @ts-expect-error nevermind
|
|
22
|
-
(to(routeId, locale) as I18n.RoutePathnames[Id]);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default useTo;
|
|
26
|
-
`);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
"use client";
|
|
3
|
-
|
|
4
|
-
import { toSpa } from "./toSpa";
|
|
5
|
-
import type { I18n } from "./types";
|
|
6
|
-
import { useLocale } from "./useLocale";
|
|
7
|
-
|
|
8
|
-
export type UseToSpaReturn = ReturnType<typeof useToSpa>;
|
|
9
|
-
|
|
10
|
-
export const useToSpa = () => {
|
|
11
|
-
const locale = useLocale();
|
|
12
|
-
return <
|
|
13
|
-
Root extends keyof I18n.RouteSpa,
|
|
14
|
-
Path extends Extract<keyof I18n.RouteSpa[Root], string>,
|
|
15
|
-
>(
|
|
16
|
-
root: Root,
|
|
17
|
-
path: Path,
|
|
18
|
-
...args: I18n.RouteJoinedId<Root, Path> extends I18n.RouteIdDynamic
|
|
19
|
-
? [params: I18n.RouteParams[I18n.RouteJoinedId<Root, Path>]]
|
|
20
|
-
: I18n.RouteJoinedId<Root, Path> extends I18n.RouteIdStatic
|
|
21
|
-
? []
|
|
22
|
-
: never
|
|
23
|
-
) => {
|
|
24
|
-
const [params] = args;
|
|
25
|
-
return (
|
|
26
|
-
// prettier-ignore
|
|
27
|
-
// @ts-expect-error FIXME: types
|
|
28
|
-
(params ? toSpa(root, path, params, locale) : toSpa(root, path, locale)) as I18n.RouteSpa[Root][Path]
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default useToSpa;
|
|
34
|
-
`);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { i18nCompiler as t } from "../compiler";
|
|
2
|
-
import { getRedirects as e, getRewrites as r, tweakNextConfig as i } from "./plugin-shared";
|
|
3
|
-
export let withI18nAsync = (a = {})=>async ()=>{
|
|
4
|
-
let { i18nCompiler: n, redirects: l, rewrites: o, ...p } = a, c = p;
|
|
5
|
-
if (!n) return c;
|
|
6
|
-
let m = await t(n);
|
|
7
|
-
if ((c = i(m.config, c)).redirects = ()=>e(l, n, m), c.rewrites = ()=>r(o, n, m), "next-translate" === n.code.adapter) try {
|
|
8
|
-
c = (await import("next-translate-plugin").then((t)=>t.default))(c);
|
|
9
|
-
} catch (t) {}
|
|
10
|
-
return c;
|
|
11
|
-
};
|