@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/index.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import t from "./config";
|
|
2
|
-
import e from "./config.cjs";
|
|
3
|
-
import o from "./defaultLocale";
|
|
4
|
-
import m from "./deriveLocalisedPathnames";
|
|
5
|
-
import n from "./isLocale";
|
|
6
|
-
import r from "./locales";
|
|
7
|
-
import a from "./pathnameToRouteId";
|
|
8
|
-
import s from "./routes";
|
|
9
|
-
import f from "./routesSlim";
|
|
10
|
-
import i from "./routesSpa";
|
|
11
|
-
import x from "./tFns";
|
|
12
|
-
import p from "./tInterpolateParams";
|
|
13
|
-
import l from "./tPluralise";
|
|
14
|
-
import d from "./to";
|
|
15
|
-
import c from "./toFns";
|
|
16
|
-
import u from "./toFormat";
|
|
17
|
-
import F from "./toSpa";
|
|
18
|
-
import L from "./types";
|
|
19
|
-
export default (()=>({
|
|
20
|
-
files: [
|
|
21
|
-
{
|
|
22
|
-
name: "config.cjs",
|
|
23
|
-
fn: e,
|
|
24
|
-
ext: "js"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: "config",
|
|
28
|
-
fn: t,
|
|
29
|
-
ext: "ts",
|
|
30
|
-
index: !0
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: "defaultLocale",
|
|
34
|
-
fn: o,
|
|
35
|
-
ext: "ts",
|
|
36
|
-
index: !0
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "deriveLocalisedPathnames",
|
|
40
|
-
fn: m,
|
|
41
|
-
ext: "ts",
|
|
42
|
-
index: !0
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: "isLocale",
|
|
46
|
-
fn: n,
|
|
47
|
-
ext: "ts",
|
|
48
|
-
index: !0
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: "locales",
|
|
52
|
-
fn: r,
|
|
53
|
-
ext: "ts",
|
|
54
|
-
index: !0
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "pathnameToRouteId",
|
|
58
|
-
fn: a,
|
|
59
|
-
ext: "ts",
|
|
60
|
-
index: !0
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: "routes",
|
|
64
|
-
fn: s,
|
|
65
|
-
ext: "ts"
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: "routesSlim",
|
|
69
|
-
fn: f,
|
|
70
|
-
ext: "ts"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: "routesSpa",
|
|
74
|
-
fn: i,
|
|
75
|
-
ext: "ts"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: "tFns",
|
|
79
|
-
fn: x,
|
|
80
|
-
ext: "ts"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: "tInterpolateParams",
|
|
84
|
-
fn: p,
|
|
85
|
-
ext: "ts"
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
name: "to",
|
|
89
|
-
fn: d,
|
|
90
|
-
ext: "ts",
|
|
91
|
-
index: !0
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: "toFns",
|
|
95
|
-
fn: c,
|
|
96
|
-
ext: "ts",
|
|
97
|
-
index: !0
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
name: "toFormat",
|
|
101
|
-
fn: u,
|
|
102
|
-
ext: "ts",
|
|
103
|
-
index: !0
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: "toSpa",
|
|
107
|
-
fn: F,
|
|
108
|
-
ext: "ts",
|
|
109
|
-
index: !0
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: "tPluralise",
|
|
113
|
-
fn: l,
|
|
114
|
-
ext: "ts"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
name: "types",
|
|
118
|
-
fn: L,
|
|
119
|
-
ext: "ts",
|
|
120
|
-
index: !0
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
}));
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
import { locales } from "./locales";
|
|
3
|
-
import type { I18n } from "./types";
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
-
export const isLocale = (payload: any): payload is I18n.Locale => locales.includes(payload);
|
|
7
|
-
|
|
8
|
-
export default isLocale;
|
|
9
|
-
`);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { escapeRegExp as e } from "@koine/utils";
|
|
2
|
-
export default (({ options: t })=>{
|
|
3
|
-
let { idDelimiter: a, optionalCatchAll: r, catchAll: o } = t.routes.tokens;
|
|
4
|
-
return `
|
|
5
|
-
/**
|
|
6
|
-
* Convert a URL like pathname to a "named route"
|
|
7
|
-
* E.g. it transforms:
|
|
8
|
-
* - \`/dashboard/user/[id]\` into \`dashboard.user.[id]\`
|
|
9
|
-
*/
|
|
10
|
-
export const pathnameToRouteId = (pathname: string) =>
|
|
11
|
-
pathname
|
|
12
|
-
.replace(/^\\//g, "")
|
|
13
|
-
.replace(/\\//g, "${a}")
|
|
14
|
-
.replace(/${e(a)}${e(r.start)}.+$/, "")
|
|
15
|
-
.replace(/${e(a)}${e(o.start)}.+$/, "")
|
|
16
|
-
.replace(/\\/index$/, "");
|
|
17
|
-
|
|
18
|
-
export default pathnameToRouteId;
|
|
19
|
-
`;
|
|
20
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default (({ routes: t })=>{
|
|
2
|
-
let e = JSON.stringify(Object.fromEntries(Object.entries(t.byId).map(([t, { pathnamesSlim: e, pathnames: r }])=>[
|
|
3
|
-
t,
|
|
4
|
-
e || r
|
|
5
|
-
]).sort()), null, 2);
|
|
6
|
-
return `
|
|
7
|
-
export const routesSlim = ${e} as const;
|
|
8
|
-
|
|
9
|
-
export default routesSlim;
|
|
10
|
-
`;
|
|
11
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default (({ routes: t })=>{
|
|
2
|
-
let e = JSON.stringify(Object.fromEntries(Object.entries(t.byId).filter(([, { pathnamesSpa: t }])=>!!t).map(([t, { pathnamesSpa: e }])=>[
|
|
3
|
-
t,
|
|
4
|
-
e
|
|
5
|
-
]).sort()), null, 2);
|
|
6
|
-
return `
|
|
7
|
-
export const routesSpa = ${e} as const;
|
|
8
|
-
|
|
9
|
-
export default routesSpa;
|
|
10
|
-
`;
|
|
11
|
-
});
|
package/adapter-js/code/tFns.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { areEqual as t, isArray as e, isBoolean as r, isNumber as l, isPrimitive as o, isString as a } from "@koine/utils";
|
|
2
|
-
import { dataParamsToTsInterfaceBody as n } from "../../compiler/helpers";
|
|
3
|
-
let i = (t)=>a(t) || l(t) ? `"${t}"` : r(t) ? `${t}` : e(t) ? JSON.stringify(t) : `(${JSON.stringify(t)})`, s = (e, r)=>t(e, r), p = (t, e)=>{
|
|
4
|
-
let { defaultLocale: r } = t, l = "";
|
|
5
|
-
for(let t in e){
|
|
6
|
-
let o = e[t];
|
|
7
|
-
t === r || s(o, e[r]) || (l += `locale === "${t}" ? ${i(o)} : `);
|
|
8
|
-
}
|
|
9
|
-
return l + i(e[r]);
|
|
10
|
-
};
|
|
11
|
-
export default (({ config: t, options: e, translations: r })=>{
|
|
12
|
-
let l = `
|
|
13
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
14
|
-
/* eslint-disable prefer-const */
|
|
15
|
-
import type { I18n } from "./types";
|
|
16
|
-
import { tInterpolateParams } from "./tInterpolateParams";
|
|
17
|
-
import { tPluralise } from "./tPluralise";
|
|
18
|
-
|
|
19
|
-
`;
|
|
20
|
-
for(let a in r){
|
|
21
|
-
let { values: s, params: m, plural: f } = r[a], u = `${e.translations.fnsPrefix}${a}`;
|
|
22
|
-
f && (m ? m.count = "number" : m = {
|
|
23
|
-
count: "number"
|
|
24
|
-
});
|
|
25
|
-
let $ = [
|
|
26
|
-
m ? `params: { ${n(m)} }` : "",
|
|
27
|
-
"locale?: I18n.Locale"
|
|
28
|
-
].filter(Boolean).join(", ");
|
|
29
|
-
l += `export let ${u} = (${$}) => `;
|
|
30
|
-
let c = "";
|
|
31
|
-
o(s) ? c += i(s) : c += p(t, s), f && (c = `tPluralise(${c}, params.count)`), l += (c = m ? `tInterpolateParams(${c}, params);` : `${c};`) + `\n`;
|
|
32
|
-
}
|
|
33
|
-
return l;
|
|
34
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
let e = (e)=>e.split("").map((e)=>`\\${e}`).join("");
|
|
2
|
-
export default (({ options: a })=>{
|
|
3
|
-
let { start: t, end: r } = a.translations.dynamicDelimiters;
|
|
4
|
-
return `
|
|
5
|
-
/* eslint-disable prefer-const */
|
|
6
|
-
export let tInterpolateParams = (
|
|
7
|
-
value: string,
|
|
8
|
-
params?: object,
|
|
9
|
-
) =>
|
|
10
|
-
params ? value.replace(
|
|
11
|
-
/${e(t)}(.*?)${e(r)}/g,
|
|
12
|
-
(_, key) =>
|
|
13
|
-
params[key.trim() as keyof typeof params] + "",
|
|
14
|
-
) : value;
|
|
15
|
-
|
|
16
|
-
export default tInterpolateParams;
|
|
17
|
-
`;
|
|
18
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default (()=>`
|
|
2
|
-
/* eslint-disable prefer-const */
|
|
3
|
-
let pluralRules = new Intl.PluralRules();
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
-
export let tPluralise = (values: any, count: number) =>
|
|
7
|
-
values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"]);
|
|
8
|
-
|
|
9
|
-
export default tPluralise;
|
|
10
|
-
`);
|
package/adapter-js/code/to.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export default (({ config: o })=>`
|
|
2
|
-
import { isLocale } from "./isLocale";
|
|
3
|
-
import { toFormat } from "./toFormat";
|
|
4
|
-
import { routesSlim } from "./routesSlim";
|
|
5
|
-
import type { I18n } from "./types";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* *To* route utility
|
|
9
|
-
*
|
|
10
|
-
* @returns A localised relative URL based on your i18nCompiler configuration
|
|
11
|
-
*/
|
|
12
|
-
export function to<Id extends I18n.RouteId>(
|
|
13
|
-
id: Id,
|
|
14
|
-
...args: Id extends I18n.RouteIdDynamic
|
|
15
|
-
?
|
|
16
|
-
| [I18n.RouteParams[Id]]
|
|
17
|
-
| [I18n.RouteParams[Id], I18n.Locale]
|
|
18
|
-
: [] | [I18n.Locale]
|
|
19
|
-
) {
|
|
20
|
-
const locale = (isLocale(args[0]) ? args[0] : args[1]) || "${o.defaultLocale}";
|
|
21
|
-
|
|
22
|
-
return toFormat(
|
|
23
|
-
locale,
|
|
24
|
-
(routesSlim[id] as Record<string, string>)[locale] ??
|
|
25
|
-
(routesSlim[id] as Record<string, string>)["${o.defaultLocale}"] ??
|
|
26
|
-
routesSlim[id],
|
|
27
|
-
isLocale(args[0]) ? undefined : args[0]
|
|
28
|
-
) as I18n.RoutePathnames[Id];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default to;
|
|
32
|
-
`);
|
package/adapter-js/code/toFns.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { changeCaseSnake as t, isString as e } from "@koine/utils";
|
|
2
|
-
let o = (t, e)=>{
|
|
3
|
-
let { defaultLocale: o } = t, r = "";
|
|
4
|
-
for(let t in e){
|
|
5
|
-
let l = e[t];
|
|
6
|
-
t !== o && l !== e[o] && (r += `locale === "${t}" ? "${l}" : `);
|
|
7
|
-
}
|
|
8
|
-
return r + ('"' + e[o]) + '"';
|
|
9
|
-
};
|
|
10
|
-
export default (({ config: r, routes: l, options: a })=>{
|
|
11
|
-
let n = 1 === r.locales.length, $ = `
|
|
12
|
-
/* eslint-disable prefer-const */
|
|
13
|
-
import { toFormat } from "./toFormat";
|
|
14
|
-
import type { I18n } from "./types";
|
|
15
|
-
|
|
16
|
-
`;
|
|
17
|
-
for(let m in l.byId){
|
|
18
|
-
let { pathnames: i, params: s } = l.byId[m], f = `${a.routes.fnsPrefix}${t(m)}`, p = `I18n.RouteParams["${m}"]`, c = [
|
|
19
|
-
s ? `params: ${p}` : "",
|
|
20
|
-
n ? "" : "locale?: I18n.Locale"
|
|
21
|
-
].filter(Boolean).join(", "), u = n ? '""' : "locale", I = s ? ", params" : "";
|
|
22
|
-
$ += `export let ${f} = (${c}) => `, e(i) ? $ += `toFormat(${u}, "${i}"${I});` : $ += `toFormat(${u}, ${o(r, i)}${I});`, $ += `\n`;
|
|
23
|
-
}
|
|
24
|
-
return $;
|
|
25
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export default (({ config: a })=>`
|
|
2
|
-
export function toFormat(
|
|
3
|
-
locale: string | undefined,
|
|
4
|
-
pathname: string,
|
|
5
|
-
params?: object,
|
|
6
|
-
) {
|
|
7
|
-
locale = locale || "${a.defaultLocale}";
|
|
8
|
-
if (process.env["NODE_ENV"] === "development") {
|
|
9
|
-
if (params) {
|
|
10
|
-
pathname.replace(/\\[(.*?)\\]/g, (_, dynamicKey) => {
|
|
11
|
-
const key = dynamicKey as Extract<keyof typeof params, string>;
|
|
12
|
-
|
|
13
|
-
if (!(key in params)) {
|
|
14
|
-
console.warn(
|
|
15
|
-
"[@koine/i18n]::interpolateTo, using '" +
|
|
16
|
-
pathname +
|
|
17
|
-
"' without param '" +
|
|
18
|
-
key +
|
|
19
|
-
"'",
|
|
20
|
-
{ params }
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!["string", "number"].includes(typeof params[key])) {
|
|
25
|
-
console.warn(
|
|
26
|
-
"[@koine/i18n]::toFormat, using '" +
|
|
27
|
-
pathname +
|
|
28
|
-
"' with unserializable param '" +
|
|
29
|
-
key +
|
|
30
|
-
"' (type '" +
|
|
31
|
-
Object.prototype.toString.call((params[key])).slice(8, -1) +
|
|
32
|
-
"')",
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
return "";
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (params) {
|
|
41
|
-
pathname = pathname.replace(
|
|
42
|
-
/\\[(.*?)\\]/g,
|
|
43
|
-
(_, key) =>
|
|
44
|
-
params[key as keyof typeof params] + "",
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
${a.hideDefaultLocaleInUrl ? `
|
|
48
|
-
if (locale !== "${a.defaultLocale}") {
|
|
49
|
-
return "/" + locale + pathname;
|
|
50
|
-
}
|
|
51
|
-
` : ""}
|
|
52
|
-
return pathname;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default toFormat;
|
|
56
|
-
`);
|
package/adapter-js/code/toSpa.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export default (({ config: o, options: t })=>{
|
|
2
|
-
let { idDelimiter: e } = t.routes.tokens;
|
|
3
|
-
return `
|
|
4
|
-
import { isLocale } from "./isLocale";
|
|
5
|
-
import { routesSpa } from "./routesSpa";
|
|
6
|
-
import { toFormat } from "./toFormat";
|
|
7
|
-
import type { I18n } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* *To spa* route utility
|
|
11
|
-
*
|
|
12
|
-
* @returns A localised relative URL based on your i18nCompiler configuration
|
|
13
|
-
*/
|
|
14
|
-
export function toSpa<
|
|
15
|
-
Root extends keyof I18n.RouteSpa,
|
|
16
|
-
Path extends Extract<keyof I18n.RouteSpa[Root], string>,
|
|
17
|
-
>(
|
|
18
|
-
rootId: Root,
|
|
19
|
-
pathId: Path,
|
|
20
|
-
...args: I18n.RouteJoinedId<Root, Path> extends I18n.RouteIdDynamic
|
|
21
|
-
?
|
|
22
|
-
| [I18n.RouteParams[I18n.RouteJoinedId<Root, Path>]]
|
|
23
|
-
| [I18n.RouteParams[I18n.RouteJoinedId<Root, Path>], I18n.Locale]
|
|
24
|
-
: [] | [I18n.Locale]
|
|
25
|
-
) {
|
|
26
|
-
const locale = (isLocale(args[0]) ? args[0] : args[1]) || "${o.defaultLocale}";
|
|
27
|
-
const fullId = \`\${rootId}${e}\${pathId}\` as I18n.RouteJoinedId<Root, Path>;
|
|
28
|
-
return toFormat(
|
|
29
|
-
// FIXME: actually the locale will be prepended if hideDefaultLocaleInUrl will be false
|
|
30
|
-
"", // do not pass the locale so that won't be prepended
|
|
31
|
-
(routesSpa[fullId] as Record<string, string>)[locale],
|
|
32
|
-
args.length === 2
|
|
33
|
-
? args[0]
|
|
34
|
-
: args[0] && !isLocale(args[0])
|
|
35
|
-
? args[0]
|
|
36
|
-
: void 0,
|
|
37
|
-
) as I18n.RouteSpa[Root][Path];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default toSpa;
|
|
41
|
-
`;
|
|
42
|
-
});
|