@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.
Files changed (256) hide show
  1. package/actions/helpers-git.js +45 -0
  2. package/actions/helpers-i18n.js +27 -0
  3. package/actions/i18n.js +17 -0
  4. package/adapter-js/code/config.cjs.js +3 -3
  5. package/adapter-js/code/config.js +3 -3
  6. package/adapter-js/code/defaultLocale.js +3 -3
  7. package/adapter-js/code/deriveLocalisedPathnames.js +2 -2
  8. package/adapter-js/code/index.js +112 -46
  9. package/adapter-js/code/isLocale.js +2 -2
  10. package/adapter-js/code/locales.js +4 -4
  11. package/adapter-js/code/pathnameToRouteId.js +7 -7
  12. package/adapter-js/code/routes.js +7 -6
  13. package/adapter-js/code/routesSlim.js +7 -9
  14. package/adapter-js/code/routesSpa.js +7 -7
  15. package/adapter-js/code/tFns.js +24 -65
  16. package/adapter-js/code/tInterpolateParams.js +5 -8
  17. package/adapter-js/code/tPluralise.js +2 -4
  18. package/adapter-js/code/to.js +4 -4
  19. package/adapter-js/code/toFns.js +17 -33
  20. package/adapter-js/code/toFormat.js +6 -8
  21. package/adapter-js/code/toSpa.js +5 -5
  22. package/adapter-js/code/types.js +62 -117
  23. package/adapter-next/code/index.js +49 -22
  24. package/adapter-next/code/next-redirects.js +5 -5
  25. package/adapter-next/code/next-rewrites.js +5 -5
  26. package/adapter-next/code/useCurrentLocalisedPathnames.js +2 -2
  27. package/adapter-next/code/useLocale.js +3 -3
  28. package/adapter-next/code/useRouteId.js +2 -2
  29. package/adapter-next/code/useTo.js +2 -2
  30. package/adapter-next/code/useToSpa.js +2 -2
  31. package/adapter-next/plugin-async.js +11 -21
  32. package/adapter-next/plugin-legacy.js +165 -224
  33. package/adapter-next/plugin-shared.js +31 -41
  34. package/adapter-next/plugin.js +12 -23
  35. package/adapter-next/redirects.js +46 -72
  36. package/adapter-next/rewrites.js +45 -63
  37. package/adapter-next/transformPathname.js +2 -19
  38. package/adapter-next/webpackPluginI18n.js +7 -15
  39. package/adapter-next-translate/code/DynamicNamespaces.js +2 -2
  40. package/adapter-next-translate/code/T.js +2 -2
  41. package/adapter-next-translate/code/TransText.js +2 -2
  42. package/adapter-next-translate/code/getT.js +2 -2
  43. package/adapter-next-translate/code/index.js +44 -21
  44. package/adapter-next-translate/code/nextTranslateI18n.js +4 -4
  45. package/adapter-next-translate/code/useT.js +2 -2
  46. package/cjs/adapter-js/code/config.cjs.d.ts +3 -0
  47. package/cjs/adapter-js/code/config.d.ts +3 -0
  48. package/cjs/adapter-js/code/defaultLocale.d.ts +3 -0
  49. package/cjs/adapter-js/code/deriveLocalisedPathnames.d.ts +2 -0
  50. package/cjs/adapter-js/code/index.d.ts +3 -0
  51. package/cjs/adapter-js/code/isLocale.d.ts +2 -0
  52. package/cjs/adapter-js/code/locales.d.ts +3 -0
  53. package/cjs/adapter-js/code/pathnameToRouteId.d.ts +3 -0
  54. package/cjs/adapter-js/code/routes.d.ts +3 -0
  55. package/cjs/adapter-js/code/routesSlim.d.ts +3 -0
  56. package/cjs/adapter-js/code/routesSpa.d.ts +3 -0
  57. package/cjs/adapter-js/code/tFns.d.ts +3 -0
  58. package/cjs/adapter-js/code/tInterpolateParams.d.ts +3 -0
  59. package/cjs/adapter-js/code/tPluralise.d.ts +2 -0
  60. package/cjs/adapter-js/code/to.d.ts +3 -0
  61. package/cjs/adapter-js/code/toFns.d.ts +3 -0
  62. package/cjs/adapter-js/code/toFormat.d.ts +3 -0
  63. package/cjs/adapter-js/code/toSpa.d.ts +3 -0
  64. package/cjs/adapter-js/code/types.d.ts +3 -0
  65. package/cjs/adapter-next/code/index.d.ts +3 -0
  66. package/cjs/adapter-next/code/next-redirects.d.ts +3 -0
  67. package/cjs/adapter-next/code/next-rewrites.d.ts +3 -0
  68. package/cjs/adapter-next/code/useCurrentLocalisedPathnames.d.ts +2 -0
  69. package/cjs/adapter-next/code/useLocale.d.ts +3 -0
  70. package/cjs/adapter-next/code/useRouteId.d.ts +2 -0
  71. package/cjs/adapter-next/code/useTo.d.ts +2 -0
  72. package/cjs/adapter-next/code/useToSpa.d.ts +2 -0
  73. package/cjs/adapter-next/plugin-async.d.ts +9 -0
  74. package/cjs/adapter-next/plugin-legacy.d.ts +22 -0
  75. package/cjs/adapter-next/plugin-shared.d.ts +13 -0
  76. package/cjs/adapter-next/plugin.d.ts +7 -0
  77. package/cjs/adapter-next/redirects.d.ts +4 -0
  78. package/cjs/adapter-next/rewrites.d.ts +4 -0
  79. package/cjs/adapter-next/transformPathname.d.ts +1 -0
  80. package/cjs/adapter-next/webpackPluginI18n.d.ts +7 -0
  81. package/cjs/adapter-next-translate/code/DynamicNamespaces.d.ts +2 -0
  82. package/cjs/adapter-next-translate/code/T.d.ts +2 -0
  83. package/cjs/adapter-next-translate/code/TransText.d.ts +2 -0
  84. package/cjs/adapter-next-translate/code/getT.d.ts +2 -0
  85. package/cjs/adapter-next-translate/code/index.d.ts +3 -0
  86. package/cjs/adapter-next-translate/code/nextTranslateI18n.d.ts +3 -0
  87. package/cjs/adapter-next-translate/code/useT.d.ts +2 -0
  88. package/cjs/client/formatRoutePathname.d.ts +4 -0
  89. package/cjs/client/index.d.ts +3 -0
  90. package/cjs/client/interpolateTo.d.ts +4 -0
  91. package/cjs/client/routeHasDynamicPortion.d.ts +2 -0
  92. package/cjs/compiler/api.d.ts +30 -0
  93. package/cjs/compiler/code/data-routes.d.ts +19 -0
  94. package/cjs/compiler/code/data-translations.d.ts +13 -0
  95. package/cjs/compiler/code/data.d.ts +33 -0
  96. package/cjs/compiler/code/generate.d.ts +14 -0
  97. package/cjs/compiler/code/index.d.ts +3 -0
  98. package/cjs/compiler/code/tsCompile.d.ts +2 -0
  99. package/cjs/compiler/code/write.d.ts +11 -0
  100. package/cjs/compiler/config.d.ts +12 -0
  101. package/cjs/compiler/helpers.d.ts +2 -0
  102. package/cjs/compiler/input/data-local.d.ts +4 -0
  103. package/cjs/compiler/input/data-remote.d.ts +7 -0
  104. package/cjs/compiler/input/data.d.ts +4 -0
  105. package/cjs/compiler/input/index.d.ts +4 -0
  106. package/cjs/compiler/input/types.d.ts +14 -0
  107. package/cjs/compiler/input/write.d.ts +8 -0
  108. package/cjs/compiler/pluralisation.d.ts +37 -0
  109. package/cjs/compiler/summary/data.d.ts +6 -0
  110. package/cjs/compiler/summary/generate.d.ts +4 -0
  111. package/cjs/compiler/summary/index.d.ts +3 -0
  112. package/cjs/compiler/summary/write.d.ts +10 -0
  113. package/cjs/compiler/types.d.ts +82 -0
  114. package/cjs/compiler-sync.d.ts +4 -0
  115. package/cjs/compiler-worker.d.ts +1 -0
  116. package/cjs/compiler.d.ts +2 -0
  117. package/cjs/i18n/actions/helpers-git.js +45 -0
  118. package/cjs/i18n/actions/helpers-i18n.js +27 -0
  119. package/cjs/i18n/actions/i18n.js +17 -0
  120. package/cjs/i18n/adapter-js/code/config.cjs.js +14 -0
  121. package/cjs/i18n/adapter-js/code/config.js +14 -0
  122. package/cjs/i18n/adapter-js/code/defaultLocale.js +7 -0
  123. package/cjs/i18n/adapter-js/code/deriveLocalisedPathnames.js +78 -0
  124. package/cjs/i18n/adapter-js/code/index.js +123 -0
  125. package/cjs/i18n/adapter-js/code/isLocale.js +9 -0
  126. package/cjs/i18n/adapter-js/code/locales.js +8 -0
  127. package/cjs/i18n/adapter-js/code/pathnameToRouteId.js +20 -0
  128. package/cjs/i18n/adapter-js/code/routes.js +11 -0
  129. package/cjs/i18n/adapter-js/code/routesSlim.js +11 -0
  130. package/cjs/i18n/adapter-js/code/routesSpa.js +11 -0
  131. package/cjs/i18n/adapter-js/code/tFns.js +34 -0
  132. package/cjs/i18n/adapter-js/code/tInterpolateParams.js +18 -0
  133. package/cjs/i18n/adapter-js/code/tPluralise.js +10 -0
  134. package/cjs/i18n/adapter-js/code/to.js +32 -0
  135. package/cjs/i18n/adapter-js/code/toFns.js +25 -0
  136. package/cjs/i18n/adapter-js/code/toFormat.js +56 -0
  137. package/cjs/i18n/adapter-js/code/toSpa.js +42 -0
  138. package/cjs/i18n/adapter-js/code/types.js +327 -0
  139. package/cjs/i18n/adapter-next/code/index.js +54 -0
  140. package/cjs/i18n/adapter-next/code/next-redirects.js +5 -0
  141. package/cjs/i18n/adapter-next/code/next-rewrites.js +5 -0
  142. package/cjs/i18n/adapter-next/code/useCurrentLocalisedPathnames.js +20 -0
  143. package/cjs/i18n/adapter-next/code/useLocale.js +8 -0
  144. package/cjs/i18n/adapter-next/code/useRouteId.js +10 -0
  145. package/cjs/i18n/adapter-next/code/useTo.js +26 -0
  146. package/cjs/i18n/adapter-next/code/useToSpa.js +34 -0
  147. package/cjs/i18n/adapter-next/plugin-async.js +11 -0
  148. package/{next.esm.js → cjs/i18n/adapter-next/plugin-legacy.js} +9 -85
  149. package/cjs/i18n/adapter-next/plugin-shared.js +39 -0
  150. package/cjs/i18n/adapter-next/plugin.js +13 -0
  151. package/cjs/i18n/adapter-next/redirects.js +51 -0
  152. package/cjs/i18n/adapter-next/rewrites.js +50 -0
  153. package/cjs/i18n/adapter-next/transformPathname.js +3 -0
  154. package/cjs/i18n/adapter-next/webpackPluginI18n.js +11 -0
  155. package/cjs/i18n/adapter-next-translate/code/DynamicNamespaces.js +9 -0
  156. package/cjs/i18n/adapter-next-translate/code/T.js +31 -0
  157. package/cjs/i18n/adapter-next-translate/code/TransText.js +9 -0
  158. package/cjs/i18n/adapter-next-translate/code/getT.js +15 -0
  159. package/cjs/i18n/adapter-next-translate/code/index.js +49 -0
  160. package/cjs/i18n/adapter-next-translate/code/nextTranslateI18n.js +19 -0
  161. package/cjs/i18n/adapter-next-translate/code/useT.js +43 -0
  162. package/{formatRoutePathname.esm.js → cjs/i18n/client/formatRoutePathname.js} +2 -3
  163. package/cjs/i18n/client/index.js +3 -0
  164. package/cjs/i18n/client/interpolateTo.js +14 -0
  165. package/cjs/i18n/client/routeHasDynamicPortion.js +2 -0
  166. package/cjs/i18n/compiler/api.js +18 -0
  167. package/cjs/i18n/compiler/code/data-routes.js +99 -0
  168. package/cjs/i18n/compiler/code/data-translations.js +86 -0
  169. package/cjs/i18n/compiler/code/data.js +20 -0
  170. package/cjs/i18n/compiler/code/generate.js +46 -0
  171. package/cjs/i18n/compiler/code/index.js +2 -0
  172. package/cjs/i18n/compiler/code/tsCompile.js +27 -0
  173. package/cjs/i18n/compiler/code/write.js +39 -0
  174. package/cjs/i18n/compiler/config.js +13 -0
  175. package/cjs/i18n/compiler/helpers.js +14 -0
  176. package/cjs/i18n/compiler/input/data-local.js +60 -0
  177. package/cjs/i18n/compiler/input/data-remote.js +41 -0
  178. package/cjs/i18n/compiler/input/data.js +11 -0
  179. package/cjs/i18n/compiler/input/index.js +3 -0
  180. package/cjs/i18n/compiler/input/types.js +1 -0
  181. package/cjs/i18n/compiler/input/write.js +15 -0
  182. package/cjs/i18n/compiler/pluralisation.js +59 -0
  183. package/cjs/i18n/compiler/summary/data.js +28 -0
  184. package/cjs/i18n/compiler/summary/generate.js +27 -0
  185. package/cjs/i18n/compiler/summary/index.js +2 -0
  186. package/cjs/i18n/compiler/summary/write.js +18 -0
  187. package/cjs/i18n/compiler/types.js +1 -0
  188. package/cjs/i18n/compiler-sync.js +2 -0
  189. package/cjs/i18n/compiler-worker.js +3 -0
  190. package/cjs/i18n/compiler.js +1 -0
  191. package/cjs/i18n/index.js +2 -0
  192. package/cjs/i18n/next.js +3 -0
  193. package/cjs/i18n/types.js +1 -0
  194. package/cjs/index.d.ts +2 -0
  195. package/cjs/next.d.ts +3 -0
  196. package/cjs/package.json +34 -0
  197. package/cjs/types.d.ts +48 -0
  198. package/client/formatRoutePathname.js +3 -7
  199. package/client/interpolateTo.js +12 -35
  200. package/client/routeHasDynamicPortion.js +1 -1
  201. package/compiler/api.js +17 -22
  202. package/compiler/code/data-routes.js +73 -148
  203. package/compiler/code/data-translations.js +68 -130
  204. package/compiler/code/data.js +17 -19
  205. package/compiler/code/generate.js +43 -70
  206. package/compiler/code/index.js +0 -1
  207. package/compiler/code/tsCompile.js +26 -39
  208. package/compiler/code/write.js +36 -75
  209. package/compiler/config.js +9 -10
  210. package/compiler/helpers.js +14 -19
  211. package/compiler/input/data-local.js +52 -62
  212. package/compiler/input/data-remote.js +32 -56
  213. package/compiler/input/data.js +9 -15
  214. package/compiler/input/index.js +0 -1
  215. package/compiler/input/types.js +1 -1
  216. package/compiler/input/write.js +10 -10
  217. package/compiler/pluralisation.js +48 -56
  218. package/compiler/summary/data.js +22 -49
  219. package/compiler/summary/generate.js +26 -72
  220. package/compiler/summary/index.js +1 -1
  221. package/compiler/summary/write.js +16 -26
  222. package/compiler/types.js +1 -1
  223. package/compiler-sync.js +2 -3
  224. package/compiler-worker.js +3 -3
  225. package/compiler.js +1 -1
  226. package/next.js +2 -2
  227. package/package.json +305 -22
  228. package/types.js +1 -1
  229. package/README.md +0 -1
  230. package/api.cjs.js +0 -1839
  231. package/api.esm.js +0 -1815
  232. package/compiler-sync.cjs.d.ts +0 -1
  233. package/compiler-sync.cjs.default.js +0 -1
  234. package/compiler-sync.cjs.js +0 -9
  235. package/compiler-sync.cjs.mjs +0 -2
  236. package/compiler-sync.esm.js +0 -5
  237. package/compiler-worker.cjs.d.ts +0 -1
  238. package/compiler-worker.cjs.default.js +0 -1
  239. package/compiler-worker.cjs.js +0 -17
  240. package/compiler-worker.cjs.mjs +0 -2
  241. package/compiler-worker.esm.js +0 -15
  242. package/compiler.cjs.d.ts +0 -1
  243. package/compiler.cjs.default.js +0 -1
  244. package/compiler.cjs.js +0 -20
  245. package/compiler.cjs.mjs +0 -2
  246. package/compiler.esm.js +0 -12
  247. package/formatRoutePathname.cjs.js +0 -8
  248. package/index.cjs.d.ts +0 -1
  249. package/index.cjs.default.js +0 -1
  250. package/index.cjs.js +0 -24
  251. package/index.cjs.mjs +0 -2
  252. package/index.esm.js +0 -19
  253. package/next.cjs.d.ts +0 -1
  254. package/next.cjs.default.js +0 -1
  255. package/next.cjs.js +0 -287
  256. 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
