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.
Files changed (56) hide show
  1. package/dist/{codes → cjs/codes}/codes.js +11 -12
  2. package/dist/{codes → cjs/codes}/getLanguageDirection.js +4 -4
  3. package/dist/{index.js → cjs/index.js} +10 -29
  4. package/dist/cjs/translation/_bundleTranslation.js +42 -0
  5. package/dist/cjs/translation/_intl.js +52 -0
  6. package/dist/cjs/translation/_translate.js +51 -0
  7. package/dist/cjs/translation/_translateReactChildren.js +56 -0
  8. package/dist/cjs/translation/_updateRemoteDictionary.js +30 -0
  9. package/dist/mjs/codes/15924/CodeToScript.json +215 -0
  10. package/dist/mjs/codes/15924/ScriptToCode.json +215 -0
  11. package/dist/mjs/codes/3166/CodeToRegion.json +296 -0
  12. package/dist/mjs/codes/3166/RegionToCode.json +296 -0
  13. package/dist/mjs/codes/639-1/CodeToLanguage.json +185 -0
  14. package/dist/mjs/codes/639-1/LanguageToCode.json +227 -0
  15. package/dist/mjs/codes/639-3/CodeToLanguageTriletter.json +186 -0
  16. package/dist/mjs/codes/639-3/LanguageToCodeTriletter.json +228 -0
  17. package/dist/mjs/codes/codes.d.ts +8 -0
  18. package/dist/mjs/codes/codes.js +305 -0
  19. package/dist/mjs/codes/getLanguageDirection.d.ts +1 -0
  20. package/dist/mjs/codes/getLanguageDirection.js +68 -0
  21. package/dist/mjs/codes/predefined/Predefined.json +28 -0
  22. package/dist/mjs/index.d.ts +153 -0
  23. package/dist/mjs/index.js +130 -0
  24. package/dist/mjs/translation/_bundleTranslation.d.ts +22 -0
  25. package/dist/mjs/translation/_bundleTranslation.js +39 -0
  26. package/dist/mjs/translation/_intl.d.ts +1 -0
  27. package/dist/mjs/translation/_intl.js +49 -0
  28. package/dist/mjs/translation/_translate.d.ts +1 -0
  29. package/dist/mjs/translation/_translate.js +48 -0
  30. package/dist/mjs/translation/_translateReactChildren.d.ts +1 -0
  31. package/dist/mjs/translation/_translateReactChildren.js +53 -0
  32. package/dist/mjs/translation/_updateRemoteDictionary.d.ts +17 -0
  33. package/dist/mjs/translation/_updateRemoteDictionary.js +27 -0
  34. package/package.json +12 -5
  35. package/dist/translation/_bundleTranslation.js +0 -54
  36. package/dist/translation/_intl.js +0 -63
  37. package/dist/translation/_translate.js +0 -62
  38. package/dist/translation/_translateReactChildren.js +0 -67
  39. package/dist/translation/_updateRemoteDictionary.js +0 -41
  40. /package/dist/{codes → cjs/codes}/15924/CodeToScript.json +0 -0
  41. /package/dist/{codes → cjs/codes}/15924/ScriptToCode.json +0 -0
  42. /package/dist/{codes → cjs/codes}/3166/CodeToRegion.json +0 -0
  43. /package/dist/{codes → cjs/codes}/3166/RegionToCode.json +0 -0
  44. /package/dist/{codes → cjs/codes}/639-1/CodeToLanguage.json +0 -0
  45. /package/dist/{codes → cjs/codes}/639-1/LanguageToCode.json +0 -0
  46. /package/dist/{codes → cjs/codes}/639-3/CodeToLanguageTriletter.json +0 -0
  47. /package/dist/{codes → cjs/codes}/639-3/LanguageToCodeTriletter.json +0 -0
  48. /package/dist/{codes → cjs/codes}/codes.d.ts +0 -0
  49. /package/dist/{codes → cjs/codes}/getLanguageDirection.d.ts +0 -0
  50. /package/dist/{codes → cjs/codes}/predefined/Predefined.json +0 -0
  51. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  52. /package/dist/{translation → cjs/translation}/_bundleTranslation.d.ts +0 -0
  53. /package/dist/{translation → cjs/translation}/_intl.d.ts +0 -0
  54. /package/dist/{translation → cjs/translation}/_translate.d.ts +0 -0
  55. /package/dist/{translation → cjs/translation}/_translateReactChildren.d.ts +0 -0
  56. /package/dist/{translation → cjs/translation}/_updateRemoteDictionary.d.ts +0 -0
