@digitaldefiance/i18n-lib 1.0.31 → 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,19 +107,27 @@ class I18nEngine {
107
107
  const fallback = fallbackLanguage ?? this.config.defaultLanguage;
108
108
  try {
109
109
  const stringValue = this.getString(lang, key);
110
- const result = (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
- return typeof result === 'string' ? result : String(result);
113
+ // Ensure result is always a string
114
+ if (typeof result !== 'string') {
115
+ result = String(result);
116
+ }
117
+ return result;
114
118
  }
115
119
  catch {
116
120
  if (lang !== fallback) {
117
121
  try {
118
122
  const stringValue = this.getString(fallback, key);
119
- const result = (0, utils_1.isTemplate)(key)
123
+ let result = (0, utils_1.isTemplate)(key)
120
124
  ? (0, utils_1.replaceVariables)(stringValue, vars, this.config.constants)
121
125
  : stringValue;
122
- return typeof result === 'string' ? result : String(result);
126
+ // Ensure result is always a string
127
+ if (typeof result !== 'string') {
128
+ result = String(result);
129
+ }
130
+ return result;
123
131
  }
124
132
  catch {
125
133
  return String(key);
@@ -161,10 +169,14 @@ class I18nEngine {
161
169
  if (!strings?.[key])
162
170
  return String(key);
163
171
  const stringValue = strings[key];
164
- const result = (0, utils_1.isTemplate)(key)
172
+ let result = (0, utils_1.isTemplate)(key)
165
173
  ? (0, utils_1.replaceVariables)(stringValue, vars, this.config.constants)
166
174
  : stringValue;
167
- return typeof result === 'string' ? result : String(result);
175
+ // Ensure result is always a string
176
+ if (typeof result !== 'string') {
177
+ result = String(result);
178
+ }
179
+ return result;
168
180
  }
169
181
  catch {
170
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.31",
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",