generaltranslation 2.0.53 → 2.0.55
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/{codes → cjs/codes}/codes.js +11 -12
- package/dist/{codes → cjs/codes}/getLanguageDirection.js +4 -4
- package/dist/{index.js → cjs/index.js} +10 -29
- package/dist/cjs/translation/_bundleTranslation.js +42 -0
- package/dist/cjs/translation/_intl.js +52 -0
- package/dist/cjs/translation/_translate.js +51 -0
- package/dist/cjs/translation/_translateReactChildren.js +56 -0
- package/dist/cjs/translation/_updateRemoteDictionary.js +30 -0
- package/dist/mjs/codes/15924/CodeToScript.json +215 -0
- package/dist/mjs/codes/15924/ScriptToCode.json +215 -0
- package/dist/mjs/codes/3166/CodeToRegion.json +296 -0
- package/dist/mjs/codes/3166/RegionToCode.json +296 -0
- package/dist/mjs/codes/639-1/CodeToLanguage.json +185 -0
- package/dist/mjs/codes/639-1/LanguageToCode.json +227 -0
- package/dist/mjs/codes/639-3/CodeToLanguageTriletter.json +186 -0
- package/dist/mjs/codes/639-3/LanguageToCodeTriletter.json +228 -0
- package/dist/mjs/codes/codes.d.ts +8 -0
- package/dist/mjs/codes/codes.js +305 -0
- package/dist/mjs/codes/getLanguageDirection.d.ts +1 -0
- package/dist/mjs/codes/getLanguageDirection.js +68 -0
- package/dist/mjs/codes/predefined/Predefined.json +28 -0
- package/dist/mjs/index.d.ts +153 -0
- package/dist/mjs/index.js +130 -0
- package/dist/mjs/translation/_bundleTranslation.d.ts +22 -0
- package/dist/mjs/translation/_bundleTranslation.js +39 -0
- package/dist/mjs/translation/_intl.d.ts +1 -0
- package/dist/mjs/translation/_intl.js +49 -0
- package/dist/mjs/translation/_translate.d.ts +1 -0
- package/dist/mjs/translation/_translate.js +48 -0
- package/dist/mjs/translation/_translateReactChildren.d.ts +1 -0
- package/dist/mjs/translation/_translateReactChildren.js +53 -0
- package/dist/mjs/translation/_updateRemoteDictionary.d.ts +17 -0
- package/dist/mjs/translation/_updateRemoteDictionary.js +27 -0
- package/package.json +12 -5
- package/dist/translation/_bundleTranslation.js +0 -54
- package/dist/translation/_intl.js +0 -63
- package/dist/translation/_translate.js +0 -62
- package/dist/translation/_translateReactChildren.js +0 -67
- package/dist/translation/_updateRemoteDictionary.js +0 -41
- /package/dist/{codes → cjs/codes}/15924/CodeToScript.json +0 -0
- /package/dist/{codes → cjs/codes}/15924/ScriptToCode.json +0 -0
- /package/dist/{codes → cjs/codes}/3166/CodeToRegion.json +0 -0
- /package/dist/{codes → cjs/codes}/3166/RegionToCode.json +0 -0
- /package/dist/{codes → cjs/codes}/639-1/CodeToLanguage.json +0 -0
- /package/dist/{codes → cjs/codes}/639-1/LanguageToCode.json +0 -0
- /package/dist/{codes → cjs/codes}/639-3/CodeToLanguageTriletter.json +0 -0
- /package/dist/{codes → cjs/codes}/639-3/LanguageToCodeTriletter.json +0 -0
- /package/dist/{codes → cjs/codes}/codes.d.ts +0 -0
- /package/dist/{codes → cjs/codes}/getLanguageDirection.d.ts +0 -0
- /package/dist/{codes → cjs/codes}/predefined/Predefined.json +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{translation → cjs/translation}/_bundleTranslation.d.ts +0 -0
- /package/dist/{translation → cjs/translation}/_intl.d.ts +0 -0
- /package/dist/{translation → cjs/translation}/_translate.d.ts +0 -0
- /package/dist/{translation → cjs/translation}/_translateReactChildren.d.ts +0 -0
- /package/dist/{translation → cjs/translation}/_updateRemoteDictionary.d.ts +0 -0
@@ -1,5 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
// ----- IMPORTS ----- //
|
3
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
4
|
};
|
@@ -9,6 +8,7 @@ exports._standardizeLanguageCode = _standardizeLanguageCode;
|
|
9
8
|
exports._isValidLanguageCode = _isValidLanguageCode;
|
10
9
|
exports._getLanguageObject = _getLanguageObject;
|
11
10
|
exports._isSameLanguage = _isSameLanguage;
|
11
|
+
// ----- IMPORTS ----- //
|
12
12
|
// Import modules for mapping ISO 639 codes to language names and vice versa
|
13
13
|
const CodeToLanguage_json_1 = __importDefault(require("./639-1/CodeToLanguage.json"));
|
14
14
|
const LanguageToCode_json_1 = __importDefault(require("./639-1/LanguageToCode.json"));
|
@@ -31,7 +31,6 @@ const RegionToCode = RegionToCode_json_1.default;
|
|
31
31
|
const CodeToRegion = CodeToRegion_json_1.default;
|
32
32
|
// Import predefined common regions
|
33
33
|
const Predefined_json_1 = __importDefault(require("./predefined/Predefined.json"));
|
34
|
-
const generaltranslation_1 = require("generaltranslation");
|
35
34
|
const Predefined = Predefined_json_1.default;
|
36
35
|
// ----- VALIDITY CHECKS ----- //
|
37
36
|
/**
|
@@ -41,7 +40,7 @@ const Predefined = Predefined_json_1.default;
|
|
41
40
|
* @internal
|
42
41
|
*/
|
43
42
|
function _standardizeLanguageCode(code) {
|
44
|
-
if (!(
|
43
|
+
if (!_isValidLanguageCode(code))
|
45
44
|
return '';
|
46
45
|
const codeParts = code.split('-');
|
47
46
|
let result = `${codeParts[0].toLowerCase()}`;
|
@@ -104,11 +103,11 @@ const _capitalize = (code) => {
|
|
104
103
|
* @returns {string} The language name.
|
105
104
|
*/
|
106
105
|
const _mapCodeToLanguage = (code) => {
|
107
|
-
code = code
|
108
|
-
if (
|
106
|
+
code = code?.toLowerCase();
|
107
|
+
if (code?.length === 2) {
|
109
108
|
return CodeToLanguage[code];
|
110
109
|
}
|
111
|
-
if (
|
110
|
+
if (code?.length === 3) {
|
112
111
|
return CodeToLanguageTriletter[code];
|
113
112
|
}
|
114
113
|
return '';
|
@@ -120,7 +119,7 @@ const _mapCodeToLanguage = (code) => {
|
|
120
119
|
* @returns {string} BCP 47 language tag.
|
121
120
|
*/
|
122
121
|
const _mapLanguageToCode = (language) => {
|
123
|
-
language = language
|
122
|
+
language = language?.toLowerCase();
|
124
123
|
return LanguageToCode[language] || LanguageToCodeTriletter[language] || '';
|
125
124
|
};
|
126
125
|
/**
|
@@ -138,7 +137,7 @@ const _mapCodeToScript = (code) => {
|
|
138
137
|
* @returns {string} The ISO 15924 code.
|
139
138
|
*/
|
140
139
|
const _mapScriptToCode = (script) => {
|
141
|
-
script = script
|
140
|
+
script = script?.toLowerCase();
|
142
141
|
return ScriptToCode[script] || '';
|
143
142
|
};
|
144
143
|
/**
|
@@ -147,7 +146,7 @@ const _mapScriptToCode = (script) => {
|
|
147
146
|
* @returns {string} The region name.
|
148
147
|
*/
|
149
148
|
const _mapCodeToRegion = (code) => {
|
150
|
-
code = code
|
149
|
+
code = code?.toUpperCase();
|
151
150
|
return CodeToRegion[code] || '';
|
152
151
|
};
|
153
152
|
/**
|
@@ -156,7 +155,7 @@ const _mapCodeToRegion = (code) => {
|
|
156
155
|
* @returns {string} The ISO 3166 code.
|
157
156
|
*/
|
158
157
|
const _mapRegionToCode = (region) => {
|
159
|
-
region = region
|
158
|
+
region = region?.toLowerCase();
|
160
159
|
return RegionToCode[region] || '';
|
161
160
|
};
|
162
161
|
/**
|
@@ -171,7 +170,7 @@ function _getLanguageObject(codes) {
|
|
171
170
|
* @returns {LanguageObject|null} The language object.
|
172
171
|
*/
|
173
172
|
const _handleGetLanguageObject = (code) => {
|
174
|
-
if (!(
|
173
|
+
if (!_isValidLanguageCode(code))
|
175
174
|
return null;
|
176
175
|
const codeParts = code.split('-');
|
177
176
|
let languageObject = {
|
@@ -280,7 +279,7 @@ const _handleGetLanguageCodeFromString = (language) => {
|
|
280
279
|
* @returns {string} The language code.
|
281
280
|
*/
|
282
281
|
const _handleGetLanguageCodeFromObject = (languageObject) => {
|
283
|
-
if (!
|
282
|
+
if (!languageObject?.language)
|
284
283
|
return '';
|
285
284
|
let code = languageObject.language.toLowerCase();
|
286
285
|
if (languageObject.script) {
|
@@ -50,7 +50,7 @@ const rtlLanguages = [
|
|
50
50
|
'yi' /* 'ייִדיש', Yiddish */
|
51
51
|
];
|
52
52
|
/* ----- END YAHOO COPYRIGHT ----- */
|
53
|
-
const
|
53
|
+
const codes_js_1 = require("./codes.js");
|
54
54
|
/**
|
55
55
|
* Get the text direction for a given language code.
|
56
56
|
*
|
@@ -60,12 +60,12 @@ const codes_1 = require("./codes");
|
|
60
60
|
*/
|
61
61
|
function _getLanguageDirection(code) {
|
62
62
|
return rtlLanguages.some(language => {
|
63
|
-
const lo = (0,
|
64
|
-
const clo = (0,
|
63
|
+
const lo = (0, codes_js_1._getLanguageObject)(language);
|
64
|
+
const clo = (0, codes_js_1._getLanguageObject)(code);
|
65
65
|
if (!lo || !clo)
|
66
66
|
return false;
|
67
67
|
if (lo.script && clo.script && lo.script !== clo.script)
|
68
68
|
return false;
|
69
|
-
return (0,
|
69
|
+
return (0, codes_js_1._isSameLanguage)(code, language);
|
70
70
|
}) ? 'rtl' : 'ltr';
|
71
71
|
}
|
@@ -1,15 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
// `generaltranslation` language toolkit
|
3
3
|
// © 2024, General Translation, Inc.
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
11
|
-
});
|
12
|
-
};
|
13
4
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
14
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
15
6
|
};
|
@@ -60,10 +51,8 @@ class GT {
|
|
60
51
|
* @param {{ notes?: string, [key: string]: any }} metadata - Additional metadata for the translation request.
|
61
52
|
* @returns {Promise<{ translation: string, error?: Error | unknown }>} - The translated content with optional error information.
|
62
53
|
*/
|
63
|
-
translate(content, targetLanguage, metadata) {
|
64
|
-
return
|
65
|
-
return yield (0, _translate_1.default)(this, content, targetLanguage, Object.assign({ projectID: this.projectID, defaultLanguage: this.defaultLanguage }, metadata));
|
66
|
-
});
|
54
|
+
async translate(content, targetLanguage, metadata) {
|
55
|
+
return await (0, _translate_1.default)(this, content, targetLanguage, { projectID: this.projectID, defaultLanguage: this.defaultLanguage, ...metadata });
|
67
56
|
}
|
68
57
|
/**
|
69
58
|
* Translates a string and caches for use in a public project.
|
@@ -73,10 +62,8 @@ class GT {
|
|
73
62
|
* @param {dictionaryName?: string, context?: string, [key: string]: any }} metadata - Additional metadata for the translation request.
|
74
63
|
* @returns {Promise<{ translation: string, error?: Error | unknown }>} The translated content with optional error information.
|
75
64
|
*/
|
76
|
-
intl(content, targetLanguage, projectID, metadata) {
|
77
|
-
return
|
78
|
-
return yield (0, _intl_1.default)(this, content, targetLanguage, projectID || this.projectID, Object.assign({ projectID: projectID || this.projectID, defaultLanguage: this.defaultLanguage }, metadata));
|
79
|
-
});
|
65
|
+
async intl(content, targetLanguage, projectID, metadata) {
|
66
|
+
return await (0, _intl_1.default)(this, content, targetLanguage, projectID || this.projectID, { projectID: projectID || this.projectID, defaultLanguage: this.defaultLanguage, ...metadata });
|
80
67
|
}
|
81
68
|
/**
|
82
69
|
* Translates the content of React children elements.
|
@@ -88,20 +75,16 @@ class GT {
|
|
88
75
|
*
|
89
76
|
* @returns {Promise<any>} - A promise that resolves to the translated content.
|
90
77
|
*/
|
91
|
-
translateReactChildren(content, targetLanguage, metadata) {
|
92
|
-
return
|
93
|
-
return yield (0, _translateReactChildren_1.default)(this, content, targetLanguage, Object.assign({ projectID: this.projectID, defaultLanguage: this.defaultLanguage }, metadata));
|
94
|
-
});
|
78
|
+
async translateReactChildren(content, targetLanguage, metadata) {
|
79
|
+
return await (0, _translateReactChildren_1.default)(this, content, targetLanguage, { projectID: this.projectID, defaultLanguage: this.defaultLanguage, ...metadata });
|
95
80
|
}
|
96
81
|
/**
|
97
82
|
* Bundles multiple translation requests and sends them to the server.
|
98
83
|
* @param requests - Array of requests to be processed and sent.
|
99
84
|
* @returns A promise that resolves to an array of processed results.
|
100
85
|
*/
|
101
|
-
bundleTranslation(requests) {
|
102
|
-
return
|
103
|
-
return (0, _bundleTranslation_1.default)(this, requests);
|
104
|
-
});
|
86
|
+
async bundleTranslation(requests) {
|
87
|
+
return (0, _bundleTranslation_1.default)(this, requests);
|
105
88
|
}
|
106
89
|
/**
|
107
90
|
* Pushes updates to a remotely cached translation dictionary.
|
@@ -111,10 +94,8 @@ class GT {
|
|
111
94
|
* @param {boolean} [replace=false] - Whether to replace the existing dictionary. Defaults to false.
|
112
95
|
* @returns {Promise<string[]>} A promise that resolves to an array of strings indicating the languages which have been updated.
|
113
96
|
*/
|
114
|
-
updateRemoteDictionary(
|
115
|
-
return
|
116
|
-
return (0, _updateRemoteDictionary_1.default)(this, updates, languages, projectID, replace);
|
117
|
-
});
|
97
|
+
async updateRemoteDictionary(updates, languages = [], projectID = this.projectID, replace = false) {
|
98
|
+
return (0, _updateRemoteDictionary_1.default)(this, updates, languages, projectID, replace);
|
118
99
|
}
|
119
100
|
}
|
120
101
|
// ----- EXPORTS ----- //
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = _bundleTranslation;
|
4
|
+
/**
|
5
|
+
* Bundles multiple requests and sends them to the server.
|
6
|
+
* @param {{ baseURL: string, apiKey: string }} gt - Contains the baseURL and apiKey for the server request.
|
7
|
+
* @param {Request[]} requests - Array of requests to be processed and sent.
|
8
|
+
* @param {{ timeout?: number }} options - Additional options for the request, including timeout.
|
9
|
+
* @returns {Promise<Array<any | null>>} A promise that resolves to an array of processed results.
|
10
|
+
* @internal
|
11
|
+
*/
|
12
|
+
async function _bundleTranslation(gt, requests) {
|
13
|
+
const controller = new AbortController();
|
14
|
+
const signal = controller.signal;
|
15
|
+
if (requests[0]?.data?.metadata?.timeout) {
|
16
|
+
setTimeout(() => controller.abort(), requests[0].data.metadata.timeout);
|
17
|
+
}
|
18
|
+
try {
|
19
|
+
const response = await fetch(`${gt.baseURL}/bundle`, {
|
20
|
+
method: 'POST',
|
21
|
+
headers: {
|
22
|
+
'Content-Type': 'application/json',
|
23
|
+
'gtx-api-key': gt.apiKey,
|
24
|
+
},
|
25
|
+
body: JSON.stringify(requests),
|
26
|
+
signal
|
27
|
+
});
|
28
|
+
if (!response.ok) {
|
29
|
+
throw new Error(`${response.status}: ${await response.text()}`);
|
30
|
+
}
|
31
|
+
const resultArray = await response.json();
|
32
|
+
return resultArray;
|
33
|
+
}
|
34
|
+
catch (error) {
|
35
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
36
|
+
console.error('Request timed out');
|
37
|
+
return Array.from(requests, () => ({ translation: null, error: 'Request timed out' }));
|
38
|
+
}
|
39
|
+
console.error(error);
|
40
|
+
return Array.from(requests, () => ({ translation: null, error: error }));
|
41
|
+
}
|
42
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = _translate;
|
4
|
+
/**
|
5
|
+
* Translates a single piece of content and caches for use in a public project.
|
6
|
+
* @param {{ baseURL: string, apiKey: string }} gt - The translation service configuration.
|
7
|
+
* @param {string} content - The content to translate.
|
8
|
+
* @param {string} targetLanguage - The target language for the translation.
|
9
|
+
* @param {string} projectID - The ID of the project
|
10
|
+
* @param {{ dictionaryName?: string, notes?: string, timeout?: number, [key: string]: any }} metadata - Additional metadata for the translation request.
|
11
|
+
* @returns {Promise<{ translation: string, error?: Error | unknown }>} - The translated content with optional error information.
|
12
|
+
* @internal
|
13
|
+
*/
|
14
|
+
async function _translate(gt, content, targetLanguage, projectID, metadata) {
|
15
|
+
const controller = new AbortController();
|
16
|
+
const signal = controller.signal;
|
17
|
+
if (metadata.timeout) {
|
18
|
+
setTimeout(() => controller.abort(), metadata.timeout);
|
19
|
+
}
|
20
|
+
try {
|
21
|
+
const response = await fetch(`${gt.baseURL}/translate`, {
|
22
|
+
method: 'POST',
|
23
|
+
headers: {
|
24
|
+
'Content-Type': 'application/json',
|
25
|
+
'gtx-api-key': gt.apiKey,
|
26
|
+
},
|
27
|
+
body: JSON.stringify({
|
28
|
+
content, targetLanguage, projectID, metadata
|
29
|
+
}),
|
30
|
+
signal
|
31
|
+
});
|
32
|
+
if (!response.ok) {
|
33
|
+
throw new Error(`${response.status}: ${await response.text()}`);
|
34
|
+
}
|
35
|
+
const result = await response.json();
|
36
|
+
return result;
|
37
|
+
}
|
38
|
+
catch (error) {
|
39
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
40
|
+
console.error('Request timed out');
|
41
|
+
return {
|
42
|
+
translation: content,
|
43
|
+
error: 'Request timed out'
|
44
|
+
};
|
45
|
+
}
|
46
|
+
console.error(error);
|
47
|
+
return {
|
48
|
+
translation: content,
|
49
|
+
error: error
|
50
|
+
};
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = _translate;
|
4
|
+
/**
|
5
|
+
* Translates a string.
|
6
|
+
* @param {{ baseURL: string, apiKey: string }} gt - The translation service configuration.
|
7
|
+
* @param {string} content - The content to translate.
|
8
|
+
* @param {string} targetLanguage - The target language for the translation.
|
9
|
+
* @param {{ notes?: string, timeout?: number, [key: string]: any }} metadata - Additional metadata for the translation request.
|
10
|
+
* @returns {Promise<{ translation: string, error?: Error | unknown }>} - The translated content with optional error information.
|
11
|
+
* @internal
|
12
|
+
*/
|
13
|
+
async function _translate(gt, content, targetLanguage, metadata) {
|
14
|
+
const controller = new AbortController();
|
15
|
+
const signal = controller.signal;
|
16
|
+
if (metadata.timeout) {
|
17
|
+
setTimeout(() => controller.abort(), metadata.timeout);
|
18
|
+
}
|
19
|
+
try {
|
20
|
+
const response = await fetch(`${gt.baseURL}/translate`, {
|
21
|
+
method: 'POST',
|
22
|
+
headers: {
|
23
|
+
'Content-Type': 'application/json',
|
24
|
+
'gtx-api-key': gt.apiKey,
|
25
|
+
},
|
26
|
+
body: JSON.stringify({
|
27
|
+
content, targetLanguage, metadata
|
28
|
+
}),
|
29
|
+
signal
|
30
|
+
});
|
31
|
+
if (!response.ok) {
|
32
|
+
throw new Error(`${response.status}: ${await response.text()}`);
|
33
|
+
}
|
34
|
+
const result = await response.json();
|
35
|
+
return result;
|
36
|
+
}
|
37
|
+
catch (error) {
|
38
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
39
|
+
console.error('Request timed out');
|
40
|
+
return {
|
41
|
+
translation: content,
|
42
|
+
error: 'Request timed out'
|
43
|
+
};
|
44
|
+
}
|
45
|
+
console.error(error);
|
46
|
+
return {
|
47
|
+
translation: content,
|
48
|
+
error: error
|
49
|
+
};
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = _translateReactChildren;
|
4
|
+
/**
|
5
|
+
* Translates the given content into the target language using a specified API.
|
6
|
+
*
|
7
|
+
* @param {{ baseURL: string, apiKey: string }} gt - An object containing baseURL and apiKey for the API.
|
8
|
+
* @param {any} content - The content to be translated. This can be of any type.
|
9
|
+
* @param {string} targetLanguage - The target language code (e.g., 'en', 'fr') for the translation.
|
10
|
+
* @param {{ [key: string]: any }} metadata - Additional metadata to be sent with the translation request.
|
11
|
+
*
|
12
|
+
* @returns {Promise<{ translation: any | null, error?: Error | unknown }>} - A promise that resolves to the translated content as an object, or null if an error occurs.
|
13
|
+
*
|
14
|
+
* @throws {Error} - Throws an error if the response from the API is not ok (status code not in the range 200-299).
|
15
|
+
* @internal
|
16
|
+
**/
|
17
|
+
async function _translateReactChildren(gt, content, targetLanguage, metadata) {
|
18
|
+
const controller = new AbortController();
|
19
|
+
const signal = controller.signal;
|
20
|
+
if (metadata.timeout) {
|
21
|
+
setTimeout(() => controller.abort(), metadata.timeout);
|
22
|
+
}
|
23
|
+
try {
|
24
|
+
const response = await fetch(`${gt.baseURL}/react`, {
|
25
|
+
method: 'POST',
|
26
|
+
headers: {
|
27
|
+
'Content-Type': 'application/json',
|
28
|
+
'gtx-api-key': gt.apiKey,
|
29
|
+
},
|
30
|
+
body: JSON.stringify({
|
31
|
+
content: content,
|
32
|
+
targetLanguage: targetLanguage,
|
33
|
+
metadata: metadata
|
34
|
+
}),
|
35
|
+
signal
|
36
|
+
});
|
37
|
+
if (!response.ok) {
|
38
|
+
throw new Error(`${response.status}: ${await response.text()}`);
|
39
|
+
}
|
40
|
+
return await response.json();
|
41
|
+
}
|
42
|
+
catch (error) {
|
43
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
44
|
+
console.error('Request timed out');
|
45
|
+
return {
|
46
|
+
translation: null,
|
47
|
+
error: 'Request timed out'
|
48
|
+
};
|
49
|
+
}
|
50
|
+
console.error(error);
|
51
|
+
return {
|
52
|
+
translation: null,
|
53
|
+
error: error
|
54
|
+
};
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = _updateRemoteDictionary;
|
4
|
+
async function _updateRemoteDictionary(gt, updates, languages, projectID, replace) {
|
5
|
+
try {
|
6
|
+
const response = await fetch(`${gt.baseURL}/update`, {
|
7
|
+
method: 'POST',
|
8
|
+
headers: {
|
9
|
+
'Content-Type': 'application/json',
|
10
|
+
'gtx-api-key': gt.apiKey,
|
11
|
+
},
|
12
|
+
body: JSON.stringify({
|
13
|
+
updates, languages, projectID, replace
|
14
|
+
})
|
15
|
+
});
|
16
|
+
if (!response.ok) {
|
17
|
+
throw new Error(`${response.status}: ${await response.text()}`);
|
18
|
+
}
|
19
|
+
const result = await response.json();
|
20
|
+
return result.languages;
|
21
|
+
}
|
22
|
+
catch (error) {
|
23
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
24
|
+
console.error('Request timed out');
|
25
|
+
return [];
|
26
|
+
}
|
27
|
+
console.error(error);
|
28
|
+
return [];
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,215 @@
|
|
1
|
+
{
|
2
|
+
"Adlm": "Adlam",
|
3
|
+
"Afak": "Afaka",
|
4
|
+
"Aghb": "Caucasian Albanian",
|
5
|
+
"Ahom": "Ahom",
|
6
|
+
"Aran": "Arabic (Nastaliq variant)",
|
7
|
+
"Armi": "Imperial Aramaic",
|
8
|
+
"Armn": "Armenian",
|
9
|
+
"Avst": "Avestan",
|
10
|
+
"Bali": "Balinese",
|
11
|
+
"Bamu": "Bamum",
|
12
|
+
"Bass": "Bassa Vah",
|
13
|
+
"Batk": "Batak",
|
14
|
+
"Beng": "Bengali",
|
15
|
+
"Bhks": "Bhaiksuki",
|
16
|
+
"Blis": "Blissymbols",
|
17
|
+
"Bopo": "Bopomofo",
|
18
|
+
"Brah": "Brahmi",
|
19
|
+
"Brai": "Braille",
|
20
|
+
"Bugi": "Buginese",
|
21
|
+
"Buhd": "Buhid",
|
22
|
+
"Cakm": "Chakma",
|
23
|
+
"Cans": "Unified Canadian Aboriginal Syllabics",
|
24
|
+
"Cari": "Carian",
|
25
|
+
"Cham": "Cham",
|
26
|
+
"Cher": "Cherokee",
|
27
|
+
"Chis": "Chisoi",
|
28
|
+
"Chrs": "Chorasmian",
|
29
|
+
"Cirt": "Cirth",
|
30
|
+
"Copt": "Coptic",
|
31
|
+
"Cpmn": "Cypro-Minoan",
|
32
|
+
"Cprt": "Cypriot syllabary",
|
33
|
+
"Cyrl": "Cyrillic",
|
34
|
+
"Cyrs": "Cyrillic (Old Church Slavonic variant)",
|
35
|
+
"Deva": "Devanagari",
|
36
|
+
"Diak": "Dives Akuru",
|
37
|
+
"Dogr": "Dogra",
|
38
|
+
"Dsrt": "Deseret",
|
39
|
+
"Dupl": "Duployan shorthand",
|
40
|
+
"Egyd": "Egyptian demotic",
|
41
|
+
"Egyh": "Egyptian hieratic",
|
42
|
+
"Egyp": "Egyptian hieroglyphs",
|
43
|
+
"Elba": "Elbasan",
|
44
|
+
"Elym": "Elymaic",
|
45
|
+
"Ethi": "Ethiopic",
|
46
|
+
"Gara": "Garay",
|
47
|
+
"Geok": "Khutsuri (Asomtavruli and Nuskhuri)",
|
48
|
+
"Geor": "Georgian (Mkhedruli and Mtavruli)",
|
49
|
+
"Glag": "Glagolitic",
|
50
|
+
"Gong": "Gunjala Gondi",
|
51
|
+
"Gonm": "Masaram Gondi",
|
52
|
+
"Goth": "Gothic",
|
53
|
+
"Gran": "Grantha",
|
54
|
+
"Grek": "Greek",
|
55
|
+
"Gujr": "Gujarati",
|
56
|
+
"Gukh": "Gurung Khema",
|
57
|
+
"Guru": "Gurmukhi",
|
58
|
+
"Hanb": "Han with Bopomofo",
|
59
|
+
"Hang": "Hangul",
|
60
|
+
"Hani": "Han",
|
61
|
+
"Hano": "Hanunoo",
|
62
|
+
"Hans": "Han (Simplified variant)",
|
63
|
+
"Hant": "Han (Traditional variant)",
|
64
|
+
"Hatr": "Hatran",
|
65
|
+
"Hebr": "Hebrew",
|
66
|
+
"Hira": "Hiragana",
|
67
|
+
"Hluw": "Anatolian Hieroglyphs",
|
68
|
+
"Hmng": "Pahawh Hmong",
|
69
|
+
"Hmnp": "Nyiakeng Puachue Hmong",
|
70
|
+
"Hrkt": "Japanese syllabaries",
|
71
|
+
"Hung": "Old Hungarian",
|
72
|
+
"Inds": "Indus",
|
73
|
+
"Ital": "Old Italic",
|
74
|
+
"Jamo": "Jamo",
|
75
|
+
"Java": "Javanese",
|
76
|
+
"Jpan": "Japanese",
|
77
|
+
"Jurc": "Jurchen",
|
78
|
+
"Kali": "Kayah Li",
|
79
|
+
"Kana": "Katakana",
|
80
|
+
"Kawi": "Kawi",
|
81
|
+
"Khar": "Kharoshthi",
|
82
|
+
"Khmr": "Khmer",
|
83
|
+
"Khoj": "Khojki",
|
84
|
+
"Kitl": "Khitan large script",
|
85
|
+
"Kits": "Khitan small script",
|
86
|
+
"Knda": "Kannada",
|
87
|
+
"Kore": "Korean",
|
88
|
+
"Kpel": "Kpelle",
|
89
|
+
"Krai": "Kirat Rai",
|
90
|
+
"Kthi": "Kaithi",
|
91
|
+
"Lana": "Tai Tham",
|
92
|
+
"Laoo": "Lao",
|
93
|
+
"Latf": "Latin (Fraktur variant)",
|
94
|
+
"Latg": "Latin (Gaelic variant)",
|
95
|
+
"Latn": "Latin",
|
96
|
+
"Leke": "Leke",
|
97
|
+
"Lepc": "Lepcha",
|
98
|
+
"Limb": "Limbu",
|
99
|
+
"Lina": "Linear A",
|
100
|
+
"Linb": "Linear B",
|
101
|
+
"Lisu": "Lisu",
|
102
|
+
"Loma": "Loma",
|
103
|
+
"Lyci": "Lycian",
|
104
|
+
"Lydi": "Lydian",
|
105
|
+
"Mahj": "Mahajani",
|
106
|
+
"Maka": "Makasar",
|
107
|
+
"Mand": "Mandaic",
|
108
|
+
"Mani": "Manichaean",
|
109
|
+
"Marc": "Marchen",
|
110
|
+
"Maya": "Mayan hieroglyphs",
|
111
|
+
"Medf": "Medefaidrin",
|
112
|
+
"Mend": "Mende Kikakui",
|
113
|
+
"Merc": "Meroitic Cursive",
|
114
|
+
"Mero": "Meroitic Hieroglyphs",
|
115
|
+
"Mlym": "Malayalam",
|
116
|
+
"Modi": "Modi",
|
117
|
+
"Mong": "Mongolian",
|
118
|
+
"Moon": "Moon",
|
119
|
+
"Mroo": "Mro",
|
120
|
+
"Mtei": "Meitei Mayek",
|
121
|
+
"Mult": "Multani",
|
122
|
+
"Mymr": "Myanmar",
|
123
|
+
"Nagm": "Nag Mundari",
|
124
|
+
"Nand": "Nandinagari",
|
125
|
+
"Narb": "Old North Arabian",
|
126
|
+
"Nbat": "Nabataean",
|
127
|
+
"Newa": "Newa",
|
128
|
+
"Nkdb": "Naxi Dongba",
|
129
|
+
"Nkgb": "Naxi Geba",
|
130
|
+
"Nkoo": "N’Ko",
|
131
|
+
"Nshu": "Nüshu",
|
132
|
+
"Ogam": "Ogham",
|
133
|
+
"Olck": "Ol Chiki",
|
134
|
+
"Onao": "Ol Onal",
|
135
|
+
"Orkh": "Old Turkic",
|
136
|
+
"Orya": "Oriya",
|
137
|
+
"Osge": "Osage",
|
138
|
+
"Osma": "Osmanya",
|
139
|
+
"Ougr": "Old Uyghur",
|
140
|
+
"Palm": "Palmyrene",
|
141
|
+
"Pauc": "Pau Cin Hau",
|
142
|
+
"Pcun": "Proto-Cuneiform",
|
143
|
+
"Pelm": "Proto-Elamite",
|
144
|
+
"Perm": "Old Permic",
|
145
|
+
"Phag": "Phags-pa",
|
146
|
+
"Phli": "Inscriptional Pahlavi",
|
147
|
+
"Phlp": "Psalter Pahlavi",
|
148
|
+
"Phlv": "Book Pahlavi",
|
149
|
+
"Phnx": "Phoenician",
|
150
|
+
"Piqd": "Klingon",
|
151
|
+
"Plrd": "Miao",
|
152
|
+
"Prti": "Inscriptional Parthian",
|
153
|
+
"Psin": "Proto-Sinaitic",
|
154
|
+
"Ranj": "Ranjana",
|
155
|
+
"Rjng": "Rejang",
|
156
|
+
"Rohg": "Hanifi Rohingya",
|
157
|
+
"Roro": "Rongorongo",
|
158
|
+
"Runr": "Runic",
|
159
|
+
"Samr": "Samaritan",
|
160
|
+
"Sara": "Sarati",
|
161
|
+
"Sarb": "Old South Arabian",
|
162
|
+
"Saur": "Saurashtra",
|
163
|
+
"Sgnw": "SignWriting",
|
164
|
+
"Shaw": "Shavian",
|
165
|
+
"Shrd": "Sharada",
|
166
|
+
"Shui": "Shuishu",
|
167
|
+
"Sidd": "Siddham",
|
168
|
+
"Sidt": "Sidetic",
|
169
|
+
"Sind": "Khudawadi",
|
170
|
+
"Sinh": "Sinhala",
|
171
|
+
"Sogd": "Sogdian",
|
172
|
+
"Sogo": "Old Sogdian",
|
173
|
+
"Sora": "Sora Sompeng",
|
174
|
+
"Soyo": "Soyombo",
|
175
|
+
"Sund": "Sundanese",
|
176
|
+
"Sunu": "Sunuwar",
|
177
|
+
"Sylo": "Syloti Nagri",
|
178
|
+
"Syrc": "Syriac",
|
179
|
+
"Syre": "Syriac (Estrangelo variant)",
|
180
|
+
"Syrj": "Syriac (Western variant)",
|
181
|
+
"Syrn": "Syriac (Eastern variant)",
|
182
|
+
"Tagb": "Tagbanwa",
|
183
|
+
"Takr": "Takri",
|
184
|
+
"Tale": "Tai Le",
|
185
|
+
"Talu": "New Tai Lue",
|
186
|
+
"Taml": "Tamil",
|
187
|
+
"Tang": "Tangut",
|
188
|
+
"Tavt": "Tai Viet",
|
189
|
+
"Tayo": "Tai Yo",
|
190
|
+
"Telu": "Telugu",
|
191
|
+
"Teng": "Tengwar",
|
192
|
+
"Tfng": "Tifinagh",
|
193
|
+
"Tglg": "Tagalog",
|
194
|
+
"Thaa": "Thaana",
|
195
|
+
"Thai": "Thai",
|
196
|
+
"Tibt": "Tibetan",
|
197
|
+
"Tirh": "Tirhuta",
|
198
|
+
"Tnsa": "Tangsa",
|
199
|
+
"Todr": "Todhri",
|
200
|
+
"Tols": "Tolong Siki",
|
201
|
+
"Toto": "Toto",
|
202
|
+
"Tutg": "Tulu-Tigalari",
|
203
|
+
"Ugar": "Ugaritic",
|
204
|
+
"Vaii": "Vai",
|
205
|
+
"Visp": "Visible Speech",
|
206
|
+
"Vith": "Vithkuqi",
|
207
|
+
"Wara": "Warang Citi",
|
208
|
+
"Wcho": "Wancho",
|
209
|
+
"Wole": "Woleai",
|
210
|
+
"Xpeo": "Old Persian",
|
211
|
+
"Xsux": "Sumero-Akkadian cuneiform",
|
212
|
+
"Yezi": "Yezidi",
|
213
|
+
"Yiii": "Yi",
|
214
|
+
"Zanb": "Zanabazar Square"
|
215
|
+
}
|