i18n-keyless-node 1.15.1 → 1.15.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 +2 -2
- package/dist/service.js +12 -1
- package/package.json +2 -2
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18n-keyless-node",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.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.15.
|
|
18
|
+
"i18n-keyless-core": "1.15.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@eslint/js": "^9.9.0",
|
package/dist/service.js
CHANGED
|
@@ -165,6 +165,7 @@ async function awaitForTranslationFn(key, currentLanguage, options) {
|
|
|
165
165
|
const uniqueId = store.uniqueId;
|
|
166
166
|
const context = options?.context;
|
|
167
167
|
const debug = options?.debug;
|
|
168
|
+
const replace = options?.replace;
|
|
168
169
|
try {
|
|
169
170
|
// Ensure config is initialized enough for either API call or custom handler
|
|
170
171
|
if (!config.API_KEY && !config.handleTranslate) {
|
|
@@ -193,7 +194,17 @@ async function awaitForTranslationFn(key, currentLanguage, options) {
|
|
|
193
194
|
if (lastUsedAt !== newLastUsedAt) {
|
|
194
195
|
sendTranslationsUsageToI18nKeyless();
|
|
195
196
|
}
|
|
196
|
-
|
|
197
|
+
if (!replace) {
|
|
198
|
+
return translation;
|
|
199
|
+
}
|
|
200
|
+
// Create a regex that matches all keys to replace
|
|
201
|
+
// Escape special regex characters in keys
|
|
202
|
+
const pattern = Object.keys(replace)
|
|
203
|
+
.map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
204
|
+
.join("|");
|
|
205
|
+
const regex = new RegExp(pattern, "g");
|
|
206
|
+
// Replace all occurrences in a single pass
|
|
207
|
+
return translation.replace(regex, (matched) => replace[matched] || matched);
|
|
197
208
|
}
|
|
198
209
|
// Use custom handler if provided
|
|
199
210
|
if (config.handleTranslate) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18n-keyless-node",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.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.15.
|
|
18
|
+
"i18n-keyless-core": "1.15.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@eslint/js": "^9.9.0",
|