i18n-keyless-core 1.12.0 → 1.12.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 +1 -1
- package/dist/service.d.ts +0 -8
- package/dist/service.js +0 -89
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/service.d.ts
CHANGED
|
@@ -25,11 +25,3 @@ export declare function translateKey(key: string, store: FetchTranslationParams,
|
|
|
25
25
|
* @returns Promise resolving to the translation response or void if failed
|
|
26
26
|
*/
|
|
27
27
|
export declare function getAllTranslationsFromLanguage(targetLanguage: Lang, store: FetchTranslationParams): Promise<I18nKeylessResponse | void>;
|
|
28
|
-
/**
|
|
29
|
-
* Queues a key for translation if not already translated
|
|
30
|
-
* @param key - The text to translate
|
|
31
|
-
* @param store - The translation store
|
|
32
|
-
* @param options - Optional parameters for the translation process
|
|
33
|
-
* @throws Error if config is not initialized
|
|
34
|
-
*/
|
|
35
|
-
export declare const awaitForTranslation: (key: string, store: FetchTranslationParams, options?: TranslationOptions) => Promise<string | null | undefined>;
|
package/dist/service.js
CHANGED
|
@@ -161,92 +161,3 @@ export async function getAllTranslationsFromLanguage(targetLanguage, store) {
|
|
|
161
161
|
console.error("i18n-keyless: fetch all translations error:", error);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Queues a key for translation if not already translated
|
|
166
|
-
* @param key - The text to translate
|
|
167
|
-
* @param store - The translation store
|
|
168
|
-
* @param options - Optional parameters for the translation process
|
|
169
|
-
* @throws Error if config is not initialized
|
|
170
|
-
*/
|
|
171
|
-
export const awaitForTranslation = new Proxy(async function (key, store, options) {
|
|
172
|
-
const currentLanguage = store.currentLanguage;
|
|
173
|
-
const config = store.config;
|
|
174
|
-
const translations = store.translations;
|
|
175
|
-
const uniqueId = store.uniqueId;
|
|
176
|
-
if (!config.API_KEY) {
|
|
177
|
-
throw new Error("i18n-keyless: config is not initialized");
|
|
178
|
-
}
|
|
179
|
-
const context = options?.context;
|
|
180
|
-
const debug = options?.debug;
|
|
181
|
-
// if (key.length > 280) {
|
|
182
|
-
// console.error("i18n-keyless: Key length exceeds 280 characters limit:", key);
|
|
183
|
-
// return;
|
|
184
|
-
// }
|
|
185
|
-
if (!key) {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
if (debug) {
|
|
189
|
-
console.log("translateKey", key, context, debug);
|
|
190
|
-
}
|
|
191
|
-
const forceTemporaryLang = options?.forceTemporary?.[currentLanguage];
|
|
192
|
-
const translation = context ? translations[`${key}__${context}`] : translations[key];
|
|
193
|
-
if (translation && !forceTemporaryLang) {
|
|
194
|
-
if (debug) {
|
|
195
|
-
console.log("translation exists", `${key}__${context}`);
|
|
196
|
-
}
|
|
197
|
-
return translation;
|
|
198
|
-
}
|
|
199
|
-
try {
|
|
200
|
-
if (config.handleTranslate) {
|
|
201
|
-
await config.handleTranslate?.(key);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
const body = {
|
|
205
|
-
key,
|
|
206
|
-
context,
|
|
207
|
-
forceTemporary: options?.forceTemporary,
|
|
208
|
-
languages: config.languages.supported,
|
|
209
|
-
primaryLanguage: config.languages.primary,
|
|
210
|
-
};
|
|
211
|
-
const apiUrl = config.API_URL || "https://api.i18n-keyless.com";
|
|
212
|
-
const url = `${apiUrl}/translate?return_translation=true`;
|
|
213
|
-
if (debug) {
|
|
214
|
-
console.log("fetching translation", url, body);
|
|
215
|
-
}
|
|
216
|
-
const response = await api
|
|
217
|
-
.fetchTranslation(url, {
|
|
218
|
-
method: "POST",
|
|
219
|
-
headers: {
|
|
220
|
-
"Content-Type": "application/json",
|
|
221
|
-
Authorization: `Bearer ${config.API_KEY}`,
|
|
222
|
-
unique_id: uniqueId || "",
|
|
223
|
-
Version: packageJson.version,
|
|
224
|
-
},
|
|
225
|
-
body: JSON.stringify(body),
|
|
226
|
-
})
|
|
227
|
-
.then((res) => res);
|
|
228
|
-
if (debug) {
|
|
229
|
-
console.log("response", response);
|
|
230
|
-
}
|
|
231
|
-
if (response.message) {
|
|
232
|
-
console.warn("i18n-keyless: ", response.message);
|
|
233
|
-
}
|
|
234
|
-
return response.data;
|
|
235
|
-
}
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
238
|
-
catch (error) {
|
|
239
|
-
console.error("i18n-keyless: Error await translating key:", error);
|
|
240
|
-
}
|
|
241
|
-
}, {
|
|
242
|
-
apply(target, thisArg, args) {
|
|
243
|
-
const result = Reflect.apply(target, thisArg, args);
|
|
244
|
-
if (result instanceof Promise) {
|
|
245
|
-
result.catch((error) => {
|
|
246
|
-
console.error("awaitForTranslation was not properly awaited:", error);
|
|
247
|
-
throw error;
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
return result;
|
|
251
|
-
},
|
|
252
|
-
});
|