azure-translator-code
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -74,29 +74,61 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var translatedJson, _i, _a, _b, jsonKey, jsonValue, response, _c, _d; | ||
return __generator(this, function (_e) { | ||
switch (_e.label) { | ||
var translatedJson, _i, _a, _b, jsonKey, jsonValue, response, translatedArray, _c, jsonValue_1, item, response, _d, _e; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
case 0: | ||
translatedJson = {}; | ||
_i = 0, _a = Object.entries(jsonFile); | ||
_e.label = 1; | ||
_f.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3, 6]; | ||
if (!(_i < _a.length)) return [3, 14]; | ||
_b = _a[_i], jsonKey = _b[0], jsonValue = _b[1]; | ||
if (!(typeof jsonValue === 'string')) return [3, 3]; | ||
if (!(jsonValue === null)) return [3, 2]; | ||
translatedJson[jsonKey] = null; | ||
return [3, 13]; | ||
case 2: | ||
if (!(typeof jsonValue === 'string')) return [3, 4]; | ||
return [4, translateText(jsonValue, fromLang, toLang, endpoint, key, location)]; | ||
case 2: | ||
response = _e.sent(); | ||
case 3: | ||
response = _f.sent(); | ||
translatedJson[jsonKey] = response.data[0].translations[0].text; | ||
return [3, 5]; | ||
case 3: | ||
_c = translatedJson; | ||
_d = jsonKey; | ||
return [4, translate(key, endpoint, location, fromLang, toLang, jsonValue)]; | ||
return [3, 13]; | ||
case 4: | ||
_c[_d] = _e.sent(); | ||
_e.label = 5; | ||
if (!(typeof jsonValue === 'boolean' || typeof jsonValue === 'number')) return [3, 5]; | ||
translatedJson[jsonKey] = jsonValue; | ||
return [3, 13]; | ||
case 5: | ||
if (!Array.isArray(jsonValue)) return [3, 11]; | ||
translatedArray = []; | ||
_c = 0, jsonValue_1 = jsonValue; | ||
_f.label = 6; | ||
case 6: | ||
if (!(_c < jsonValue_1.length)) return [3, 10]; | ||
item = jsonValue_1[_c]; | ||
if (!(typeof item === 'string')) return [3, 8]; | ||
return [4, translateText(item, fromLang, toLang, endpoint, key, location)]; | ||
case 7: | ||
response = _f.sent(); | ||
translatedArray.push(response.data[0].translations[0].text); | ||
return [3, 9]; | ||
case 8: | ||
translatedArray.push(item); | ||
_f.label = 9; | ||
case 9: | ||
_c++; | ||
return [3, 6]; | ||
case 10: | ||
translatedJson[jsonKey] = translatedArray; | ||
return [3, 13]; | ||
case 11: | ||
if (!(typeof jsonValue === 'object' && jsonValue !== null)) return [3, 13]; | ||
_d = translatedJson; | ||
_e = jsonKey; | ||
return [4, translate(key, endpoint, location, fromLang, toLang, jsonValue)]; | ||
case 12: | ||
_d[_e] = _f.sent(); | ||
_f.label = 13; | ||
case 13: | ||
_i++; | ||
return [3, 1]; | ||
case 6: return [2, translatedJson]; | ||
case 14: return [2, translatedJson]; | ||
} | ||
@@ -103,0 +135,0 @@ }); |
{ | ||
"name": "azure-translator-code", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "Azure Cognitive Services Translator Text API Code for Use with Common Languages", | ||
@@ -11,3 +11,3 @@ "author": { | ||
"scripts": { | ||
"test": "jest", | ||
"test": "jest --coverage", | ||
"test:silent": "jest --watchAll --silent --noStackTrace", | ||
@@ -52,2 +52,3 @@ "build:dist": "tsc", | ||
"@typescript-eslint/parser": "^6.7.0", | ||
"dotenv": "^16.4.5", | ||
"eslint": "^8.49.0", | ||
@@ -54,0 +55,0 @@ "eslint-config-prettier": "^9.0.0", |
@@ -1,2 +0,4 @@ | ||
import type { TranslationType } from '../types'; | ||
export type TranslationType = { | ||
[key: string]: string | boolean | null | number | TranslationType | TranslationType[]; | ||
}; | ||
/** | ||
@@ -3,0 +5,0 @@ * Translates a JSON object from one language to another using the Azure Translator service. |
64437
1096
14