@form-engine-ts/translator-azure 1.0.0
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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/index.cjs +174 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +149 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nitta-a
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @form-engine-ts/translator-azure
|
|
2
|
+
|
|
3
|
+
Server-side Azure AI Translator REST API v3.0 adapter for form-engine-ts.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @form-engine-ts/core @form-engine-ts/translator-azure
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createAzureTranslator } from "@form-engine-ts/translator-azure";
|
|
15
|
+
|
|
16
|
+
const translator = createAzureTranslator({
|
|
17
|
+
apiKey: process.env.AZURE_TRANSLATOR_KEY!,
|
|
18
|
+
region: "japaneast"
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const japanese = await translator.translateText("Thank you", "ja", "en");
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Keep credentials on a trusted server. Custom-domain endpoints must include the complete Translate operation path.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createAzureTranslator: () => createAzureTranslator
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var DEFAULT_ENDPOINT = "https://api.cognitive.microsofttranslator.com/translate";
|
|
27
|
+
var MAX_BATCH_SIZE = 1e3;
|
|
28
|
+
var MAX_CHARACTER_COUNT = 5e4;
|
|
29
|
+
function isRecord(value) {
|
|
30
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
function requireNonEmpty(value, name) {
|
|
33
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
34
|
+
throw new TypeError(`${name} must be a non-empty string.`);
|
|
35
|
+
}
|
|
36
|
+
return value.trim();
|
|
37
|
+
}
|
|
38
|
+
function parseEndpoint(value) {
|
|
39
|
+
try {
|
|
40
|
+
return new URL(value ?? DEFAULT_ENDPOINT).toString();
|
|
41
|
+
} catch (cause) {
|
|
42
|
+
throw new TypeError("endpoint must be a valid absolute URL.", { cause });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function redact(value, apiKey) {
|
|
46
|
+
return value.replaceAll(apiKey, "[redacted]");
|
|
47
|
+
}
|
|
48
|
+
function redactCause(cause, apiKey) {
|
|
49
|
+
if (cause instanceof Error) return new Error(redact(cause.message, apiKey));
|
|
50
|
+
if (typeof cause === "string") return redact(cause, apiKey);
|
|
51
|
+
return cause;
|
|
52
|
+
}
|
|
53
|
+
function apiErrorDetail(body, apiKey) {
|
|
54
|
+
if (body.length === 0) return void 0;
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(body);
|
|
57
|
+
if (isRecord(parsed) && isRecord(parsed.error)) {
|
|
58
|
+
const code = typeof parsed.error.code === "string" || typeof parsed.error.code === "number" ? String(parsed.error.code) : void 0;
|
|
59
|
+
const message = typeof parsed.error.message === "string" ? parsed.error.message : void 0;
|
|
60
|
+
if (code !== void 0 && message !== void 0) return redact(`${code}: ${message}`, apiKey);
|
|
61
|
+
if (message !== void 0) return redact(message, apiKey);
|
|
62
|
+
if (code !== void 0) return `Azure error code ${code}`;
|
|
63
|
+
}
|
|
64
|
+
if (isRecord(parsed) && typeof parsed.message === "string") return redact(parsed.message, apiKey);
|
|
65
|
+
} catch {
|
|
66
|
+
return redact(body, apiKey);
|
|
67
|
+
}
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
function validateTexts(texts) {
|
|
71
|
+
if (!Array.isArray(texts) || texts.some((text) => typeof text !== "string")) {
|
|
72
|
+
throw new TypeError("texts must be an array of strings.");
|
|
73
|
+
}
|
|
74
|
+
if (texts.length > MAX_BATCH_SIZE) {
|
|
75
|
+
throw new TypeError(`texts must contain no more than ${MAX_BATCH_SIZE} items.`);
|
|
76
|
+
}
|
|
77
|
+
let totalCharacters = 0;
|
|
78
|
+
for (const [index, text] of texts.entries()) {
|
|
79
|
+
if (text.length > MAX_CHARACTER_COUNT) {
|
|
80
|
+
throw new TypeError(`text at index ${index} must contain no more than ${MAX_CHARACTER_COUNT} characters.`);
|
|
81
|
+
}
|
|
82
|
+
totalCharacters += text.length;
|
|
83
|
+
}
|
|
84
|
+
if (totalCharacters > MAX_CHARACTER_COUNT) {
|
|
85
|
+
throw new TypeError(`texts must contain no more than ${MAX_CHARACTER_COUNT} characters in total.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function createAzureTranslator(options) {
|
|
89
|
+
const apiKey = requireNonEmpty(options?.apiKey, "apiKey");
|
|
90
|
+
const region = options?.region === void 0 ? void 0 : requireNonEmpty(options.region, "region");
|
|
91
|
+
const endpoint = parseEndpoint(options?.endpoint);
|
|
92
|
+
const fetchImpl = options?.fetchFn ?? globalThis.fetch;
|
|
93
|
+
if (typeof fetchImpl !== "function") {
|
|
94
|
+
throw new Error("Fetch is unavailable. Pass fetchFn when creating the Azure translator.");
|
|
95
|
+
}
|
|
96
|
+
const translateBatch = async (texts, targetLocale, sourceLocale) => {
|
|
97
|
+
validateTexts(texts);
|
|
98
|
+
const target = requireNonEmpty(targetLocale, "targetLocale");
|
|
99
|
+
const source = sourceLocale === void 0 ? void 0 : requireNonEmpty(sourceLocale, "sourceLocale");
|
|
100
|
+
if (texts.length === 0) return [];
|
|
101
|
+
const requestUrl = new URL(endpoint);
|
|
102
|
+
requestUrl.searchParams.set("api-version", "3.0");
|
|
103
|
+
requestUrl.searchParams.set("to", target);
|
|
104
|
+
if (source === void 0) requestUrl.searchParams.delete("from");
|
|
105
|
+
else requestUrl.searchParams.set("from", source);
|
|
106
|
+
const headers = {
|
|
107
|
+
"Content-Type": "application/json; charset=UTF-8",
|
|
108
|
+
"Ocp-Apim-Subscription-Key": apiKey
|
|
109
|
+
};
|
|
110
|
+
if (region !== void 0) headers["Ocp-Apim-Subscription-Region"] = region;
|
|
111
|
+
let response;
|
|
112
|
+
try {
|
|
113
|
+
response = await fetchImpl(requestUrl.toString(), {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers,
|
|
116
|
+
body: JSON.stringify(texts.map((text) => ({ Text: text })))
|
|
117
|
+
});
|
|
118
|
+
} catch (cause) {
|
|
119
|
+
throw new Error("Azure Translator request failed before receiving an HTTP response.", {
|
|
120
|
+
cause: redactCause(cause, apiKey)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
let body;
|
|
124
|
+
try {
|
|
125
|
+
body = await response.text();
|
|
126
|
+
} catch (cause) {
|
|
127
|
+
throw new Error(`Azure Translator response body could not be read (HTTP ${response.status}).`, {
|
|
128
|
+
cause: redactCause(cause, apiKey)
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
const detail = apiErrorDetail(body, apiKey);
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Azure Translator request failed with HTTP ${response.status}${detail === void 0 ? "." : `: ${detail}`}`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
let parsed;
|
|
138
|
+
try {
|
|
139
|
+
parsed = JSON.parse(body);
|
|
140
|
+
} catch (cause) {
|
|
141
|
+
throw new Error(`Azure Translator returned invalid JSON (HTTP ${response.status}).`, { cause });
|
|
142
|
+
}
|
|
143
|
+
if (!Array.isArray(parsed)) {
|
|
144
|
+
throw new Error("Azure Translator response must be an array.");
|
|
145
|
+
}
|
|
146
|
+
if (parsed.length !== texts.length) {
|
|
147
|
+
throw new Error(`Azure Translator returned ${parsed.length} results for ${texts.length} texts.`);
|
|
148
|
+
}
|
|
149
|
+
return parsed.map((item, index) => {
|
|
150
|
+
if (!isRecord(item) || !Array.isArray(item.translations)) {
|
|
151
|
+
throw new Error(`Azure Translator result at index ${index} is missing the translations array.`);
|
|
152
|
+
}
|
|
153
|
+
const translation = item.translations[0];
|
|
154
|
+
if (!isRecord(translation) || typeof translation.text !== "string") {
|
|
155
|
+
throw new Error(`Azure Translator translation at index ${index} is invalid.`);
|
|
156
|
+
}
|
|
157
|
+
return translation.text;
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
async translateText(text, targetLocale, sourceLocale) {
|
|
162
|
+
if (typeof text !== "string") throw new TypeError("text must be a string.");
|
|
163
|
+
const translations = await translateBatch([text], targetLocale, sourceLocale);
|
|
164
|
+
const translated = translations[0];
|
|
165
|
+
if (translated === void 0) throw new Error("Azure Translator returned no translation.");
|
|
166
|
+
return translated;
|
|
167
|
+
},
|
|
168
|
+
translateBatch
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
172
|
+
0 && (module.exports = {
|
|
173
|
+
createAzureTranslator
|
|
174
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AsyncTranslationAdapter } from '@form-engine-ts/core';
|
|
2
|
+
|
|
3
|
+
interface AzureTranslatorOptions {
|
|
4
|
+
readonly apiKey: string;
|
|
5
|
+
readonly region?: string;
|
|
6
|
+
readonly endpoint?: string;
|
|
7
|
+
readonly fetchFn?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
declare function createAzureTranslator(options: AzureTranslatorOptions): AsyncTranslationAdapter;
|
|
10
|
+
|
|
11
|
+
export { type AzureTranslatorOptions, createAzureTranslator };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AsyncTranslationAdapter } from '@form-engine-ts/core';
|
|
2
|
+
|
|
3
|
+
interface AzureTranslatorOptions {
|
|
4
|
+
readonly apiKey: string;
|
|
5
|
+
readonly region?: string;
|
|
6
|
+
readonly endpoint?: string;
|
|
7
|
+
readonly fetchFn?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
declare function createAzureTranslator(options: AzureTranslatorOptions): AsyncTranslationAdapter;
|
|
10
|
+
|
|
11
|
+
export { type AzureTranslatorOptions, createAzureTranslator };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var DEFAULT_ENDPOINT = "https://api.cognitive.microsofttranslator.com/translate";
|
|
3
|
+
var MAX_BATCH_SIZE = 1e3;
|
|
4
|
+
var MAX_CHARACTER_COUNT = 5e4;
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function requireNonEmpty(value, name) {
|
|
9
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
10
|
+
throw new TypeError(`${name} must be a non-empty string.`);
|
|
11
|
+
}
|
|
12
|
+
return value.trim();
|
|
13
|
+
}
|
|
14
|
+
function parseEndpoint(value) {
|
|
15
|
+
try {
|
|
16
|
+
return new URL(value ?? DEFAULT_ENDPOINT).toString();
|
|
17
|
+
} catch (cause) {
|
|
18
|
+
throw new TypeError("endpoint must be a valid absolute URL.", { cause });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function redact(value, apiKey) {
|
|
22
|
+
return value.replaceAll(apiKey, "[redacted]");
|
|
23
|
+
}
|
|
24
|
+
function redactCause(cause, apiKey) {
|
|
25
|
+
if (cause instanceof Error) return new Error(redact(cause.message, apiKey));
|
|
26
|
+
if (typeof cause === "string") return redact(cause, apiKey);
|
|
27
|
+
return cause;
|
|
28
|
+
}
|
|
29
|
+
function apiErrorDetail(body, apiKey) {
|
|
30
|
+
if (body.length === 0) return void 0;
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(body);
|
|
33
|
+
if (isRecord(parsed) && isRecord(parsed.error)) {
|
|
34
|
+
const code = typeof parsed.error.code === "string" || typeof parsed.error.code === "number" ? String(parsed.error.code) : void 0;
|
|
35
|
+
const message = typeof parsed.error.message === "string" ? parsed.error.message : void 0;
|
|
36
|
+
if (code !== void 0 && message !== void 0) return redact(`${code}: ${message}`, apiKey);
|
|
37
|
+
if (message !== void 0) return redact(message, apiKey);
|
|
38
|
+
if (code !== void 0) return `Azure error code ${code}`;
|
|
39
|
+
}
|
|
40
|
+
if (isRecord(parsed) && typeof parsed.message === "string") return redact(parsed.message, apiKey);
|
|
41
|
+
} catch {
|
|
42
|
+
return redact(body, apiKey);
|
|
43
|
+
}
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
function validateTexts(texts) {
|
|
47
|
+
if (!Array.isArray(texts) || texts.some((text) => typeof text !== "string")) {
|
|
48
|
+
throw new TypeError("texts must be an array of strings.");
|
|
49
|
+
}
|
|
50
|
+
if (texts.length > MAX_BATCH_SIZE) {
|
|
51
|
+
throw new TypeError(`texts must contain no more than ${MAX_BATCH_SIZE} items.`);
|
|
52
|
+
}
|
|
53
|
+
let totalCharacters = 0;
|
|
54
|
+
for (const [index, text] of texts.entries()) {
|
|
55
|
+
if (text.length > MAX_CHARACTER_COUNT) {
|
|
56
|
+
throw new TypeError(`text at index ${index} must contain no more than ${MAX_CHARACTER_COUNT} characters.`);
|
|
57
|
+
}
|
|
58
|
+
totalCharacters += text.length;
|
|
59
|
+
}
|
|
60
|
+
if (totalCharacters > MAX_CHARACTER_COUNT) {
|
|
61
|
+
throw new TypeError(`texts must contain no more than ${MAX_CHARACTER_COUNT} characters in total.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function createAzureTranslator(options) {
|
|
65
|
+
const apiKey = requireNonEmpty(options?.apiKey, "apiKey");
|
|
66
|
+
const region = options?.region === void 0 ? void 0 : requireNonEmpty(options.region, "region");
|
|
67
|
+
const endpoint = parseEndpoint(options?.endpoint);
|
|
68
|
+
const fetchImpl = options?.fetchFn ?? globalThis.fetch;
|
|
69
|
+
if (typeof fetchImpl !== "function") {
|
|
70
|
+
throw new Error("Fetch is unavailable. Pass fetchFn when creating the Azure translator.");
|
|
71
|
+
}
|
|
72
|
+
const translateBatch = async (texts, targetLocale, sourceLocale) => {
|
|
73
|
+
validateTexts(texts);
|
|
74
|
+
const target = requireNonEmpty(targetLocale, "targetLocale");
|
|
75
|
+
const source = sourceLocale === void 0 ? void 0 : requireNonEmpty(sourceLocale, "sourceLocale");
|
|
76
|
+
if (texts.length === 0) return [];
|
|
77
|
+
const requestUrl = new URL(endpoint);
|
|
78
|
+
requestUrl.searchParams.set("api-version", "3.0");
|
|
79
|
+
requestUrl.searchParams.set("to", target);
|
|
80
|
+
if (source === void 0) requestUrl.searchParams.delete("from");
|
|
81
|
+
else requestUrl.searchParams.set("from", source);
|
|
82
|
+
const headers = {
|
|
83
|
+
"Content-Type": "application/json; charset=UTF-8",
|
|
84
|
+
"Ocp-Apim-Subscription-Key": apiKey
|
|
85
|
+
};
|
|
86
|
+
if (region !== void 0) headers["Ocp-Apim-Subscription-Region"] = region;
|
|
87
|
+
let response;
|
|
88
|
+
try {
|
|
89
|
+
response = await fetchImpl(requestUrl.toString(), {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers,
|
|
92
|
+
body: JSON.stringify(texts.map((text) => ({ Text: text })))
|
|
93
|
+
});
|
|
94
|
+
} catch (cause) {
|
|
95
|
+
throw new Error("Azure Translator request failed before receiving an HTTP response.", {
|
|
96
|
+
cause: redactCause(cause, apiKey)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
let body;
|
|
100
|
+
try {
|
|
101
|
+
body = await response.text();
|
|
102
|
+
} catch (cause) {
|
|
103
|
+
throw new Error(`Azure Translator response body could not be read (HTTP ${response.status}).`, {
|
|
104
|
+
cause: redactCause(cause, apiKey)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
const detail = apiErrorDetail(body, apiKey);
|
|
109
|
+
throw new Error(
|
|
110
|
+
`Azure Translator request failed with HTTP ${response.status}${detail === void 0 ? "." : `: ${detail}`}`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
let parsed;
|
|
114
|
+
try {
|
|
115
|
+
parsed = JSON.parse(body);
|
|
116
|
+
} catch (cause) {
|
|
117
|
+
throw new Error(`Azure Translator returned invalid JSON (HTTP ${response.status}).`, { cause });
|
|
118
|
+
}
|
|
119
|
+
if (!Array.isArray(parsed)) {
|
|
120
|
+
throw new Error("Azure Translator response must be an array.");
|
|
121
|
+
}
|
|
122
|
+
if (parsed.length !== texts.length) {
|
|
123
|
+
throw new Error(`Azure Translator returned ${parsed.length} results for ${texts.length} texts.`);
|
|
124
|
+
}
|
|
125
|
+
return parsed.map((item, index) => {
|
|
126
|
+
if (!isRecord(item) || !Array.isArray(item.translations)) {
|
|
127
|
+
throw new Error(`Azure Translator result at index ${index} is missing the translations array.`);
|
|
128
|
+
}
|
|
129
|
+
const translation = item.translations[0];
|
|
130
|
+
if (!isRecord(translation) || typeof translation.text !== "string") {
|
|
131
|
+
throw new Error(`Azure Translator translation at index ${index} is invalid.`);
|
|
132
|
+
}
|
|
133
|
+
return translation.text;
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
async translateText(text, targetLocale, sourceLocale) {
|
|
138
|
+
if (typeof text !== "string") throw new TypeError("text must be a string.");
|
|
139
|
+
const translations = await translateBatch([text], targetLocale, sourceLocale);
|
|
140
|
+
const translated = translations[0];
|
|
141
|
+
if (translated === void 0) throw new Error("Azure Translator returned no translation.");
|
|
142
|
+
return translated;
|
|
143
|
+
},
|
|
144
|
+
translateBatch
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
createAzureTranslator
|
|
149
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@form-engine-ts/translator-azure",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/nitta-a/form-engine-ts.git",
|
|
28
|
+
"directory": "packages/translator-azure"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/nitta-a/form-engine-ts/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/nitta-a/form-engine-ts#readme",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"form",
|
|
36
|
+
"translation",
|
|
37
|
+
"azure",
|
|
38
|
+
"translator",
|
|
39
|
+
"typescript"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@form-engine-ts/core": "1.0.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --external @form-engine-ts/core",
|
|
46
|
+
"check": "biome check . && tsc --noEmit",
|
|
47
|
+
"test": "vitest run --globals",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
49
|
+
}
|
|
50
|
+
}
|