@koine/i18n 2.0.0-beta.74 → 2.0.0-beta.76
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/actions/helpers-git.js +45 -0
- package/actions/helpers-i18n.js +27 -0
- package/actions/i18n.js +17 -0
- package/adapter-js/code/config.cjs.js +3 -3
- package/adapter-js/code/config.js +3 -3
- package/adapter-js/code/defaultLocale.js +3 -3
- package/adapter-js/code/deriveLocalisedPathnames.js +2 -2
- package/adapter-js/code/index.js +112 -46
- package/adapter-js/code/isLocale.js +2 -2
- package/adapter-js/code/locales.js +4 -4
- package/adapter-js/code/pathnameToRouteId.js +7 -7
- package/adapter-js/code/routes.js +7 -6
- package/adapter-js/code/routesSlim.js +7 -9
- package/adapter-js/code/routesSpa.js +7 -7
- package/adapter-js/code/tFns.js +24 -65
- package/adapter-js/code/tInterpolateParams.js +5 -8
- package/adapter-js/code/tPluralise.js +2 -4
- package/adapter-js/code/to.js +4 -4
- package/adapter-js/code/toFns.js +17 -33
- package/adapter-js/code/toFormat.js +6 -8
- package/adapter-js/code/toSpa.js +5 -5
- package/adapter-js/code/types.js +62 -117
- package/adapter-next/code/index.js +49 -22
- package/adapter-next/code/next-redirects.js +5 -5
- package/adapter-next/code/next-rewrites.js +5 -5
- package/adapter-next/code/useCurrentLocalisedPathnames.js +2 -2
- package/adapter-next/code/useLocale.js +3 -3
- package/adapter-next/code/useRouteId.js +2 -2
- package/adapter-next/code/useTo.js +2 -2
- package/adapter-next/code/useToSpa.js +2 -2
- package/adapter-next/plugin-async.js +11 -21
- package/adapter-next/plugin-legacy.js +165 -224
- package/adapter-next/plugin-shared.js +31 -41
- package/adapter-next/plugin.js +12 -23
- package/adapter-next/redirects.js +46 -72
- package/adapter-next/rewrites.js +45 -63
- package/adapter-next/transformPathname.js +2 -19
- package/adapter-next/webpackPluginI18n.js +7 -15
- package/adapter-next-translate/code/DynamicNamespaces.js +2 -2
- package/adapter-next-translate/code/T.js +2 -2
- package/adapter-next-translate/code/TransText.js +2 -2
- package/adapter-next-translate/code/getT.js +2 -2
- package/adapter-next-translate/code/index.js +44 -21
- package/adapter-next-translate/code/nextTranslateI18n.js +4 -4
- package/adapter-next-translate/code/useT.js +2 -2
- package/cjs/adapter-js/code/config.cjs.d.ts +3 -0
- package/cjs/adapter-js/code/config.d.ts +3 -0
- package/cjs/adapter-js/code/defaultLocale.d.ts +3 -0
- package/cjs/adapter-js/code/deriveLocalisedPathnames.d.ts +2 -0
- package/cjs/adapter-js/code/index.d.ts +3 -0
- package/cjs/adapter-js/code/isLocale.d.ts +2 -0
- package/cjs/adapter-js/code/locales.d.ts +3 -0
- package/cjs/adapter-js/code/pathnameToRouteId.d.ts +3 -0
- package/cjs/adapter-js/code/routes.d.ts +3 -0
- package/cjs/adapter-js/code/routesSlim.d.ts +3 -0
- package/cjs/adapter-js/code/routesSpa.d.ts +3 -0
- package/cjs/adapter-js/code/tFns.d.ts +3 -0
- package/cjs/adapter-js/code/tInterpolateParams.d.ts +3 -0
- package/cjs/adapter-js/code/tPluralise.d.ts +2 -0
- package/cjs/adapter-js/code/to.d.ts +3 -0
- package/cjs/adapter-js/code/toFns.d.ts +3 -0
- package/cjs/adapter-js/code/toFormat.d.ts +3 -0
- package/cjs/adapter-js/code/toSpa.d.ts +3 -0
- package/cjs/adapter-js/code/types.d.ts +3 -0
- package/cjs/adapter-next/code/index.d.ts +3 -0
- package/cjs/adapter-next/code/next-redirects.d.ts +3 -0
- package/cjs/adapter-next/code/next-rewrites.d.ts +3 -0
- package/cjs/adapter-next/code/useCurrentLocalisedPathnames.d.ts +2 -0
- package/cjs/adapter-next/code/useLocale.d.ts +3 -0
- package/cjs/adapter-next/code/useRouteId.d.ts +2 -0
- package/cjs/adapter-next/code/useTo.d.ts +2 -0
- package/cjs/adapter-next/code/useToSpa.d.ts +2 -0
- package/cjs/adapter-next/plugin-async.d.ts +9 -0
- package/cjs/adapter-next/plugin-legacy.d.ts +22 -0
- package/cjs/adapter-next/plugin-shared.d.ts +13 -0
- package/cjs/adapter-next/plugin.d.ts +7 -0
- package/cjs/adapter-next/redirects.d.ts +4 -0
- package/cjs/adapter-next/rewrites.d.ts +4 -0
- package/cjs/adapter-next/transformPathname.d.ts +1 -0
- package/cjs/adapter-next/webpackPluginI18n.d.ts +7 -0
- package/cjs/adapter-next-translate/code/DynamicNamespaces.d.ts +2 -0
- package/cjs/adapter-next-translate/code/T.d.ts +2 -0
- package/cjs/adapter-next-translate/code/TransText.d.ts +2 -0
- package/cjs/adapter-next-translate/code/getT.d.ts +2 -0
- package/cjs/adapter-next-translate/code/index.d.ts +3 -0
- package/cjs/adapter-next-translate/code/nextTranslateI18n.d.ts +3 -0
- package/cjs/adapter-next-translate/code/useT.d.ts +2 -0
- package/cjs/client/formatRoutePathname.d.ts +4 -0
- package/cjs/client/index.d.ts +3 -0
- package/cjs/client/interpolateTo.d.ts +4 -0
- package/cjs/client/routeHasDynamicPortion.d.ts +2 -0
- package/cjs/compiler/api.d.ts +30 -0
- package/cjs/compiler/code/data-routes.d.ts +19 -0
- package/cjs/compiler/code/data-translations.d.ts +13 -0
- package/cjs/compiler/code/data.d.ts +33 -0
- package/cjs/compiler/code/generate.d.ts +14 -0
- package/cjs/compiler/code/index.d.ts +3 -0
- package/cjs/compiler/code/tsCompile.d.ts +2 -0
- package/cjs/compiler/code/write.d.ts +11 -0
- package/cjs/compiler/config.d.ts +12 -0
- package/cjs/compiler/helpers.d.ts +2 -0
- package/cjs/compiler/input/data-local.d.ts +4 -0
- package/cjs/compiler/input/data-remote.d.ts +7 -0
- package/cjs/compiler/input/data.d.ts +4 -0
- package/cjs/compiler/input/index.d.ts +4 -0
- package/cjs/compiler/input/types.d.ts +14 -0
- package/cjs/compiler/input/write.d.ts +8 -0
- package/cjs/compiler/pluralisation.d.ts +37 -0
- package/cjs/compiler/summary/data.d.ts +6 -0
- package/cjs/compiler/summary/generate.d.ts +4 -0
- package/cjs/compiler/summary/index.d.ts +3 -0
- package/cjs/compiler/summary/write.d.ts +10 -0
- package/cjs/compiler/types.d.ts +82 -0
- package/cjs/compiler-sync.d.ts +4 -0
- package/cjs/compiler-worker.d.ts +1 -0
- package/cjs/compiler.d.ts +2 -0
- package/cjs/i18n/actions/helpers-git.js +45 -0
- package/cjs/i18n/actions/helpers-i18n.js +27 -0
- package/cjs/i18n/actions/i18n.js +17 -0
- package/cjs/i18n/adapter-js/code/config.cjs.js +14 -0
- package/cjs/i18n/adapter-js/code/config.js +14 -0
- package/cjs/i18n/adapter-js/code/defaultLocale.js +7 -0
- package/cjs/i18n/adapter-js/code/deriveLocalisedPathnames.js +78 -0
- package/cjs/i18n/adapter-js/code/index.js +123 -0
- package/cjs/i18n/adapter-js/code/isLocale.js +9 -0
- package/cjs/i18n/adapter-js/code/locales.js +8 -0
- package/cjs/i18n/adapter-js/code/pathnameToRouteId.js +20 -0
- package/cjs/i18n/adapter-js/code/routes.js +11 -0
- package/cjs/i18n/adapter-js/code/routesSlim.js +11 -0
- package/cjs/i18n/adapter-js/code/routesSpa.js +11 -0
- package/cjs/i18n/adapter-js/code/tFns.js +34 -0
- package/cjs/i18n/adapter-js/code/tInterpolateParams.js +18 -0
- package/cjs/i18n/adapter-js/code/tPluralise.js +10 -0
- package/cjs/i18n/adapter-js/code/to.js +32 -0
- package/cjs/i18n/adapter-js/code/toFns.js +25 -0
- package/cjs/i18n/adapter-js/code/toFormat.js +56 -0
- package/cjs/i18n/adapter-js/code/toSpa.js +42 -0
- package/cjs/i18n/adapter-js/code/types.js +327 -0
- package/cjs/i18n/adapter-next/code/index.js +54 -0
- package/cjs/i18n/adapter-next/code/next-redirects.js +5 -0
- package/cjs/i18n/adapter-next/code/next-rewrites.js +5 -0
- package/cjs/i18n/adapter-next/code/useCurrentLocalisedPathnames.js +20 -0
- package/cjs/i18n/adapter-next/code/useLocale.js +8 -0
- package/cjs/i18n/adapter-next/code/useRouteId.js +10 -0
- package/cjs/i18n/adapter-next/code/useTo.js +26 -0
- package/cjs/i18n/adapter-next/code/useToSpa.js +34 -0
- package/cjs/i18n/adapter-next/plugin-async.js +11 -0
- package/{next.esm.js → cjs/i18n/adapter-next/plugin-legacy.js} +9 -85
- package/cjs/i18n/adapter-next/plugin-shared.js +39 -0
- package/cjs/i18n/adapter-next/plugin.js +13 -0
- package/cjs/i18n/adapter-next/redirects.js +51 -0
- package/cjs/i18n/adapter-next/rewrites.js +50 -0
- package/cjs/i18n/adapter-next/transformPathname.js +3 -0
- package/cjs/i18n/adapter-next/webpackPluginI18n.js +11 -0
- package/cjs/i18n/adapter-next-translate/code/DynamicNamespaces.js +9 -0
- package/cjs/i18n/adapter-next-translate/code/T.js +31 -0
- package/cjs/i18n/adapter-next-translate/code/TransText.js +9 -0
- package/cjs/i18n/adapter-next-translate/code/getT.js +15 -0
- package/cjs/i18n/adapter-next-translate/code/index.js +49 -0
- package/cjs/i18n/adapter-next-translate/code/nextTranslateI18n.js +19 -0
- package/cjs/i18n/adapter-next-translate/code/useT.js +43 -0
- package/{formatRoutePathname.esm.js → cjs/i18n/client/formatRoutePathname.js} +2 -3
- package/cjs/i18n/client/index.js +3 -0
- package/cjs/i18n/client/interpolateTo.js +14 -0
- package/cjs/i18n/client/routeHasDynamicPortion.js +2 -0
- package/cjs/i18n/compiler/api.js +18 -0
- package/cjs/i18n/compiler/code/data-routes.js +99 -0
- package/cjs/i18n/compiler/code/data-translations.js +86 -0
- package/cjs/i18n/compiler/code/data.js +20 -0
- package/cjs/i18n/compiler/code/generate.js +46 -0
- package/cjs/i18n/compiler/code/index.js +2 -0
- package/cjs/i18n/compiler/code/tsCompile.js +27 -0
- package/cjs/i18n/compiler/code/write.js +39 -0
- package/cjs/i18n/compiler/config.js +13 -0
- package/cjs/i18n/compiler/helpers.js +14 -0
- package/cjs/i18n/compiler/input/data-local.js +60 -0
- package/cjs/i18n/compiler/input/data-remote.js +41 -0
- package/cjs/i18n/compiler/input/data.js +11 -0
- package/cjs/i18n/compiler/input/index.js +3 -0
- package/cjs/i18n/compiler/input/types.js +1 -0
- package/cjs/i18n/compiler/input/write.js +15 -0
- package/cjs/i18n/compiler/pluralisation.js +59 -0
- package/cjs/i18n/compiler/summary/data.js +28 -0
- package/cjs/i18n/compiler/summary/generate.js +27 -0
- package/cjs/i18n/compiler/summary/index.js +2 -0
- package/cjs/i18n/compiler/summary/write.js +18 -0
- package/cjs/i18n/compiler/types.js +1 -0
- package/cjs/i18n/compiler-sync.js +2 -0
- package/cjs/i18n/compiler-worker.js +3 -0
- package/cjs/i18n/compiler.js +1 -0
- package/cjs/i18n/index.js +2 -0
- package/cjs/i18n/next.js +3 -0
- package/cjs/i18n/types.js +1 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/next.d.ts +3 -0
- package/cjs/package.json +34 -0
- package/cjs/types.d.ts +48 -0
- package/client/formatRoutePathname.js +3 -7
- package/client/interpolateTo.js +12 -35
- package/client/routeHasDynamicPortion.js +1 -1
- package/compiler/api.js +17 -22
- package/compiler/code/data-routes.js +73 -148
- package/compiler/code/data-translations.js +68 -130
- package/compiler/code/data.js +17 -19
- package/compiler/code/generate.js +43 -70
- package/compiler/code/index.js +0 -1
- package/compiler/code/tsCompile.js +26 -39
- package/compiler/code/write.js +36 -75
- package/compiler/config.js +9 -10
- package/compiler/helpers.js +14 -19
- package/compiler/input/data-local.js +52 -62
- package/compiler/input/data-remote.js +32 -56
- package/compiler/input/data.js +9 -15
- package/compiler/input/index.js +0 -1
- package/compiler/input/types.js +1 -1
- package/compiler/input/write.js +10 -10
- package/compiler/pluralisation.js +48 -56
- package/compiler/summary/data.js +22 -49
- package/compiler/summary/generate.js +26 -72
- package/compiler/summary/index.js +1 -1
- package/compiler/summary/write.js +16 -26
- package/compiler/types.js +1 -1
- package/compiler-sync.js +2 -3
- package/compiler-worker.js +3 -3
- package/compiler.js +1 -1
- package/next.js +2 -2
- package/package.json +305 -22
- package/types.js +1 -1
- package/README.md +0 -1
- package/api.cjs.js +0 -1839
- package/api.esm.js +0 -1815
- package/compiler-sync.cjs.d.ts +0 -1
- package/compiler-sync.cjs.default.js +0 -1
- package/compiler-sync.cjs.js +0 -9
- package/compiler-sync.cjs.mjs +0 -2
- package/compiler-sync.esm.js +0 -5
- package/compiler-worker.cjs.d.ts +0 -1
- package/compiler-worker.cjs.default.js +0 -1
- package/compiler-worker.cjs.js +0 -17
- package/compiler-worker.cjs.mjs +0 -2
- package/compiler-worker.esm.js +0 -15
- package/compiler.cjs.d.ts +0 -1
- package/compiler.cjs.default.js +0 -1
- package/compiler.cjs.js +0 -20
- package/compiler.cjs.mjs +0 -2
- package/compiler.esm.js +0 -12
- package/formatRoutePathname.cjs.js +0 -8
- package/index.cjs.d.ts +0 -1
- package/index.cjs.default.js +0 -1
- package/index.cjs.js +0 -24
- package/index.cjs.mjs +0 -2
- package/index.esm.js +0 -19
- package/next.cjs.d.ts +0 -1
- package/next.cjs.default.js +0 -1
- package/next.cjs.js +0 -287
- package/next.cjs.mjs +0 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as t from "@actions/core";
|
|
2
|
+
import { simpleGit as i } from "simple-git";
|
|
3
|
+
function e(i, e) {
|
|
4
|
+
e && console.log(e), i && t.error(i);
|
|
5
|
+
}
|
|
6
|
+
export class Git {
|
|
7
|
+
constructor(i, e){
|
|
8
|
+
this.errors = [], this.baseDir = i, this.afterFetch = e, this.outputs = {
|
|
9
|
+
committed: "false",
|
|
10
|
+
commit_sha: void 0,
|
|
11
|
+
pushed: "false"
|
|
12
|
+
}, Object.entries(this.outputs).forEach(([i, e])=>t.setOutput(i, e));
|
|
13
|
+
}
|
|
14
|
+
async run() {
|
|
15
|
+
let s = i({
|
|
16
|
+
baseDir: this.baseDir
|
|
17
|
+
}), o = process.env.GITHUB_REF?.substring(11) || "main";
|
|
18
|
+
t.info(`Running in folder ${this.baseDir}...`), t.info("> Pulling from remote..."), await s.fetch(void 0, e).pull(void 0, void 0, void 0, e), await this.afterFetch(), t.info("> Checking for uncommitted changes in the git working tree...");
|
|
19
|
+
let r = (await s.status()).files.length;
|
|
20
|
+
r ? (t.info(`> Found ${r} changed files.`), await s.fetch([
|
|
21
|
+
"--tags",
|
|
22
|
+
"--force"
|
|
23
|
+
], e), t.info("> Re-staging files..."), await s.add(".").catch((t)=>{
|
|
24
|
+
if (t.message.includes("fatal: pathspec") && t.message.includes("did not match any files")) this.errors.push(Error("Add command did not match any file"));
|
|
25
|
+
else throw t;
|
|
26
|
+
}), t.info("> Creating commit..."), await s.commit("chore(action): auto commit", void 0, {}, (t, i)=>(i && (this.setOutput("committed", "true"), this.setOutput("commit_sha", i.commit)), e(t, i))), t.info("> Pushing commit to repo..."), await s.push("origin", o, {
|
|
27
|
+
"--set-upstream": null
|
|
28
|
+
}, (t, i)=>(i && this.setOutput("pushed", "true"), e(t, i))), t.endGroup(), t.info("> Task completed!!!")) : (t.endGroup(), t.info("> Working tree clean. Nothing to commit."));
|
|
29
|
+
}
|
|
30
|
+
setOutput(i, e) {
|
|
31
|
+
this.outputs[i] = e, t.setOutput(i, e);
|
|
32
|
+
}
|
|
33
|
+
logOutputs() {
|
|
34
|
+
for(let i in t.startGroup("Outputs"), this.outputs)t.info(`${i}: ${this.outputs[i]}`);
|
|
35
|
+
t.endGroup();
|
|
36
|
+
}
|
|
37
|
+
success() {
|
|
38
|
+
if (1 === this.errors.length) throw this.errors[0];
|
|
39
|
+
if (this.errors.length > 1) throw this.errors.forEach((i)=>t.error(i)), "There have been multiple runtime errors.";
|
|
40
|
+
this.logOutputs();
|
|
41
|
+
}
|
|
42
|
+
error(i) {
|
|
43
|
+
t.endGroup(), this.logOutputs(), t.setFailed(i);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getConfig as o } from "../compiler/config";
|
|
2
|
+
import { getInputDataLocal as r } from "../compiler/input/data-local";
|
|
3
|
+
import { writeInput as t } from "../compiler/input/write";
|
|
4
|
+
import { getSummaryData as i } from "../compiler/summary/data";
|
|
5
|
+
import { writeSummary as m } from "../compiler/summary/write";
|
|
6
|
+
export let i18nAction = async (p)=>{
|
|
7
|
+
let { cwd: u, source: e = ".", url: a, output: { input: l, summaryJson: c, summaryMarkdown: n }, ...s } = p, f = await r({
|
|
8
|
+
cwd: u,
|
|
9
|
+
source: e,
|
|
10
|
+
...s
|
|
11
|
+
}), w = [];
|
|
12
|
+
if (l && w.push(t({
|
|
13
|
+
cwd: u,
|
|
14
|
+
output: l
|
|
15
|
+
}, f)), c || n) {
|
|
16
|
+
let r = i(o(f), {
|
|
17
|
+
sourceUrl: a
|
|
18
|
+
}, f);
|
|
19
|
+
w.push(m({
|
|
20
|
+
cwd: u,
|
|
21
|
+
outputJson: c,
|
|
22
|
+
outputMarkdown: n,
|
|
23
|
+
sourceUrl: a
|
|
24
|
+
}, r));
|
|
25
|
+
}
|
|
26
|
+
return await Promise.all(w), f;
|
|
27
|
+
};
|
package/actions/i18n.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getInput as o, info as s } from "@actions/core";
|
|
2
|
+
import { Git as r } from "./helpers-git";
|
|
3
|
+
import { i18nAction as t } from "./helpers-i18n";
|
|
4
|
+
let e = async ()=>{
|
|
5
|
+
let r = process.env.GITHUB_REPOSITORY, e = process.env.GITHUB_REF.replace("refs/heads/", ""), u = `https://github.com/${r}/blob/${e}`, n = await t({
|
|
6
|
+
url: u,
|
|
7
|
+
output: {
|
|
8
|
+
input: o("output_input") || ".github/input.json",
|
|
9
|
+
summaryJson: o("output_summary_json") || ".github/summary.json",
|
|
10
|
+
summaryMarkdown: o("output_summary_md") || ".github/summary.md"
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
s(`Found locales: ${n.localesFolders.join(", ")}`), s(`Found ${n.translationFiles.length} JSON files`);
|
|
14
|
+
}, u = new r(process.cwd(), e);
|
|
15
|
+
u.run().then(()=>u.success()).catch((o)=>{
|
|
16
|
+
u.error(o), console.error(o);
|
|
17
|
+
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export default ({ config })
|
|
1
|
+
export default (({ config: e })=>`
|
|
2
2
|
const { locales } = require("./locales");
|
|
3
3
|
const { defaultLocale } = require("./defaultLocale");
|
|
4
4
|
|
|
5
5
|
const config = {
|
|
6
6
|
locales,
|
|
7
7
|
defaultLocale,
|
|
8
|
-
hideDefaultLocaleInUrl: ${
|
|
8
|
+
hideDefaultLocaleInUrl: ${e.hideDefaultLocaleInUrl},
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
exports.config = config;
|
|
12
12
|
|
|
13
13
|
module.exports = config;
|
|
14
|
-
|
|
14
|
+
`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default ({ config })
|
|
1
|
+
export default (({ config: e })=>`
|
|
2
2
|
import { locales } from "./locales";
|
|
3
3
|
import { defaultLocale } from "./defaultLocale";
|
|
4
4
|
|
|
@@ -7,8 +7,8 @@ import { defaultLocale } from "./defaultLocale";
|
|
|
7
7
|
export const config = {
|
|
8
8
|
locales,
|
|
9
9
|
defaultLocale,
|
|
10
|
-
hideDefaultLocaleInUrl: ${
|
|
10
|
+
hideDefaultLocaleInUrl: ${e.hideDefaultLocaleInUrl},
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export default config;
|
|
14
|
-
|
|
14
|
+
`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export default ({ config })
|
|
1
|
+
export default (({ config: e })=>`
|
|
2
2
|
import type { I18n } from "./types";
|
|
3
3
|
|
|
4
|
-
export const defaultLocale: I18n.Locale = "${
|
|
4
|
+
export const defaultLocale: I18n.Locale = "${e.defaultLocale}";
|
|
5
5
|
|
|
6
6
|
export default defaultLocale;
|
|
7
|
-
|
|
7
|
+
`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default ()
|
|
1
|
+
export default (()=>`
|
|
2
2
|
import { locales } from "./locales";
|
|
3
3
|
import { to } from "./to";
|
|
4
4
|
import type { I18n } from "./types";
|
|
@@ -75,4 +75,4 @@ export const deriveLocalisedPathnames = (routeId: I18n.RouteId, locationLike: Lo
|
|
|
75
75
|
}, {} as LocalisedPathnames);
|
|
76
76
|
|
|
77
77
|
export default deriveLocalisedPathnames;
|
|
78
|
-
|
|
78
|
+
`);
|
package/adapter-js/code/index.js
CHANGED
|
@@ -1,57 +1,123 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
return {
|
|
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 (()=>({
|
|
21
20
|
files: [
|
|
22
|
-
{
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
},
|
|
25
38
|
{
|
|
26
39
|
name: "deriveLocalisedPathnames",
|
|
27
|
-
fn:
|
|
40
|
+
fn: m,
|
|
41
|
+
ext: "ts",
|
|
42
|
+
index: !0
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "isLocale",
|
|
46
|
+
fn: n,
|
|
28
47
|
ext: "ts",
|
|
29
|
-
index:
|
|
48
|
+
index: !0
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "locales",
|
|
52
|
+
fn: r,
|
|
53
|
+
ext: "ts",
|
|
54
|
+
index: !0
|
|
30
55
|
},
|
|
31
|
-
{ name: "isLocale", fn: isLocale, ext: "ts", index: true },
|
|
32
|
-
{ name: "locales", fn: locales, ext: "ts", index: true },
|
|
33
56
|
{
|
|
34
57
|
name: "pathnameToRouteId",
|
|
35
|
-
fn:
|
|
58
|
+
fn: a,
|
|
36
59
|
ext: "ts",
|
|
37
|
-
index:
|
|
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"
|
|
38
81
|
},
|
|
39
|
-
{ name: "routes", fn: routes, ext: "ts" },
|
|
40
|
-
{ name: "routesSlim", fn: routesSlim, ext: "ts" },
|
|
41
|
-
{ name: "routesSpa", fn: routesSpa, ext: "ts" },
|
|
42
|
-
{ name: "tFns", fn: tFns, ext: "ts" },
|
|
43
82
|
{
|
|
44
83
|
name: "tInterpolateParams",
|
|
45
|
-
fn:
|
|
46
|
-
ext: "ts"
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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,4 +1,4 @@
|
|
|
1
|
-
export default ()
|
|
1
|
+
export default (()=>`
|
|
2
2
|
import { locales } from "./locales";
|
|
3
3
|
import type { I18n } from "./types";
|
|
4
4
|
|
|
@@ -6,4 +6,4 @@ import type { I18n } from "./types";
|
|
|
6
6
|
export const isLocale = (payload: any): payload is I18n.Locale => locales.includes(payload);
|
|
7
7
|
|
|
8
8
|
export default isLocale;
|
|
9
|
-
|
|
9
|
+
`);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export default ({ config })
|
|
2
|
-
|
|
1
|
+
export default (({ config: e })=>{
|
|
2
|
+
let l = `[${e.locales.map((e)=>`"${e}"`).join(", ")}]`;
|
|
3
3
|
return `
|
|
4
|
-
export const locales = ${
|
|
4
|
+
export const locales = ${l} as const;
|
|
5
5
|
|
|
6
6
|
export default locales;
|
|
7
7
|
`;
|
|
8
|
-
};
|
|
8
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { escapeRegExp } from "@koine/utils";
|
|
2
|
-
export default ({ options })
|
|
3
|
-
|
|
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
4
|
return `
|
|
5
5
|
/**
|
|
6
6
|
* Convert a URL like pathname to a "named route"
|
|
@@ -10,11 +10,11 @@ export default ({ options }) => {
|
|
|
10
10
|
export const pathnameToRouteId = (pathname: string) =>
|
|
11
11
|
pathname
|
|
12
12
|
.replace(/^\\//g, "")
|
|
13
|
-
.replace(/\\//g, "${
|
|
14
|
-
.replace(/${
|
|
15
|
-
.replace(/${
|
|
13
|
+
.replace(/\\//g, "${a}")
|
|
14
|
+
.replace(/${e(a)}${e(r.start)}.+$/, "")
|
|
15
|
+
.replace(/${e(a)}${e(o.start)}.+$/, "")
|
|
16
16
|
.replace(/\\/index$/, "");
|
|
17
17
|
|
|
18
18
|
export default pathnameToRouteId;
|
|
19
19
|
`;
|
|
20
|
-
};
|
|
20
|
+
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export default ({ routes })
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export default (({ routes: t })=>{
|
|
2
|
+
let e = JSON.stringify(Object.fromEntries(Object.entries(t.byId).map(([t, { pathnames: e }])=>[
|
|
3
|
+
t,
|
|
4
|
+
e
|
|
5
|
+
]).sort()), null, 2);
|
|
5
6
|
return `
|
|
6
|
-
export const routes = ${
|
|
7
|
+
export const routes = ${e} as const;
|
|
7
8
|
|
|
8
9
|
export default routes;
|
|
9
10
|
`;
|
|
10
|
-
};
|
|
11
|
+
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
export default ({ routes })
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
])
|
|
7
|
-
.sort()), null, 2);
|
|
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);
|
|
8
6
|
return `
|
|
9
|
-
export const routesSlim = ${
|
|
7
|
+
export const routesSlim = ${e} as const;
|
|
10
8
|
|
|
11
9
|
export default routesSlim;
|
|
12
10
|
`;
|
|
13
|
-
};
|
|
11
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export default ({ routes })
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
.sort()), null, 2);
|
|
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
6
|
return `
|
|
7
|
-
export const routesSpa = ${
|
|
7
|
+
export const routesSpa = ${e} as const;
|
|
8
8
|
|
|
9
9
|
export default routesSpa;
|
|
10
10
|
`;
|
|
11
|
-
};
|
|
11
|
+
});
|
package/adapter-js/code/tFns.js
CHANGED
|
@@ -1,33 +1,15 @@
|
|
|
1
|
-
import { areEqual, isArray, isBoolean, isNumber, isPrimitive, isString
|
|
2
|
-
import { dataParamsToTsInterfaceBody } from "../../compiler/helpers";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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)} : `);
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
return `${value}`;
|
|
9
|
-
}
|
|
10
|
-
else if (isArray(value)) {
|
|
11
|
-
return JSON.stringify(value);
|
|
12
|
-
}
|
|
13
|
-
return `(${JSON.stringify(value)})`;
|
|
9
|
+
return l + i(e[r]);
|
|
14
10
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const { defaultLocale } = config;
|
|
18
|
-
let output = "";
|
|
19
|
-
for (const locale in perLocaleValues) {
|
|
20
|
-
const value = perLocaleValues[locale];
|
|
21
|
-
if (locale !== defaultLocale &&
|
|
22
|
-
!areEqualTranslationsValues(value, perLocaleValues[defaultLocale])) {
|
|
23
|
-
output += `locale === "${locale}" ? ${getTranslationValueOutput(value)} : `;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
output += getTranslationValueOutput(perLocaleValues[defaultLocale]);
|
|
27
|
-
return output;
|
|
28
|
-
};
|
|
29
|
-
export default ({ config, options, translations }) => {
|
|
30
|
-
let output = `
|
|
11
|
+
export default (({ config: t, options: e, translations: r })=>{
|
|
12
|
+
let l = `
|
|
31
13
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
32
14
|
/* eslint-disable prefer-const */
|
|
33
15
|
import type { I18n } from "./types";
|
|
@@ -35,41 +17,18 @@ import { tInterpolateParams } from "./tInterpolateParams";
|
|
|
35
17
|
import { tPluralise } from "./tPluralise";
|
|
36
18
|
|
|
37
19
|
`;
|
|
38
|
-
for
|
|
39
|
-
let { values, params, plural } =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
? `params: { ${dataParamsToTsInterfaceBody(params)} }`
|
|
51
|
-
: "";
|
|
52
|
-
const argLocale = "locale?: I18n.Locale";
|
|
53
|
-
const args = [argParam, argLocale].filter(Boolean).join(", ");
|
|
54
|
-
output += `export let ${name} = (${args}) => `;
|
|
55
|
-
let outputFnReturn = "";
|
|
56
|
-
if (isPrimitive(values)) {
|
|
57
|
-
outputFnReturn += getTranslationValueOutput(values);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
outputFnReturn += getFunctionBodyWithLocales(config, values);
|
|
61
|
-
}
|
|
62
|
-
if (plural) {
|
|
63
|
-
outputFnReturn = `tPluralise(${outputFnReturn}, params.count)`;
|
|
64
|
-
}
|
|
65
|
-
if (params) {
|
|
66
|
-
outputFnReturn = `tInterpolateParams(${outputFnReturn}, params);`;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
outputFnReturn = `${outputFnReturn};`;
|
|
70
|
-
}
|
|
71
|
-
output += outputFnReturn;
|
|
72
|
-
output += `\n`;
|
|
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`;
|
|
73
32
|
}
|
|
74
|
-
return
|
|
75
|
-
};
|
|
33
|
+
return l;
|
|
34
|
+
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
.join("");
|
|
5
|
-
export default ({ options }) => {
|
|
6
|
-
const { start, end } = options.translations.dynamicDelimiters;
|
|
1
|
+
let e = (e)=>e.split("").map((e)=>`\\${e}`).join("");
|
|
2
|
+
export default (({ options: a })=>{
|
|
3
|
+
let { start: t, end: r } = a.translations.dynamicDelimiters;
|
|
7
4
|
return `
|
|
8
5
|
/* eslint-disable prefer-const */
|
|
9
6
|
export let tInterpolateParams = (
|
|
@@ -11,11 +8,11 @@ export let tInterpolateParams = (
|
|
|
11
8
|
params?: object,
|
|
12
9
|
) =>
|
|
13
10
|
params ? value.replace(
|
|
14
|
-
/${
|
|
11
|
+
/${e(t)}(.*?)${e(r)}/g,
|
|
15
12
|
(_, key) =>
|
|
16
13
|
params[key.trim() as keyof typeof params] + "",
|
|
17
14
|
) : value;
|
|
18
15
|
|
|
19
16
|
export default tInterpolateParams;
|
|
20
17
|
`;
|
|
21
|
-
};
|
|
18
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export default ()
|
|
2
|
-
return `
|
|
1
|
+
export default (()=>`
|
|
3
2
|
/* eslint-disable prefer-const */
|
|
4
3
|
let pluralRules = new Intl.PluralRules();
|
|
5
4
|
|
|
@@ -8,5 +7,4 @@ export let tPluralise = (values: any, count: number) =>
|
|
|
8
7
|
values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"]);
|
|
9
8
|
|
|
10
9
|
export default tPluralise;
|
|
11
|
-
|
|
12
|
-
};
|
|
10
|
+
`);
|
package/adapter-js/code/to.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default ({ config })
|
|
1
|
+
export default (({ config: o })=>`
|
|
2
2
|
import { isLocale } from "./isLocale";
|
|
3
3
|
import { toFormat } from "./toFormat";
|
|
4
4
|
import { routesSlim } from "./routesSlim";
|
|
@@ -17,16 +17,16 @@ export function to<Id extends I18n.RouteId>(
|
|
|
17
17
|
| [I18n.RouteParams[Id], I18n.Locale]
|
|
18
18
|
: [] | [I18n.Locale]
|
|
19
19
|
) {
|
|
20
|
-
const locale = (isLocale(args[0]) ? args[0] : args[1]) || "${
|
|
20
|
+
const locale = (isLocale(args[0]) ? args[0] : args[1]) || "${o.defaultLocale}";
|
|
21
21
|
|
|
22
22
|
return toFormat(
|
|
23
23
|
locale,
|
|
24
24
|
(routesSlim[id] as Record<string, string>)[locale] ??
|
|
25
|
-
(routesSlim[id] as Record<string, string>)["${
|
|
25
|
+
(routesSlim[id] as Record<string, string>)["${o.defaultLocale}"] ??
|
|
26
26
|
routesSlim[id],
|
|
27
27
|
isLocale(args[0]) ? undefined : args[0]
|
|
28
28
|
) as I18n.RoutePathnames[Id];
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export default to;
|
|
32
|
-
|
|
32
|
+
`);
|