@koine/i18n 2.0.0-beta.92 → 2.0.0-beta.93

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 (3) hide show
  1. package/api.cjs.js +23 -17
  2. package/api.esm.js +23 -17
  3. package/package.json +3 -3
package/api.cjs.js CHANGED
@@ -180,7 +180,7 @@ export function createT<TNamespace extends I18n.TranslateNamespace>(
180
180
  const k = Array.isArray(key) ? key[0] : key;
181
181
  const [namespace, i18nKey] = k.split("${n.translations.tokens.namespaceDelimiter}");
182
182
  const dic = (namespace && dictionaries[namespace]) || {};
183
- const pluralisedKey = plural(pluralRules, dic, i18nKey, query, options);
183
+ const pluralisedKey = getPluralisedKey(pluralRules, dic, i18nKey, query, options);
184
184
  const dicValue = getDicValue(dic, pluralisedKey, query, options);
185
185
  const value =
186
186
  typeof dicValue === "object"
@@ -251,7 +251,7 @@ function getDicValue(
251
251
  /**
252
252
  * Control plural keys depending the {{count}} variable
253
253
  */
254
- function plural(
254
+ function getPluralisedKey(
255
255
  pluralRules: Intl.PluralRules,
256
256
  dic: I18n.TranslationsDictionaryLoose,
257
257
  key: string,
@@ -431,6 +431,7 @@ export function getAlternates<TRouteId extends I18n.RouteId>({
431
431
  id,
432
432
  params,
433
433
  }: GetAlternatesOptions<TRouteId>) {
434
+ // TODO: i18n maybe handle error routes
434
435
  // if (id === "404" || id === "500") return {};
435
436
 
436
437
  const alternates: I18n.Alternates = {
@@ -515,7 +516,7 @@ export async function getI18nDictionaries({
515
516
  export default getI18nDictionaries;
516
517
  `);
517
518
 
518
- var x$5 = (({})=>`
519
+ var x$4 = (({})=>`
519
520
  import { createT } from "./createT";
520
521
  import { loadTranslations } from "./loadTranslations";
521
522
  import type { I18n } from "./types";
@@ -1045,7 +1046,7 @@ let c$2 = (e, a)=>!utils.isArray(a) && utils.isObject(a) && hasPlurals(a) ? hasO
1045
1046
  s.push(`"${o}": { ${l.join(" ")} }`);
1046
1047
  }
1047
1048
  return s;
1048
- }, x$4 = (e, t)=>{
1049
+ }, b = (e, t)=>{
1049
1050
  let a = [];
1050
1051
  for(let n in t.byId){
1051
1052
  let s = t.byId[n];
@@ -1107,7 +1108,7 @@ export namespace I18n {
1107
1108
  * Map every route id to its actual pathanem value for the default locale
1108
1109
  */
1109
1110
  export type RoutePathnames = {
1110
- ${x$4(e, a).join("\n ")}
1111
+ ${b(e, a).join("\n ")}
1111
1112
  }
1112
1113
 
1113
1114
  /**
@@ -1346,6 +1347,7 @@ export namespace I18n {
1346
1347
  : never;
1347
1348
  }
1348
1349
  | {
1350
+ // TODO: i18n maybe handle error routes
1349
1351
  id: TRouteId extends RouteIdStatic/* | "404" | "500" */
1350
1352
  ? TRouteId/* | "404" | "500" */
1351
1353
  : never;
@@ -1429,7 +1431,7 @@ var t$1 = createAdapter(adapterJsOptions, ({})=>({
1429
1431
  },
1430
1432
  {
1431
1433
  name: "getT",
1432
- fn: x$5,
1434
+ fn: x$4,
1433
1435
  ext: "ts",
1434
1436
  index: !0
1435
1437
  },
@@ -1795,9 +1797,11 @@ import type { I18n } from "./types";
1795
1797
  * @internal
1796
1798
  */
1797
1799
  export type I18nAppPropsData = {
1798
- locale: I18n.Locale;
1799
- dictionaries: I18n.Dictionaries;
1800
- alternates: I18n.Alternates;
1800
+ i18n: {
1801
+ locale: I18n.Locale;
1802
+ dictionaries: I18n.Dictionaries;
1803
+ alternates: I18n.Alternates;
1804
+ }
1801
1805
  };
1802
1806
 
1803
1807
  type I18nAppProps = React.PropsWithChildren<
@@ -1823,8 +1827,8 @@ type I18nAppProps = React.PropsWithChildren<
1823
1827
  * \`\`\`
1824
1828
  */
1825
1829
  export const I18nApp = (props: I18nAppProps) => {
1826
-
1827
- const { locale, dictionaries, alternates, children } = props;
1830
+ const { i18n, children } = props;
1831
+ const { locale, dictionaries, alternates } = i18n;
1828
1832
 
1829
1833
  return (
1830
1834
  <I18nProvider
@@ -2046,15 +2050,17 @@ export async function i18nProps<TRouteId extends I18n.RouteId, TParams, TData>({
2046
2050
  params,
2047
2051
  data,
2048
2052
  }: I18nPropsOptions<TRouteId, TParams, TData>) {
2049
- const i18n: I18nAppPropsData = {
2050
- locale: locale,
2051
- // @ts-expect-error FIXME: route conditional type
2052
- alternates: getAlternates({ locale, id: routeId, params: routeParams }),
2053
- dictionaries: await getI18nDictionaries({ locale, namespaces }),
2053
+ const props: I18nAppPropsData = {
2054
+ i18n: {
2055
+ locale: locale,
2056
+ // @ts-expect-error FIXME: route conditional type
2057
+ alternates: getAlternates({ locale, id: routeId, params: routeParams }),
2058
+ dictionaries: await getI18nDictionaries({ locale, namespaces }),
2059
+ }
2054
2060
  }
2055
2061
 
2056
2062
  return {
2057
- i18n,
2063
+ ...props,
2058
2064
  params: ${a ? `{ ${a}: locale, ...(params || ({} as TParams)) }` : "params || ({} as TParams)"},
2059
2065
  data: data || ({} as TData),
2060
2066
  };
package/api.esm.js CHANGED
@@ -158,7 +158,7 @@ export function createT<TNamespace extends I18n.TranslateNamespace>(
158
158
  const k = Array.isArray(key) ? key[0] : key;
159
159
  const [namespace, i18nKey] = k.split("${n.translations.tokens.namespaceDelimiter}");
160
160
  const dic = (namespace && dictionaries[namespace]) || {};
161
- const pluralisedKey = plural(pluralRules, dic, i18nKey, query, options);
161
+ const pluralisedKey = getPluralisedKey(pluralRules, dic, i18nKey, query, options);
162
162
  const dicValue = getDicValue(dic, pluralisedKey, query, options);
163
163
  const value =
164
164
  typeof dicValue === "object"
@@ -229,7 +229,7 @@ function getDicValue(
229
229
  /**
230
230
  * Control plural keys depending the {{count}} variable
231
231
  */
232
- function plural(
232
+ function getPluralisedKey(
233
233
  pluralRules: Intl.PluralRules,
234
234
  dic: I18n.TranslationsDictionaryLoose,
235
235
  key: string,
@@ -409,6 +409,7 @@ export function getAlternates<TRouteId extends I18n.RouteId>({
409
409
  id,
410
410
  params,
411
411
  }: GetAlternatesOptions<TRouteId>) {
412
+ // TODO: i18n maybe handle error routes
412
413
  // if (id === "404" || id === "500") return {};
413
414
 
414
415
  const alternates: I18n.Alternates = {
@@ -493,7 +494,7 @@ export async function getI18nDictionaries({
493
494
  export default getI18nDictionaries;
494
495
  `);
495
496
 
496
- var x$5 = (({})=>`
497
+ var x$4 = (({})=>`
497
498
  import { createT } from "./createT";
498
499
  import { loadTranslations } from "./loadTranslations";
499
500
  import type { I18n } from "./types";
@@ -1023,7 +1024,7 @@ let c$2 = (e, a)=>!isArray(a) && isObject(a) && hasPlurals(a) ? hasOnlyPluralKey
1023
1024
  s.push(`"${o}": { ${l.join(" ")} }`);
1024
1025
  }
1025
1026
  return s;
1026
- }, x$4 = (e, t)=>{
1027
+ }, b = (e, t)=>{
1027
1028
  let a = [];
1028
1029
  for(let n in t.byId){
1029
1030
  let s = t.byId[n];
@@ -1085,7 +1086,7 @@ export namespace I18n {
1085
1086
  * Map every route id to its actual pathanem value for the default locale
1086
1087
  */
1087
1088
  export type RoutePathnames = {
1088
- ${x$4(e, a).join("\n ")}
1089
+ ${b(e, a).join("\n ")}
1089
1090
  }
1090
1091
 
1091
1092
  /**
@@ -1324,6 +1325,7 @@ export namespace I18n {
1324
1325
  : never;
1325
1326
  }
1326
1327
  | {
1328
+ // TODO: i18n maybe handle error routes
1327
1329
  id: TRouteId extends RouteIdStatic/* | "404" | "500" */
1328
1330
  ? TRouteId/* | "404" | "500" */
1329
1331
  : never;
@@ -1407,7 +1409,7 @@ var t$1 = createAdapter(adapterJsOptions, ({})=>({
1407
1409
  },
1408
1410
  {
1409
1411
  name: "getT",
1410
- fn: x$5,
1412
+ fn: x$4,
1411
1413
  ext: "ts",
1412
1414
  index: !0
1413
1415
  },
@@ -1773,9 +1775,11 @@ import type { I18n } from "./types";
1773
1775
  * @internal
1774
1776
  */
1775
1777
  export type I18nAppPropsData = {
1776
- locale: I18n.Locale;
1777
- dictionaries: I18n.Dictionaries;
1778
- alternates: I18n.Alternates;
1778
+ i18n: {
1779
+ locale: I18n.Locale;
1780
+ dictionaries: I18n.Dictionaries;
1781
+ alternates: I18n.Alternates;
1782
+ }
1779
1783
  };
1780
1784
 
1781
1785
  type I18nAppProps = React.PropsWithChildren<
@@ -1801,8 +1805,8 @@ type I18nAppProps = React.PropsWithChildren<
1801
1805
  * \`\`\`
1802
1806
  */
1803
1807
  export const I18nApp = (props: I18nAppProps) => {
1804
-
1805
- const { locale, dictionaries, alternates, children } = props;
1808
+ const { i18n, children } = props;
1809
+ const { locale, dictionaries, alternates } = i18n;
1806
1810
 
1807
1811
  return (
1808
1812
  <I18nProvider
@@ -2024,15 +2028,17 @@ export async function i18nProps<TRouteId extends I18n.RouteId, TParams, TData>({
2024
2028
  params,
2025
2029
  data,
2026
2030
  }: I18nPropsOptions<TRouteId, TParams, TData>) {
2027
- const i18n: I18nAppPropsData = {
2028
- locale: locale,
2029
- // @ts-expect-error FIXME: route conditional type
2030
- alternates: getAlternates({ locale, id: routeId, params: routeParams }),
2031
- dictionaries: await getI18nDictionaries({ locale, namespaces }),
2031
+ const props: I18nAppPropsData = {
2032
+ i18n: {
2033
+ locale: locale,
2034
+ // @ts-expect-error FIXME: route conditional type
2035
+ alternates: getAlternates({ locale, id: routeId, params: routeParams }),
2036
+ dictionaries: await getI18nDictionaries({ locale, namespaces }),
2037
+ }
2032
2038
  }
2033
2039
 
2034
2040
  return {
2035
- i18n,
2041
+ ...props,
2036
2042
  params: ${a ? `{ ${a}: locale, ...(params || ({} as TParams)) }` : "params || ({} as TParams)"},
2037
2043
  data: data || ({} as TData),
2038
2044
  };
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@koine/i18n",
3
3
  "sideEffects": false,
4
4
  "dependencies": {
5
- "@koine/node": "2.0.0-beta.92",
6
- "@koine/utils": "2.0.0-beta.92",
5
+ "@koine/node": "2.0.0-beta.93",
6
+ "@koine/utils": "2.0.0-beta.93",
7
7
  "glob": "^10.3.10",
8
8
  "webpack": "^5.90.1",
9
9
  "minimatch": "^9.0.3",
@@ -58,5 +58,5 @@
58
58
  },
59
59
  "module": "./index.esm.js",
60
60
  "main": "./index.cjs.js",
61
- "version": "2.0.0-beta.92"
61
+ "version": "2.0.0-beta.93"
62
62
  }