+ };
@@ -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: ${config.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: ${config.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 = "${config.defaultLocale}";
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
+ `);
@@ -1,57 +1,123 @@
1
- import config from "./config";
2
- import configCjs from "./config.cjs";
3
- import defaultLocale from "./defaultLocale";
4
- import deriveLocalisedPathnames from "./deriveLocalisedPathnames";
5
- import isLocale from "./isLocale";
6
- import locales from "./locales";
7
- import pathnameToRouteId from "./pathnameToRouteId";
8
- import routes from "./routes";
9
- import routesSlim from "./routesSlim";
10
- import routesSpa from "./routesSpa";
11
- import tFns from "./tFns";
12
- import tInterpolateParams from "./tInterpolateParams";
13
- import tPluralise from "./tPluralise";
14
- import to from "./to";
15
- import toFns from "./toFns";
16
- import toFormat from "./toFormat";
17
- import toSpa from "./toSpa";
18
- import types from "./types";
19
- const adapter = () => {
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
- { name: "config.cjs", fn: configCjs, ext: "js" },
23
- { name: "config", fn: config, ext: "ts", index: true },
24
- { name: "defaultLocale", fn: defaultLocale, ext: "ts", index: true },
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: deriveLocalisedPathnames,
40
+ fn: m,
41
+ ext: "ts",
42
+ index: !0
43
+ },
44
+ {
45
+ name: "isLocale",
46
+ fn: n,
28
47
  ext: "ts",
29
- index: true,
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: pathnameToRouteId,
58
+ fn: a,
36
59
  ext: "ts",
37
- index: true,
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: tInterpolateParams,
46
- ext: "ts",
47
- },
48
- { name: "to", fn: to, ext: "ts", index: true },
49
- { name: "toFns", fn: toFns, ext: "ts", index: true },
50
- { name: "toFormat", fn: toFormat, ext: "ts", index: true },
51
- { name: "toSpa", fn: toSpa, ext: "ts", index: true },
52
- { name: "tPluralise", fn: tPluralise, ext: "ts" },
53
- { name: "types", fn: types, ext: "ts", index: true },
54
- ],
55
- };
56
- };
57
- export default adapter;
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
- const value = `[${config.locales.map((l) => `"${l}"`).join(", ")}]`;
1
+ export default (({ config: e })=>{
2
+ let l = `[${e.locales.map((e)=>`"${e}"`).join(", ")}]`;
3
3
  return `
4
- export const locales = ${value} as const;
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
- const { idDelimiter, optionalCatchAll, catchAll } = options.routes.tokens;
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, "${idDelimiter}")
14
- .replace(/${escapeRegExp(idDelimiter)}${escapeRegExp(optionalCatchAll.start)}.+$/, "")
15
- .replace(/${escapeRegExp(idDelimiter)}${escapeRegExp(catchAll.start)}.+$/, "")
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
- const value = JSON.stringify(Object.fromEntries(Object.entries(routes.byId)
3
- .map(([routeId, { pathnames }]) => [routeId, pathnames])
4
- .sort()), null, 2);
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 = ${value} as const;
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
- const value = JSON.stringify(Object.fromEntries(Object.entries(routes.byId)
3
- .map(([routeId, { pathnamesSlim, pathnames }]) => [
4
- routeId,
5
- pathnamesSlim || pathnames,
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 = ${value} as const;
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
- const value = JSON.stringify(Object.fromEntries(Object.entries(routes.byId)
3
- .filter(([, { pathnamesSpa }]) => !!pathnamesSpa)
4
- .map(([routeId, { pathnamesSpa }]) => [routeId, pathnamesSpa])
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 = ${value} as const;
7
+ export const routesSpa = ${e} as const;
8
8
 
9
9
  export default routesSpa;
10
10
  `;
11
- };
11
+ });
@@ -1,33 +1,15 @@
1
- import { areEqual, isArray, isBoolean, isNumber, isPrimitive, isString, } from "@koine/utils";
2
- import { dataParamsToTsInterfaceBody } from "../../compiler/helpers";
3
- const getTranslationValueOutput = (value) => {
4
- if (isString(value) || isNumber(value)) {
5
- return `"${value}"`;
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
- else if (isBoolean(value)) {
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
- const areEqualTranslationsValues = (a, b) => areEqual(a, b);
16
- const getFunctionBodyWithLocales = (config, perLocaleValues) => {
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 (const translationId in translations) {
39
- let { values, params, plural } = translations[translationId];
40
- const name = `${options.translations.fnsPrefix}${translationId}`;
41
- if (plural) {
42
- if (params) {
43
- params["count"] = "number";
44
- }
45
- else {
46
- params = { count: "number" };
47
- }
48
- }
49
- const argParam = params
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 output;
75
- };
33
+ return l;
34
+ });
@@ -1,9 +1,6 @@
1
- const escapeEachChar = (input) => input
2
- .split("")
3
- .map((v) => `\\${v}`)
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
- /${escapeEachChar(start)}(.*?)${escapeEachChar(end)}/g,
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
+ `);
@@ -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]) || "${config.defaultLocale}";
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>)["${config.defaultLocale}"] ??
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
+ `);