i18n-keyless-node 1.17.1 → 1.17.2

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.
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "i18n-keyless-node",
3
3
  "private": false,
4
- "version": "1.17.1",
4
+ "version": "1.17.2",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "postpublish": "rm -rf ./dist && rm *.tgz"
16
16
  },
17
17
  "dependencies": {
18
- "i18n-keyless-core": "1.17.1"
18
+ "i18n-keyless-core": "1.17.2"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@eslint/js": "^9.9.0",
package/dist/service.js CHANGED
@@ -182,11 +182,18 @@ async function awaitForTranslationFn(key, currentLanguage, options) {
182
182
  const translationKey = context ? `${key}__${context}` : key;
183
183
  const lastUsedAt = store.translationsUsage[translationKey];
184
184
  const newLastUsedAt = new Date().toISOString().split("T")[0];
185
+ if (debug) {
186
+ console.log("i18n-keyless: lastUsedAt", lastUsedAt);
187
+ console.log("i18n-keyless: newLastUsedAt", newLastUsedAt);
188
+ }
185
189
  if (lastUsedAt !== newLastUsedAt) {
186
190
  store.translationsUsage[translationKey] = newLastUsedAt;
187
191
  }
188
192
  // Safe navigation for potentially undefined language store
189
193
  const translation = translations[currentLanguage]?.[translationKey];
194
+ if (debug) {
195
+ console.log("i18n-keyless: translation", translation);
196
+ }
190
197
  // Return existing translation if found and not forced temporary
191
198
  if (translation && !forceTemporaryLang) {
192
199
  if (debug) {
@@ -273,7 +280,17 @@ async function awaitForTranslationFn(key, currentLanguage, options) {
273
280
  if (debug && !fetchedTranslation) {
274
281
  console.log(`i18n-keyless: Translation for lang "${currentLanguage}" not found in API response for key "${key}". Returning original key.`);
275
282
  }
276
- return fetchedTranslation || key;
283
+ if (!replace) {
284
+ return fetchedTranslation || key;
285
+ }
286
+ // Create a regex that matches all keys to replace
287
+ // Escape special regex characters in keys
288
+ const pattern = Object.keys(replace)
289
+ .map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
290
+ .join("|");
291
+ const regex = new RegExp(pattern, "g");
292
+ // Replace all occurrences in a single pass
293
+ return translation.replace(regex, (matched) => replace[matched] || matched);
277
294
  }
278
295
  catch (error) {
279
296
  // Log the specific error during translation attempt
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "i18n-keyless-node",
3
3
  "private": false,
4
- "version": "1.17.1",
4
+ "version": "1.17.2",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "postpublish": "rm -rf ./dist && rm *.tgz"
16
16
  },
17
17
  "dependencies": {
18
- "i18n-keyless-core": "1.17.1"
18
+ "i18n-keyless-core": "1.17.2"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@eslint/js": "^9.9.0",