@koine/i18n 2.0.0-beta.170 → 2.0.0-beta.172

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.
@@ -49,9 +49,12 @@ export function createT<TDictionary extends I18nUtils.TranslationsDictionaryLoos
49
49
  (typeof value === "object" && !Object.keys(value).length) ||
50
50
  (Array.isArray(value) && !value.length)
51
51
  ) {
52
- return typeof fallback !== "undefined"
53
- ? fallback
54
- : ${"key" === a ? "trace" : '""'} as TReturn;
52
+ return (
53
+ query === ""
54
+ ? value || ""
55
+ : typeof fallback !== "undefined"
56
+ ? fallback
57
+ : ${"key" === a ? "trace" : 'value || ""'}) as TReturn;
55
58
  }
56
59
 
57
60
  return (query ? i18nInterpolateParamsDeep(value, query) : value) as TReturn;
@@ -98,7 +101,7 @@ function getPluralisedKey(
98
101
  }
99
102
 
100
103
  if (getValue(dic, key + "${n}" + count) !== undefined) {
101
- return key + "." + count;
104
+ return key + "${n}" + count;
102
105
  }
103
106
 
104
107
  const nestedKey = key + "${n}" + pluralRules.select(count);
@@ -47,9 +47,12 @@ export function createT<TDictionary extends I18nUtils.TranslationsDictionaryLoos
47
47
  (typeof value === "object" && !Object.keys(value).length) ||
48
48
  (Array.isArray(value) && !value.length)
49
49
  ) {
50
- return typeof fallback !== "undefined"
51
- ? fallback
52
- : ${"key" === a ? "trace" : '""'} as TReturn;
50
+ return (
51
+ query === ""
52
+ ? value || ""
53
+ : typeof fallback !== "undefined"
54
+ ? fallback
55
+ : ${"key" === a ? "trace" : 'value || ""'}) as TReturn;
53
56
  }
54
57
 
55
58
  return (query ? i18nInterpolateParamsDeep(value, query) : value) as TReturn;
@@ -96,7 +99,7 @@ function getPluralisedKey(
96
99
  }
97
100
 
98
101
  if (getValue(dic, key + "${n}" + count) !== undefined) {
99
- return key + "." + count;
102
+ return key + "${n}" + count;
100
103
  }
101
104
 
102
105
  const nestedKey = key + "${n}" + pluralRules.select(count);
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  "node": "^14.18.0 || >=16.0.0"
6
6
  },
7
7
  "dependencies": {
8
- "@koine/node": "2.0.0-beta.170",
9
- "@koine/utils": "2.0.0-beta.170",
8
+ "@koine/node": "2.0.0-beta.172",
9
+ "@koine/utils": "2.0.0-beta.172",
10
10
  "comment-json": "^4.2.4",
11
11
  "consola": "^3.2.3",
12
12
  "glob": "^11.0.0",
@@ -110,5 +110,5 @@
110
110
  "module": "./index.esm.js",
111
111
  "main": "./index.cjs.js",
112
112
  "types": "./index.esm.d.ts",
113
- "version": "2.0.0-beta.170"
113
+ "version": "2.0.0-beta.172"
114
114
  }
package/types.d.ts CHANGED
@@ -1,10 +1,15 @@
1
1
  import type { JsonObject, Split } from "@koine/utils";
2
2
  export declare namespace I18nUtils {
3
3
  /**
4
- * Generic shape of a translation dictionary, simple a whatever valid JSON
4
+ * Generic shape of a translation dictionary, simply a whatever valid JSON
5
5
  * ready object
6
6
  */
7
7
  export type TranslationsDictionaryLoose = JsonObject;
8
+ /**
9
+ * Generic shape of a series of namespaced translation dictionaries
10
+ * {@link TranslationsDictionaryLoose}
11
+ */
12
+ export type TranslationsDictionaries = Record<string, TranslationsDictionaryLoose>;
8
13
  /**
9
14
  * Translate function _loose_ type, to use only in implementations that uses
10
15
  * the `t` function indirectly without needng knowledge of the string it needs
@@ -16,6 +21,20 @@ export declare namespace I18nUtils {
16
21
  * array or whatever basically.
17
22
  */
18
23
  export type TranslateLoosest<TReturn = any> = (path?: any, query?: TranslateQuery, fallback?: any) => TReturn;
24
+ /**
25
+ * Query object to populate the translation returned value interpolating
26
+ * dynamic data.
27
+ *
28
+ * Passing a `string` acts as _fallback_ value. If you need a fallback of
29
+ * a different type or need both the _query_ and the _fallback_ use the third
30
+ * argument to provide the fallback instead.
31
+ *
32
+ * All falsy allowed values are for ease of use of the third argument and
33
+ * they will just opt out of any interpolation step.
34
+ */
35
+ export type TranslateQuery = "" | undefined | null | 0 | false | {
36
+ [key: string]: string | number | boolean;
37
+ };
19
38
  /**
20
39
  * Dictionary to generate SEO friendly alternate URLs `<links>` where:
21
40
  *