generaltranslation 7.0.1 → 7.1.0-alpha.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/README.md +108 -0
- package/dist/index.cjs.min.cjs +1 -1
- package/dist/index.cjs.min.cjs.map +1 -1
- package/dist/index.d.ts +223 -5
- package/dist/index.esm.min.mjs +1 -1
- package/dist/index.esm.min.mjs.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/logging/errors.d.ts +10 -0
- package/dist/logging/logger.d.ts +117 -0
- package/dist/logging/warnings.d.ts +2 -0
- package/dist/translate/checkFileTranslations.d.ts +1 -0
- package/dist/translate/checkTranslationStatus.d.ts +1 -0
- package/dist/translate/downloadFile.d.ts +1 -0
- package/dist/translate/downloadFileBatch.d.ts +1 -0
- package/dist/translate/enqueueEntries.d.ts +1 -0
- package/dist/translate/enqueueFiles.d.ts +1 -0
- package/dist/translate/fetchTranslations.d.ts +1 -0
- package/dist/translate/translate.d.ts +1 -0
- package/dist/translate/translateMany.d.ts +1 -0
- package/dist/translate/utils/fetchWithTimeout.d.ts +1 -0
- package/dist/translate/utils/generateRequestHeaders.d.ts +6 -0
- package/dist/translate/utils/handleFetchError.d.ts +1 -0
- package/dist/translate/utils/validateResponse.d.ts +1 -0
- package/dist/types-dir/checkFileTranslations.d.ts +12 -0
- package/dist/types-dir/content.d.ts +49 -0
- package/dist/types-dir/downloadFile.d.ts +3 -0
- package/dist/types-dir/downloadFileBatch.d.ts +22 -0
- package/dist/types-dir/enqueueEntries.d.ts +20 -0
- package/dist/types-dir/enqueueFiles.d.ts +45 -0
- package/dist/types-dir/entry.d.ts +37 -0
- package/dist/types-dir/fetchTranslations.d.ts +11 -0
- package/dist/types-dir/file.d.ts +23 -0
- package/dist/types-dir/translate.d.ts +34 -0
- package/dist/types-dir/translateMany.d.ts +5 -0
- package/dist/types-dir/translationStatus.d.ts +9 -0
- package/dist/types-dir/variables.d.ts +9 -0
- package/dist/types.cjs.min.cjs.map +1 -1
- package/dist/types.d.ts +262 -27
- package/dist/types.esm.min.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/settings/errors.d.ts +0 -4
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
import { CustomMapping, FormatVariables } from './types';
|
1
|
+
import { CustomMapping, FormatVariables, I18nextMessage, IcuMessage, TranslateManyResult, TranslationError, TranslationResult, Updates, EnqueueEntriesOptions, EnqueueEntriesResult, EnqueueFilesOptions, EnqueueFilesResult, FileToTranslate, CheckFileTranslationsOptions, CheckFileTranslationsResult, DownloadFileBatchOptions, DownloadFileBatchResult, FetchTranslationsOptions, FetchTranslationsResult, DownloadFileOptions, EntryMetadata, Entry } from './types';
|
2
2
|
import { LocaleProperties } from './locales/getLocaleProperties';
|
3
|
+
import { JsxChildren } from './internal';
|
4
|
+
import { FileTranslationQuery } from './types-dir/checkFileTranslations';
|
5
|
+
import { CheckTranslationStatusOptions, TranslationStatusResult } from './types-dir/translationStatus';
|
3
6
|
/**
|
4
7
|
* Type representing the constructor parameters for the GT class.
|
5
8
|
* @typedef {Object} GTConstructorParams
|
@@ -38,7 +41,7 @@ type GTConstructorParams = {
|
|
38
41
|
*/
|
39
42
|
export declare class GT {
|
40
43
|
/** Base URL for the translation service API */
|
41
|
-
baseUrl
|
44
|
+
baseUrl?: string;
|
42
45
|
/** Project ID for the translation service */
|
43
46
|
projectId?: string;
|
44
47
|
/** API key for accessing the translation service */
|
@@ -70,9 +73,224 @@ export declare class GT {
|
|
70
73
|
* locales: ['en-US', 'es-ES', 'fr-FR']
|
71
74
|
* });
|
72
75
|
*/
|
73
|
-
constructor(
|
74
|
-
|
75
|
-
|
76
|
+
constructor(params?: GTConstructorParams);
|
77
|
+
setConfig({ apiKey, devApiKey, sourceLocale, targetLocale, locales, projectId, customMapping, baseUrl, }: GTConstructorParams): void;
|
78
|
+
private _getTranslationConfig;
|
79
|
+
private _validateAuth;
|
80
|
+
/**
|
81
|
+
* Enqueues translation entries for processing.
|
82
|
+
*
|
83
|
+
* @param {Updates} updates - The translation entries to enqueue.
|
84
|
+
* @param {EnqueueEntriesOptions} options - Options for enqueueing entries.
|
85
|
+
* @param {string} library - The library being used (for context).
|
86
|
+
* @returns {Promise<EnqueueTranslationEntriesResult>} The result of the enqueue operation.
|
87
|
+
*
|
88
|
+
* @example
|
89
|
+
* const gt = new GT({
|
90
|
+
* sourceLocale: 'en-US',
|
91
|
+
* targetLocale: 'es-ES',
|
92
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
93
|
+
* });
|
94
|
+
*
|
95
|
+
* const result = await gt.enqueueEntries([
|
96
|
+
* {
|
97
|
+
* content: 'Hello, world!',
|
98
|
+
* fileName: 'Button.tsx',
|
99
|
+
* fileFormat: 'TS',
|
100
|
+
* dataFormat: 'JSX',
|
101
|
+
* },
|
102
|
+
* ], {
|
103
|
+
* sourceLocale: 'en-US',
|
104
|
+
* targetLocales: ['es-ES', 'fr-FR'],
|
105
|
+
* publish: true,
|
106
|
+
* description: 'Translations for the Button component',
|
107
|
+
* });
|
108
|
+
*/
|
109
|
+
enqueueEntries(updates: Updates, options?: EnqueueEntriesOptions): Promise<EnqueueEntriesResult>;
|
110
|
+
/**
|
111
|
+
* Enqueues files for translation processing.
|
112
|
+
*
|
113
|
+
* @param {FileToTranslate[]} files - Array of files to enqueue for translation.
|
114
|
+
* @param {EnqueueFilesOptions} options - Options for enqueueing files.
|
115
|
+
* @returns {Promise<EnqueueFilesResult>} The result of the enqueue operation.
|
116
|
+
*
|
117
|
+
* @example
|
118
|
+
* const gt = new GT({
|
119
|
+
* sourceLocale: 'en-US',
|
120
|
+
* targetLocale: 'es-ES',
|
121
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
122
|
+
* });
|
123
|
+
*
|
124
|
+
* const result = await gt.enqueueFiles([
|
125
|
+
* {
|
126
|
+
* content: 'Hello, world!',
|
127
|
+
* fileName: 'Button.tsx',
|
128
|
+
* fileFormat: 'TS',
|
129
|
+
* dataFormat: 'JSX',
|
130
|
+
* },
|
131
|
+
* ], {
|
132
|
+
* sourceLocale: 'en-US',
|
133
|
+
* targetLocales: ['es-ES', 'fr-FR'],
|
134
|
+
* publish: true,
|
135
|
+
* description: 'Translations for the Button component',
|
136
|
+
* });
|
137
|
+
*/
|
138
|
+
enqueueFiles(files: FileToTranslate[], options: EnqueueFilesOptions): Promise<EnqueueFilesResult>;
|
139
|
+
/**
|
140
|
+
* Checks the translation status of files.
|
141
|
+
*
|
142
|
+
* @param {Object} data - Object mapping source paths to file information.
|
143
|
+
* @param {CheckFileTranslationsOptions} options - Options for checking file translations.
|
144
|
+
* @returns {Promise<CheckFileTranslationsResult>} The file translation status information.
|
145
|
+
*
|
146
|
+
* @example
|
147
|
+
* const gt = new GT({
|
148
|
+
* sourceLocale: 'en-US',
|
149
|
+
* targetLocale: 'es-ES',
|
150
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
151
|
+
* });
|
152
|
+
*
|
153
|
+
* const result = await gt.checkFileTranslations([
|
154
|
+
* { sourcePath: 'src/components/Button.tsx', locale: 'es-ES' },
|
155
|
+
* { sourcePath: 'src/components/Input.tsx', locale: 'fr-FR' },
|
156
|
+
* ], {
|
157
|
+
* timeout: 10000,
|
158
|
+
* });
|
159
|
+
*
|
160
|
+
*/
|
161
|
+
checkFileTranslations(data: FileTranslationQuery[], options?: CheckFileTranslationsOptions): Promise<CheckFileTranslationsResult>;
|
162
|
+
/**
|
163
|
+
* Checks the translation status of a version.
|
164
|
+
*
|
165
|
+
* @param {string} versionId - The ID of the version to check.
|
166
|
+
* @param {CheckTranslationStatusOptions} options - Options for checking the translation status.
|
167
|
+
* @returns {Promise<TranslationStatusResult>} The translation status of the version.
|
168
|
+
*
|
169
|
+
* @example
|
170
|
+
* const gt = new GT({
|
171
|
+
* sourceLocale: 'en-US',
|
172
|
+
* targetLocale: 'es-ES',
|
173
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
174
|
+
* });
|
175
|
+
*
|
176
|
+
* const result = await gt.checkTranslationStatus('1234567890', {
|
177
|
+
* timeout: 10000,
|
178
|
+
* });
|
179
|
+
*/
|
180
|
+
checkTranslationStatus(versionId: string, options?: CheckTranslationStatusOptions): Promise<TranslationStatusResult>;
|
181
|
+
/**
|
182
|
+
* Downloads a single translation file.
|
183
|
+
*
|
184
|
+
* @param {string} translationId - The ID of the translation to download.
|
185
|
+
* @param {DownloadFileOptions} options - Options for downloading the file.
|
186
|
+
* @returns {Promise<DownloadFileResult>} The downloaded file content and metadata.
|
187
|
+
*
|
188
|
+
* @example
|
189
|
+
* const gt = new GT({
|
190
|
+
* sourceLocale: 'en-US',
|
191
|
+
* targetLocale: 'es-ES',
|
192
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
193
|
+
* });
|
194
|
+
*
|
195
|
+
* const result = await gt.downloadFile('1234567890', {
|
196
|
+
* timeout: 10000,
|
197
|
+
* });
|
198
|
+
*/
|
199
|
+
downloadFile(translationId: string, options?: DownloadFileOptions): Promise<ArrayBuffer>;
|
200
|
+
/**
|
201
|
+
* Downloads multiple translation files in a batch.
|
202
|
+
*
|
203
|
+
* @param {string[]} fileIds - Array of file IDs to download.
|
204
|
+
* @param {DownloadFileBatchOptions} options - Options for the batch download.
|
205
|
+
* @returns {Promise<DownloadFileBatchResult>} The batch download results.
|
206
|
+
*
|
207
|
+
* @example
|
208
|
+
* const gt = new GT({
|
209
|
+
* sourceLocale: 'en-US',
|
210
|
+
* targetLocale: 'es-ES',
|
211
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
212
|
+
* });
|
213
|
+
*
|
214
|
+
* const result = await gt.downloadFileBatch(['1234567890', '1234567891'], {
|
215
|
+
* timeout: 10000,
|
216
|
+
* });
|
217
|
+
*/
|
218
|
+
downloadFileBatch(fileIds: string[], options?: DownloadFileBatchOptions): Promise<DownloadFileBatchResult>;
|
219
|
+
/**
|
220
|
+
* Fetches translation metadata and information.
|
221
|
+
*
|
222
|
+
* @param {string} versionId - The version ID to fetch translations for.
|
223
|
+
* @param {FetchTranslationsOptions} options - Options for fetching translations.
|
224
|
+
* @returns {Promise<FetchTranslationsResult>} The translation metadata and information.
|
225
|
+
*
|
226
|
+
* @example
|
227
|
+
* const gt = new GT({
|
228
|
+
* sourceLocale: 'en-US',
|
229
|
+
* targetLocale: 'es-ES',
|
230
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
231
|
+
* });
|
232
|
+
*
|
233
|
+
* const result = await gt.fetchTranslations('1234567890');
|
234
|
+
*/
|
235
|
+
fetchTranslations(versionId: string, options?: FetchTranslationsOptions): Promise<FetchTranslationsResult>;
|
236
|
+
/**
|
237
|
+
* Translates the source content to the target locale.
|
238
|
+
*
|
239
|
+
* @param {Content} source - {@link JsxChildren} | {@link IcuMessage} | {@link I18nextMessage} The source content to translate.
|
240
|
+
* @param {string} targetLocale - string The target locale to translate to.
|
241
|
+
* @param {EntryMetadata} metadata - {@link EntryMetadata} The metadata for the translation.
|
242
|
+
* @returns {Promise<TranslationResult | TranslationError>} The translated content.
|
243
|
+
*
|
244
|
+
* @example
|
245
|
+
* const gt = new GT({
|
246
|
+
* sourceLocale: 'en-US',
|
247
|
+
* targetLocale: 'es-ES',
|
248
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
249
|
+
* });
|
250
|
+
*
|
251
|
+
* const result = await gt.translate('Hello, world!', 'es-ES');
|
252
|
+
*
|
253
|
+
* @example
|
254
|
+
* const gt = new GT({
|
255
|
+
* sourceLocale: 'en-US',
|
256
|
+
* targetLocale: 'es-ES',
|
257
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
258
|
+
* });
|
259
|
+
*
|
260
|
+
* const result = await gt.translate('Hello, world!', 'es-ES', { context: 'A formal greeting'});
|
261
|
+
*/
|
262
|
+
_translate(source: JsxChildren, targetLocale: string, metadata?: Omit<EntryMetadata, 'dataFormat'> & {
|
263
|
+
dataFormat?: 'JSX';
|
264
|
+
}): Promise<TranslationResult | TranslationError>;
|
265
|
+
_translate(source: IcuMessage, targetLocale: string, metadata?: Omit<EntryMetadata, 'dataFormat'> & {
|
266
|
+
dataFormat?: 'ICU';
|
267
|
+
}): Promise<TranslationResult | TranslationError>;
|
268
|
+
_translate(source: I18nextMessage, targetLocale: string, metadata?: Omit<EntryMetadata, 'dataFormat'> & {
|
269
|
+
dataFormat?: 'I18NEXT';
|
270
|
+
}): Promise<TranslationResult | TranslationError>;
|
271
|
+
/**
|
272
|
+
* Translates multiple source contents to the target locale.
|
273
|
+
* Override global metadata by supplying a metadata object for each request.
|
274
|
+
*
|
275
|
+
* @param {Entry[]} sources - The source contents to translate.
|
276
|
+
* @param {EntryMetadata} globalMetadata - {@link EntryMetadata} The metadata for the translation.
|
277
|
+
* @returns {Promise<TranslateManyResult>} The translated contents.
|
278
|
+
*
|
279
|
+
* @example
|
280
|
+
* const gt = new GT({
|
281
|
+
* sourceLocale: 'en-US',
|
282
|
+
* targetLocale: 'es-ES',
|
283
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
284
|
+
* });
|
285
|
+
*
|
286
|
+
* const result = await gt.translateMany([
|
287
|
+
* { source: 'Hello, world!' },
|
288
|
+
* { source: 'Goodbye, world!' },
|
289
|
+
* ], { targetLocale: 'es-ES' });
|
290
|
+
*/
|
291
|
+
translateMany(sources: Entry[], globalMetadata?: {
|
292
|
+
targetLocale: string;
|
293
|
+
} & EntryMetadata): Promise<TranslateManyResult>;
|
76
294
|
/**
|
77
295
|
* Formats a message according to the specified locales and options.
|
78
296
|
*
|