@@ -0,0 +1,22 @@
1
+ export type Request = {
2
+ type: 'translate';
3
+ data: {
4
+ content: string;
5
+ targetLanguage: string;
6
+ metadata: Record<string, any>;
7
+ };
8
+ } | {
9
+ type: 'intl';
10
+ data: {
11
+ content: string;
12
+ targetLanguage: string;
13
+ metadata: Record<string, any>;
14
+ };
15
+ } | {
16
+ type: 'react';
17
+ data: {
18
+ children: object | string;
19
+ targetLanguage: string;
20
+ metadata: Record<string, any>;
21
+ };
22
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Bundles multiple requests and sends them to the server.
3
+ * @param {{ baseURL: string, apiKey: string }} gt - Contains the baseURL and apiKey for the server request.
4
+ * @param {Request[]} requests - Array of requests to be processed and sent.
5
+ * @param {{ timeout?: number }} options - Additional options for the request, including timeout.
6
+ * @returns {Promise<Array<any | null>>} A promise that resolves to an array of processed results.
7
+ * @internal
8
+ */
9
+ export default async function _bundleTranslation(gt, requests) {
10
+ const controller = new AbortController();
11
+ const signal = controller.signal;
12
+ if (requests[0]?.data?.metadata?.timeout) {
13
+ setTimeout(() => controller.abort(), requests[0].data.metadata.timeout);
14
+ }
15
+ try {
16
+ const response = await fetch(`${gt.baseURL}/bundle`, {
17
+ method: 'POST',
18
+ headers: {
19
+ 'Content-Type': 'application/json',
20
+ 'gtx-api-key': gt.apiKey,
21
+ },
22
+ body: JSON.stringify(requests),
23
+ signal
24
+ });
25
+ if (!response.ok) {
26
+ throw new Error(`${response.status}: ${await response.text()}`);
27
+ }
28
+ const resultArray = await response.json();
29
+ return resultArray;
30
+ }
31
+ catch (error) {
32
+ if (error instanceof Error && error.name === 'AbortError') {
33
+ console.error('Request timed out');
34
+ return Array.from(requests, () => ({ translation: null, error: 'Request timed out' }));
35
+ }
36
+ console.error(error);
37
+ return Array.from(requests, () => ({ translation: null, error: error }));
38
+ }
39
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Translates a single piece of content and caches for use in a public project.
3
+ * @param {{ baseURL: string, apiKey: string }} gt - The translation service configuration.
4
+ * @param {string} content - The content to translate.
5
+ * @param {string} targetLanguage - The target language for the translation.
6
+ * @param {string} projectID - The ID of the project
7
+ * @param {{ dictionaryName?: string, notes?: string, timeout?: number, [key: string]: any }} metadata - Additional metadata for the translation request.
8
+ * @returns {Promise<{ translation: string, error?: Error | unknown }>} - The translated content with optional error information.
9
+ * @internal
10
+ */
11
+ export default async function _translate(gt, content, targetLanguage, projectID, metadata) {
12
+ const controller = new AbortController();
13
+ const signal = controller.signal;
14
+ if (metadata.timeout) {
15
+ setTimeout(() => controller.abort(), metadata.timeout);
16
+ }
17
+ try {
18
+ const response = await fetch(`${gt.baseURL}/translate`, {
19
+ method: 'POST',
20
+ headers: {
21
+ 'Content-Type': 'application/json',
22
+ 'gtx-api-key': gt.apiKey,
23
+ },
24
+ body: JSON.stringify({
25
+ content, targetLanguage, projectID, metadata
26
+ }),
27
+ signal
28
+ });
29
+ if (!response.ok) {
30
+ throw new Error(`${response.status}: ${await response.text()}`);
31
+ }
32
+ const result = await response.json();
33
+ return result;
34
+ }
35
+ catch (error) {
36
+ if (error instanceof Error && error.name === 'AbortError') {
37
+ console.error('Request timed out');
38
+ return {
39
+ translation: content,
40
+ error: 'Request timed out'
41
+ };
42
+ }
43
+ console.error(error);
44
+ return {
45
+ translation: content,
46
+ error: error
47
+ };
48
+ }
49
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Translates a string.
3
+ * @param {{ baseURL: string, apiKey: string }} gt - The translation service configuration.
4
+ * @param {string} content - The content to translate.
5
+ * @param {string} targetLanguage - The target language for the translation.
6
+ * @param {{ notes?: string, timeout?: number, [key: string]: any }} metadata - Additional metadata for the translation request.
7
+ * @returns {Promise<{ translation: string, error?: Error | unknown }>} - The translated content with optional error information.
8
+ * @internal
9
+ */
10
+ export default async function _translate(gt, content, targetLanguage, metadata) {
11
+ const controller = new AbortController();
12
+ const signal = controller.signal;
13
+ if (metadata.timeout) {
14
+ setTimeout(() => controller.abort(), metadata.timeout);
15
+ }
16
+ try {
17
+ const response = await fetch(`${gt.baseURL}/translate`, {
18
+ method: 'POST',
19
+ headers: {
20
+ 'Content-Type': 'application/json',
21
+ 'gtx-api-key': gt.apiKey,
22
+ },
23
+ body: JSON.stringify({
24
+ content, targetLanguage, metadata
25
+ }),
26
+ signal
27
+ });
28
+ if (!response.ok) {
29
+ throw new Error(`${response.status}: ${await response.text()}`);
30
+ }
31
+ const result = await response.json();
32
+ return result;
33
+ }
34
+ catch (error) {
35
+ if (error instanceof Error && error.name === 'AbortError') {
36
+ console.error('Request timed out');
37
+ return {
38
+ translation: content,
39
+ error: 'Request timed out'
40
+ };
41
+ }
42
+ console.error(error);
43
+ return {
44
+ translation: content,
45
+ error: error
46
+ };
47
+ }
48
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Translates the given content into the target language using a specified API.
3
+ *
4
+ * @param {{ baseURL: string, apiKey: string }} gt - An object containing baseURL and apiKey for the API.
5
+ * @param {any} content - The content to be translated. This can be of any type.
6
+ * @param {string} targetLanguage - The target language code (e.g., 'en', 'fr') for the translation.
7
+ * @param {{ [key: string]: any }} metadata - Additional metadata to be sent with the translation request.
8
+ *
9
+ * @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.
10
+ *
11
+ * @throws {Error} - Throws an error if the response from the API is not ok (status code not in the range 200-299).
12
+ * @internal
13
+ **/
14
+ export default async function _translateReactChildren(gt, content, targetLanguage, 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}/react`, {
22
+ method: 'POST',
23
+ headers: {
24
+ 'Content-Type': 'application/json',
25
+ 'gtx-api-key': gt.apiKey,
26
+ },
27
+ body: JSON.stringify({
28
+ content: content,
29
+ targetLanguage: targetLanguage,
30
+ metadata: metadata
31
+ }),
32
+ signal
33
+ });
34
+ if (!response.ok) {
35
+ throw new Error(`${response.status}: ${await response.text()}`);
36
+ }
37
+ return await response.json();
38
+ }
39
+ catch (error) {
40
+ if (error instanceof Error && error.name === 'AbortError') {
41
+ console.error('Request timed out');
42
+ return {
43
+ translation: null,
44
+ error: 'Request timed out'
45
+ };
46
+ }
47
+ console.error(error);
48
+ return {
49
+ translation: null,
50
+ error: error
51
+ };
52
+ }
53
+ }
@@ -0,0 +1,17 @@
1
+ export type Update = {
2
+ type: 'react';
3
+ data: {
4
+ children: object | string;
5
+ metadata: Record<string, any>;
6
+ };
7
+ } | {
8
+ type: 'intl';
9
+ data: {
10
+ content: string;
11
+ metadata: Record<string, any>;
12
+ };
13
+ };
14
+ export default function _updateRemoteDictionary(gt: {
15
+ baseURL: string;
16
+ apiKey: string;
17
+ }, updates: Update[], languages: string[], projectID: string, replace: boolean): Promise<string[]>;
@@ -0,0 +1,27 @@
1
+ export default async function _updateRemoteDictionary(gt, updates, languages, projectID, replace) {
2
+ try {
3
+ const response = await fetch(`${gt.baseURL}/update`, {
4
+ method: 'POST',
5
+ headers: {
6
+ 'Content-Type': 'application/json',
7
+ 'gtx-api-key': gt.apiKey,
8
+ },
9
+ body: JSON.stringify({
10
+ updates, languages, projectID, replace
11
+ })
12
+ });
13
+ if (!response.ok) {
14
+ throw new Error(`${response.status}: ${await response.text()}`);
15
+ }
16
+ const result = await response.json();
17
+ return result.languages;
18
+ }
19
+ catch (error) {
20
+ if (error instanceof Error && error.name === 'AbortError') {
21
+ console.error('Request timed out');
22
+ return [];
23
+ }
24
+ console.error(error);
25
+ return [];
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,15 +1,22 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "2.0.53",
3
+ "version": "2.0.55",
4
4
  "description": "A language toolkit for AI developers",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "dist/cjs/index.js",
6
+ "types": "dist/cjs/index.d.ts",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "build": "tsc",
12
- "prepublishOnly": "npm run build"
11
+ "transpile": "rm -r -f dist; tsc; tsc --project tsconfig.cjs.json;",
12
+ "prepublishOnly": "npm run transpile"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/cjs/index.js",
17
+ "require": "./dist/cjs/index.js",
18
+ "types": "./dist/mjs/index.d.ts"
19
+ }
13
20
  },
14
21
  "repository": {
15
22
  "type": "git",
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = _bundleTranslation;
13
- /**
14
- * Bundles multiple requests and sends them to the server.
15
- * @param {{ baseURL: string, apiKey: string }} gt - Contains the baseURL and apiKey for the server request.
16
- * @param {Request[]} requests - Array of requests to be processed and sent.
17
- * @param {{ timeout?: number }} options - Additional options for the request, including timeout.
18
- * @returns {Promise<Array<any | null>>} A promise that resolves to an array of processed results.
19
- * @internal
20
- */
21
- function _bundleTranslation(gt, requests) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- var _a, _b, _c;
24
- const controller = new AbortController();
25
- const signal = controller.signal;
26
- if ((_c = (_b = (_a = requests[0]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.metadata) === null || _c === void 0 ? void 0 : _c.timeout) {
27
- setTimeout(() => controller.abort(), requests[0].data.metadata.timeout);
28
- }
29
- try {
30
- const response = yield fetch(`${gt.baseURL}/bundle`, {
31
- method: 'POST',
32
- headers: {
33
- 'Content-Type': 'application/json',
34
- 'gtx-api-key': gt.apiKey,
35
- },
36
- body: JSON.stringify(requests),
37
- signal
38
- });
39
- if (!response.ok) {
40
- throw new Error(`${response.status}: ${yield response.text()}`);
41
- }
42
- const resultArray = yield response.json();
43
- return resultArray;
44
- }
45
- catch (error) {
46
- if (error instanceof Error && error.name === 'AbortError') {
47
- console.error('Request timed out');
48
- return Array.from(requests, () => ({ translation: null, error: 'Request timed out' }));
49
- }
50
- console.error(error);
51
- return Array.from(requests, () => ({ translation: null, error: error }));
52
- }
53
- });
54
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = _translate;
13
- /**
14
- * Translates a single piece of content and caches for use in a public project.
15
- * @param {{ baseURL: string, apiKey: string }} gt - The translation service configuration.
16
- * @param {string} content - The content to translate.
17
- * @param {string} targetLanguage - The target language for the translation.
18
- * @param {string} projectID - The ID of the project
19
- * @param {{ dictionaryName?: string, notes?: string, timeout?: number, [key: string]: any }} metadata - Additional metadata for the translation request.
20
- * @returns {Promise<{ translation: string, error?: Error | unknown }>} - The translated content with optional error information.
21
- * @internal
22
- */
23
- function _translate(gt, content, targetLanguage, projectID, metadata) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const controller = new AbortController();
26
- const signal = controller.signal;
27
- if (metadata.timeout) {
28
- setTimeout(() => controller.abort(), metadata.timeout);
29
- }
30
- try {
31
- const response = yield fetch(`${gt.baseURL}/translate`, {
32
- method: 'POST',
33
- headers: {
34
- 'Content-Type': 'application/json',
35
- 'gtx-api-key': gt.apiKey,
36
- },
37
- body: JSON.stringify({
38
- content, targetLanguage, projectID, metadata
39
- }),
40
- signal
41
- });
42
- if (!response.ok) {
43
- throw new Error(`${response.status}: ${yield response.text()}`);
44
- }
45
- const result = yield response.json();
46
- return result;
47
- }
48
- catch (error) {
49
- if (error instanceof Error && error.name === 'AbortError') {
50
- console.error('Request timed out');
51
- return {
52
- translation: content,
53
- error: 'Request timed out'
54
- };
55
- }
56
- console.error(error);
57
- return {
58
- translation: content,
59
- error: error
60
- };
61
- }
62
- });
63
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = _translate;
13
- /**
14
- * Translates a string.
15
- * @param {{ baseURL: string, apiKey: string }} gt - The translation service configuration.
16
- * @param {string} content - The content to translate.
17
- * @param {string} targetLanguage - The target language for the translation.
18
- * @param {{ notes?: string, timeout?: number, [key: string]: any }} metadata - Additional metadata for the translation request.
19
- * @returns {Promise<{ translation: string, error?: Error | unknown }>} - The translated content with optional error information.
20
- * @internal
21
- */
22
- function _translate(gt, content, targetLanguage, metadata) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const controller = new AbortController();
25
- const signal = controller.signal;
26
- if (metadata.timeout) {
27
- setTimeout(() => controller.abort(), metadata.timeout);
28
- }
29
- try {
30
- const response = yield fetch(`${gt.baseURL}/translate`, {
31
- method: 'POST',
32
- headers: {
33
- 'Content-Type': 'application/json',
34
- 'gtx-api-key': gt.apiKey,
35
- },
36
- body: JSON.stringify({
37
- content, targetLanguage, metadata
38
- }),
39
- signal
40
- });
41
- if (!response.ok) {
42
- throw new Error(`${response.status}: ${yield response.text()}`);
43
- }
44
- const result = yield response.json();
45
- return result;
46
- }
47
- catch (error) {
48
- if (error instanceof Error && error.name === 'AbortError') {
49
- console.error('Request timed out');
50
- return {
51
- translation: content,
52
- error: 'Request timed out'
53
- };
54
- }
55
- console.error(error);
56
- return {
57
- translation: content,
58
- error: error
59
- };
60
- }
61
- });
62
- }
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = _translateReactChildren;
13
- /**
14
- * Translates the given content into the target language using a specified API.
15
- *
16
- * @param {{ baseURL: string, apiKey: string }} gt - An object containing baseURL and apiKey for the API.
17
- * @param {any} content - The content to be translated. This can be of any type.
18
- * @param {string} targetLanguage - The target language code (e.g., 'en', 'fr') for the translation.
19
- * @param {{ [key: string]: any }} metadata - Additional metadata to be sent with the translation request.
20
- *
21
- * @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.
22
- *
23
- * @throws {Error} - Throws an error if the response from the API is not ok (status code not in the range 200-299).
24
- * @internal
25
- **/
26
- function _translateReactChildren(gt, content, targetLanguage, metadata) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const controller = new AbortController();
29
- const signal = controller.signal;
30
- if (metadata.timeout) {
31
- setTimeout(() => controller.abort(), metadata.timeout);
32
- }
33
- try {
34
- const response = yield fetch(`${gt.baseURL}/react`, {
35
- method: 'POST',
36
- headers: {
37
- 'Content-Type': 'application/json',
38
- 'gtx-api-key': gt.apiKey,
39
- },
40
- body: JSON.stringify({
41
- content: content,
42
- targetLanguage: targetLanguage,
43
- metadata: metadata
44
- }),
45
- signal
46
- });
47
- if (!response.ok) {
48
- throw new Error(`${response.status}: ${yield response.text()}`);
49
- }
50
- return yield response.json();
51
- }
52
- catch (error) {
53
- if (error instanceof Error && error.name === 'AbortError') {
54
- console.error('Request timed out');
55
- return {
56
- translation: null,
57
- error: 'Request timed out'
58
- };
59
- }
60
- console.error(error);
61
- return {
62
- translation: null,
63
- error: error
64
- };
65
- }
66
- });
67
- }
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = _updateRemoteDictionary;
13
- function _updateRemoteDictionary(gt, updates, languages, projectID, replace) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- try {
16
- const response = yield fetch(`${gt.baseURL}/update`, {
17
- method: 'POST',
18
- headers: {
19
- 'Content-Type': 'application/json',
20
- 'gtx-api-key': gt.apiKey,
21
- },
22
- body: JSON.stringify({
23
- updates, languages, projectID, replace
24
- })
25
- });
26
- if (!response.ok) {
27
- throw new Error(`${response.status}: ${yield response.text()}`);
28
- }
29
- const result = yield response.json();
30
- return result.languages;
31
- }
32
- catch (error) {
33
- if (error instanceof Error && error.name === 'AbortError') {
34
- console.error('Request timed out');
35
- return [];
36
- }
37
- console.error(error);
38
- return [];
39
- }
40
- });
41
- }
File without changes
File without changes