i18n-keyless-node 1.12.2 → 1.12.4
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.d.ts +1 -1
- package/dist/service.js +30 -30
- package/dist/types.d.ts +2 -5
- 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.12.
|
|
4
|
+
"version": "1.12.4",
|
|
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.12.
|
|
18
|
+
"i18n-keyless-core": "1.12.4"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@eslint/js": "^9.9.0",
|
package/dist/service.d.ts
CHANGED
|
@@ -15,4 +15,4 @@ export declare function getTranslation(key: string, currentLanguage: Lang, optio
|
|
|
15
15
|
* @param options - Optional parameters for the translation process
|
|
16
16
|
* @throws Error if config is not initialized
|
|
17
17
|
*/
|
|
18
|
-
export declare const awaitForTranslation: (key: string, currentLanguage: Lang, options?: TranslationOptions) => Promise<string
|
|
18
|
+
export declare const awaitForTranslation: (key: string, currentLanguage: Lang, options?: TranslationOptions) => Promise<string>;
|
package/dist/service.js
CHANGED
|
@@ -121,35 +121,35 @@ export function getTranslation(key, currentLanguage, options) {
|
|
|
121
121
|
* @throws Error if config is not initialized
|
|
122
122
|
*/
|
|
123
123
|
export const awaitForTranslation = new Proxy(async function (key, currentLanguage, options) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
console.log("translateKey", key, context, debug);
|
|
141
|
-
}
|
|
142
|
-
const forceTemporaryLang = options?.forceTemporary?.[currentLanguage];
|
|
143
|
-
const translation = context
|
|
144
|
-
? translations[currentLanguage][`${key}__${context}`]
|
|
145
|
-
: translations[currentLanguage][key];
|
|
146
|
-
if (translation && !forceTemporaryLang) {
|
|
124
|
+
try {
|
|
125
|
+
const config = store.config;
|
|
126
|
+
const translations = store.translations;
|
|
127
|
+
const uniqueId = store.uniqueId;
|
|
128
|
+
if (!config.API_KEY) {
|
|
129
|
+
throw new Error("i18n-keyless: config is not initialized");
|
|
130
|
+
}
|
|
131
|
+
const context = options?.context;
|
|
132
|
+
const debug = options?.debug;
|
|
133
|
+
// if (key.length > 280) {
|
|
134
|
+
// console.error("i18n-keyless: Key length exceeds 280 characters limit:", key);
|
|
135
|
+
// return;
|
|
136
|
+
// }
|
|
137
|
+
if (!key) {
|
|
138
|
+
return "";
|
|
139
|
+
}
|
|
147
140
|
if (debug) {
|
|
148
|
-
console.log("
|
|
141
|
+
console.log("translateKey", key, context, debug);
|
|
142
|
+
}
|
|
143
|
+
const forceTemporaryLang = options?.forceTemporary?.[currentLanguage];
|
|
144
|
+
const translation = context
|
|
145
|
+
? translations[currentLanguage][`${key}__${context}`]
|
|
146
|
+
: translations[currentLanguage][key];
|
|
147
|
+
if (translation && !forceTemporaryLang) {
|
|
148
|
+
if (debug) {
|
|
149
|
+
console.log("translation exists", `${key}__${context}`);
|
|
150
|
+
}
|
|
151
|
+
return translation;
|
|
149
152
|
}
|
|
150
|
-
return translation;
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
153
|
if (config.handleTranslate) {
|
|
154
154
|
await config.handleTranslate?.(key);
|
|
155
155
|
}
|
|
@@ -162,7 +162,7 @@ export const awaitForTranslation = new Proxy(async function (key, currentLanguag
|
|
|
162
162
|
primaryLanguage: config.languages.primary,
|
|
163
163
|
};
|
|
164
164
|
const apiUrl = config.API_URL || "https://api.i18n-keyless.com";
|
|
165
|
-
const url = `${apiUrl}/translate
|
|
165
|
+
const url = `${apiUrl}/translate`;
|
|
166
166
|
if (debug) {
|
|
167
167
|
console.log("fetching translation", url, body);
|
|
168
168
|
}
|
|
@@ -184,13 +184,13 @@ export const awaitForTranslation = new Proxy(async function (key, currentLanguag
|
|
|
184
184
|
if (response.message) {
|
|
185
185
|
console.warn("i18n-keyless: ", response.message);
|
|
186
186
|
}
|
|
187
|
-
return response.data;
|
|
187
|
+
return response.data.translation[currentLanguage] || key;
|
|
188
188
|
}
|
|
189
|
-
return null;
|
|
190
189
|
}
|
|
191
190
|
catch (error) {
|
|
192
191
|
console.error("i18n-keyless: Error await translating key:", error);
|
|
193
192
|
}
|
|
193
|
+
return key;
|
|
194
194
|
}, {
|
|
195
195
|
apply(target, thisArg, args) {
|
|
196
196
|
const result = Reflect.apply(target, thisArg, args);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lang, PrimaryLang } from "i18n-keyless-core";
|
|
1
|
+
import { HandleTranslateFunction, Lang, PrimaryLang } from "i18n-keyless-core";
|
|
2
2
|
export type Translations = Record<string, string>;
|
|
3
3
|
export interface I18nKeylessNodeConfig {
|
|
4
4
|
/**
|
|
@@ -54,10 +54,7 @@ export interface I18nKeylessNodeConfig {
|
|
|
54
54
|
* - not use this `handleTranslate` function, and use the built in API call with API_KEY filled
|
|
55
55
|
* - not use this `handleTranslate` function nor API_KEY key, and provide your own API_URL
|
|
56
56
|
*/
|
|
57
|
-
handleTranslate?:
|
|
58
|
-
ok: boolean;
|
|
59
|
-
message: string;
|
|
60
|
-
}>;
|
|
57
|
+
handleTranslate?: HandleTranslateFunction;
|
|
61
58
|
/**
|
|
62
59
|
* if this function exists, it will be called instead of the API call
|
|
63
60
|
* if this function doesn't exist, the default behavior is to call the API, with the API_KEY
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18n-keyless-node",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.4",
|
|
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.12.
|
|
18
|
+
"i18n-keyless-core": "1.12.4"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@eslint/js": "^9.9.0",
|