i18n-keyless-node 1.15.1 → 1.16.0
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 +13 -1
- package/dist/types.d.ts +1 -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.
|
|
4
|
+
"version": "1.16.0",
|
|
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.
|
|
18
|
+
"i18n-keyless-core": "1.16.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@eslint/js": "^9.9.0",
|
package/dist/service.js
CHANGED
|
@@ -16,6 +16,7 @@ const store = {
|
|
|
16
16
|
tr: {},
|
|
17
17
|
ja: {},
|
|
18
18
|
cn: {},
|
|
19
|
+
cz: {},
|
|
19
20
|
ru: {},
|
|
20
21
|
ko: {},
|
|
21
22
|
ar: {},
|
|
@@ -165,6 +166,7 @@ async function awaitForTranslationFn(key, currentLanguage, options) {
|
|
|
165
166
|
const uniqueId = store.uniqueId;
|
|
166
167
|
const context = options?.context;
|
|
167
168
|
const debug = options?.debug;
|
|
169
|
+
const replace = options?.replace;
|
|
168
170
|
try {
|
|
169
171
|
// Ensure config is initialized enough for either API call or custom handler
|
|
170
172
|
if (!config.API_KEY && !config.handleTranslate) {
|
|
@@ -193,7 +195,17 @@ async function awaitForTranslationFn(key, currentLanguage, options) {
|
|
|
193
195
|
if (lastUsedAt !== newLastUsedAt) {
|
|
194
196
|
sendTranslationsUsageToI18nKeyless();
|
|
195
197
|
}
|
|
196
|
-
|
|
198
|
+
if (!replace) {
|
|
199
|
+
return translation;
|
|
200
|
+
}
|
|
201
|
+
// Create a regex that matches all keys to replace
|
|
202
|
+
// Escape special regex characters in keys
|
|
203
|
+
const pattern = Object.keys(replace)
|
|
204
|
+
.map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
205
|
+
.join("|");
|
|
206
|
+
const regex = new RegExp(pattern, "g");
|
|
207
|
+
// Replace all occurrences in a single pass
|
|
208
|
+
return translation.replace(regex, (matched) => replace[matched] || matched);
|
|
197
209
|
}
|
|
198
210
|
// Use custom handler if provided
|
|
199
211
|
if (config.handleTranslate) {
|
package/dist/types.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface I18nKeylessNodeConfig {
|
|
|
31
31
|
/**
|
|
32
32
|
* the languages supported for the user.
|
|
33
33
|
* For now we support:
|
|
34
|
-
* fr, nl, it, de, es, pl, pt, ro, hu, sv, tr, ja, cn, ru, ko, ar
|
|
34
|
+
* fr, nl, it, de, es, pl, pt, ro, hu, sv, tr, ja, cn, cz, ru, ko, ar
|
|
35
35
|
*
|
|
36
36
|
* If you need more, please reach out to @ambroselli_io on X/Twitter or by mail at arnaud.ambroselli.io@gmail.com
|
|
37
37
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18n-keyless-node",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.16.0",
|
|
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.
|
|
18
|
+
"i18n-keyless-core": "1.16.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@eslint/js": "^9.9.0",
|