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