@digitaldefiance/i18n-lib 1.0.30 → 1.0.32

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.
@@ -107,17 +107,27 @@ class I18nEngine {
107
107
  const fallback = fallbackLanguage ?? this.config.defaultLanguage;
108
108
  try {
109
109
  const stringValue = this.getString(lang, key);
110
- return (0, utils_1.isTemplate)(key)
110
+ let result = (0, utils_1.isTemplate)(key)
111
111
  ? (0, utils_1.replaceVariables)(stringValue, vars, this.config.constants)
112
112
  : stringValue;
113
+ // Ensure result is always a string
114
+ if (typeof result !== 'string') {
115
+ result = String(result);
116
+ }
117
+ return result;
113
118
  }
114
119
  catch {
115
120
  if (lang !== fallback) {
116
121
  try {
117
122
  const stringValue = this.getString(fallback, key);
118
- return (0, utils_1.isTemplate)(key)
123
+ let result = (0, utils_1.isTemplate)(key)
119
124
  ? (0, utils_1.replaceVariables)(stringValue, vars, this.config.constants)
120
125
  : stringValue;
126
+ // Ensure result is always a string
127
+ if (typeof result !== 'string') {
128
+ result = String(result);
129
+ }
130
+ return result;
121
131
  }
122
132
  catch {
123
133
  return String(key);
@@ -159,9 +169,14 @@ class I18nEngine {
159
169
  if (!strings?.[key])
160
170
  return String(key);
161
171
  const stringValue = strings[key];
162
- return (0, utils_1.isTemplate)(key)
172
+ let result = (0, utils_1.isTemplate)(key)
163
173
  ? (0, utils_1.replaceVariables)(stringValue, vars, this.config.constants)
164
174
  : stringValue;
175
+ // Ensure result is always a string
176
+ if (typeof result !== 'string') {
177
+ result = String(result);
178
+ }
179
+ return result;
165
180
  }
166
181
  catch {
167
182
  return String(key);
package/dist/utils.js CHANGED
@@ -21,6 +21,10 @@ const moment_timezone_1 = __importDefault(require("moment-timezone"));
21
21
  * @returns The string with variables replaced
22
22
  */
23
23
  function replaceVariables(str, vars, constants) {
24
+ // Ensure input is a string
25
+ if (typeof str !== 'string') {
26
+ str = String(str);
27
+ }
24
28
  const variables = str.match(/\{(.+?)\}/g);
25
29
  if (!variables)
26
30
  return str;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/i18n-lib",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Generic i18n library with enum translation support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",