generaltranslation 7.0.0 → 7.1.0-alpha.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/CHANGELOG.md +6 -0
- 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/types.d.ts
CHANGED
@@ -22,9 +22,16 @@ type LocaleProperties = {
|
|
22
22
|
emoji: string;
|
23
23
|
};
|
24
24
|
|
25
|
-
type
|
25
|
+
type VariableType = 'v' | 'n' | 'd' | 'c';
|
26
|
+
/**
|
27
|
+
* Variables are used to store the variable name and type.
|
28
|
+
*/
|
29
|
+
type Variable = {
|
30
|
+
k: string;
|
31
|
+
i?: number;
|
32
|
+
v?: VariableType;
|
33
|
+
};
|
26
34
|
|
27
|
-
type Content = string | Array<string | Variable>;
|
28
35
|
/**
|
29
36
|
* Map of data-_gt properties to their corresponding React props
|
30
37
|
*/
|
@@ -38,12 +45,6 @@ declare const HTML_CONTENT_PROPS: {
|
|
38
45
|
};
|
39
46
|
type HtmlContentPropKeysRecord = Partial<Record<keyof typeof HTML_CONTENT_PROPS, string>>;
|
40
47
|
type HtmlContentPropValuesRecord = Partial<Record<(typeof HTML_CONTENT_PROPS)[keyof typeof HTML_CONTENT_PROPS], string>>;
|
41
|
-
/**
|
42
|
-
* Transformations are made from a prefix and a suffix.
|
43
|
-
*/
|
44
|
-
type Transformation = 'translate-client' | 'translate-server' | 'variable-variable' | 'variable-currency' | 'variable-datetime' | 'variable-number' | 'plural' | 'branch';
|
45
|
-
type TransformationPrefix = 'translate' | 'variable' | 'plural' | 'branch' | 'fragment';
|
46
|
-
type VariableTransformationSuffix = 'variable' | 'number' | 'datetime' | 'currency';
|
47
48
|
/**
|
48
49
|
* GTProp is an internal property used to contain data for translating and rendering elements.
|
49
50
|
* note, transformations are only read on the server side if they are 'plural' or 'branch'
|
@@ -59,7 +60,238 @@ type JsxElement = {
|
|
59
60
|
c?: JsxChildren;
|
60
61
|
};
|
61
62
|
type JsxChild = string | JsxElement | Variable;
|
63
|
+
/**
|
64
|
+
* The format of the content
|
65
|
+
*/
|
66
|
+
type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';
|
67
|
+
/**
|
68
|
+
* A content type representing JSX, ICU, and I18next messages
|
69
|
+
*/
|
70
|
+
type Content = JsxChildren | IcuMessage | I18nextMessage;
|
71
|
+
/**
|
72
|
+
* A content type representing JSX elements
|
73
|
+
*/
|
62
74
|
type JsxChildren = JsxChild | JsxChild[];
|
75
|
+
/**
|
76
|
+
* A content type representing ICU messages
|
77
|
+
*/
|
78
|
+
type IcuMessage = string;
|
79
|
+
/**
|
80
|
+
* A content type representing I18next messages
|
81
|
+
*/
|
82
|
+
type I18nextMessage = string;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* ActionType is the type of action to perform on the request.
|
86
|
+
*
|
87
|
+
* @param standard - The standard action type (standard model).
|
88
|
+
* @param fast - The fast action type (mini model).
|
89
|
+
* @param string - Other model
|
90
|
+
*/
|
91
|
+
type ActionType = 'standard' | 'fast' | string;
|
92
|
+
/**
|
93
|
+
* EntryMetadata is the metadata for a GTRequest.
|
94
|
+
*
|
95
|
+
* @param context - The context of the request.
|
96
|
+
* @param id - The id of the request.
|
97
|
+
* @param hash - The hash of the request.
|
98
|
+
*/
|
99
|
+
type EntryMetadata = {
|
100
|
+
context?: string;
|
101
|
+
id?: string;
|
102
|
+
hash?: string;
|
103
|
+
dataFormat?: DataFormat;
|
104
|
+
sourceLocale?: string;
|
105
|
+
actionType?: ActionType;
|
106
|
+
timeout?: number;
|
107
|
+
};
|
108
|
+
/**
|
109
|
+
* GTRequest is a translation request object for {@link JsxChildren} | {@link IcuMessage} | {@link I18nextMessage}
|
110
|
+
*
|
111
|
+
* @param source - The source content to translate.
|
112
|
+
* @param targetLocale - The target locale to translate to.
|
113
|
+
* @param requestMetadata - The metadata for the request.
|
114
|
+
*/
|
115
|
+
type Entry = {
|
116
|
+
source: Content;
|
117
|
+
targetLocale?: string;
|
118
|
+
requestMetadata?: EntryMetadata;
|
119
|
+
};
|
120
|
+
|
121
|
+
type TranslationStatusResult = {
|
122
|
+
count: number;
|
123
|
+
availableLocales: string[];
|
124
|
+
locales: string[];
|
125
|
+
localesWaitingForApproval: any[];
|
126
|
+
};
|
127
|
+
|
128
|
+
type FileFormat = 'JSON' | 'YAML' | 'MDX' | 'MD' | 'TS' | 'JS';
|
129
|
+
type CompletedFileTranslationData = {
|
130
|
+
locale: string;
|
131
|
+
metadata: any;
|
132
|
+
fileId: string;
|
133
|
+
fileName: string;
|
134
|
+
versionId: string;
|
135
|
+
id: string;
|
136
|
+
isReady: boolean;
|
137
|
+
downloadUrl: string;
|
138
|
+
};
|
139
|
+
|
140
|
+
type FileTranslationQuery = {
|
141
|
+
versionId: string;
|
142
|
+
fileName: string;
|
143
|
+
locale: string;
|
144
|
+
};
|
145
|
+
type CheckFileTranslationsOptions = {
|
146
|
+
timeout?: number;
|
147
|
+
};
|
148
|
+
type CheckFileTranslationsResult = {
|
149
|
+
translations: CompletedFileTranslationData[];
|
150
|
+
};
|
151
|
+
|
152
|
+
type DownloadFileBatchOptions = {
|
153
|
+
timeout?: number;
|
154
|
+
};
|
155
|
+
type File = {
|
156
|
+
id: string;
|
157
|
+
fileName: string;
|
158
|
+
data: string;
|
159
|
+
metadata: any;
|
160
|
+
};
|
161
|
+
type DownloadFileBatchResult = {
|
162
|
+
files: File[];
|
163
|
+
count: number;
|
164
|
+
};
|
165
|
+
|
166
|
+
type FetchTranslationsOptions = {
|
167
|
+
timeout?: number;
|
168
|
+
};
|
169
|
+
type RetrievedTranslation = {
|
170
|
+
locale: string;
|
171
|
+
translation: any;
|
172
|
+
};
|
173
|
+
type RetrievedTranslations = RetrievedTranslation[];
|
174
|
+
type FetchTranslationsResult = {
|
175
|
+
translations: RetrievedTranslations;
|
176
|
+
};
|
177
|
+
|
178
|
+
type Updates = ({
|
179
|
+
metadata: Record<string, any>;
|
180
|
+
} & ({
|
181
|
+
dataFormat: 'JSX';
|
182
|
+
source: JsxChildren;
|
183
|
+
} | {
|
184
|
+
dataFormat: 'ICU';
|
185
|
+
source: string;
|
186
|
+
} | {
|
187
|
+
dataFormat: 'I18NEXT';
|
188
|
+
source: string;
|
189
|
+
}))[];
|
190
|
+
/**
|
191
|
+
* File object structure for enqueueing files
|
192
|
+
* @param content - The content of the file
|
193
|
+
* @param fileName - The name of the file
|
194
|
+
* @param fileFormat - The format of the file (JSON, MDX, MD, etc.)
|
195
|
+
* @param dataFormat - The format of the data within the file
|
196
|
+
*/
|
197
|
+
interface FileToTranslate {
|
198
|
+
content: string;
|
199
|
+
fileName: string;
|
200
|
+
fileFormat: FileFormat;
|
201
|
+
dataFormat?: DataFormat;
|
202
|
+
}
|
203
|
+
type EnqueueFilesOptions = {
|
204
|
+
publish: boolean;
|
205
|
+
description?: string;
|
206
|
+
sourceLocale?: string;
|
207
|
+
targetLocales: string[];
|
208
|
+
_versionId?: string;
|
209
|
+
timeout?: number;
|
210
|
+
};
|
211
|
+
type EnqueueFilesResult = {
|
212
|
+
translations: CompletedFileTranslationData[];
|
213
|
+
data: Record<string, {
|
214
|
+
fileName: string;
|
215
|
+
versionId: string;
|
216
|
+
}>;
|
217
|
+
locales: string[];
|
218
|
+
message: string;
|
219
|
+
};
|
220
|
+
|
221
|
+
type EnqueueEntriesOptions = {
|
222
|
+
timeout?: number;
|
223
|
+
sourceLocale?: string;
|
224
|
+
targetLocales?: string[];
|
225
|
+
dataFormat?: DataFormat;
|
226
|
+
version?: string;
|
227
|
+
description?: string;
|
228
|
+
requireApproval?: boolean;
|
229
|
+
};
|
230
|
+
type EnqueueEntriesResult = {
|
231
|
+
versionId: string;
|
232
|
+
locales: string[];
|
233
|
+
message: string;
|
234
|
+
projectSettings: {
|
235
|
+
cdnEnabled: boolean;
|
236
|
+
requireApproval: boolean;
|
237
|
+
};
|
238
|
+
};
|
239
|
+
|
240
|
+
type DownloadFileOptions = {
|
241
|
+
timeout?: number;
|
242
|
+
};
|
243
|
+
|
244
|
+
/**
|
245
|
+
* TranslationResultReference is used to store the reference for a translation result.
|
246
|
+
*/
|
247
|
+
type TranslationResultReference = {
|
248
|
+
id?: string;
|
249
|
+
hash: string;
|
250
|
+
};
|
251
|
+
/**
|
252
|
+
* TypedResult is a union type that represents the different types of translations that can be returned.
|
253
|
+
*/
|
254
|
+
type TypedResult = {
|
255
|
+
translation: JsxChildren;
|
256
|
+
dataFormat: 'JSX';
|
257
|
+
} | {
|
258
|
+
translation: I18nextMessage | IcuMessage;
|
259
|
+
dataFormat: 'ICU' | 'I18NEXT';
|
260
|
+
};
|
261
|
+
/**
|
262
|
+
* RequestError is a type that represents an error that occurred during a translation request.
|
263
|
+
*/
|
264
|
+
type TranslationError = {
|
265
|
+
error: string;
|
266
|
+
code: number;
|
267
|
+
reference?: TranslationResultReference;
|
268
|
+
};
|
269
|
+
/**
|
270
|
+
* RequestSuccess is a type that represents a successful translation request.
|
271
|
+
*/
|
272
|
+
type RequestSuccess = TypedResult & {
|
273
|
+
locale: string;
|
274
|
+
reference: TranslationResultReference;
|
275
|
+
};
|
276
|
+
type TranslationResult = RequestSuccess | TranslationError;
|
277
|
+
|
278
|
+
/**
|
279
|
+
* BatchTranslationResult is the result of a batch translation request.
|
280
|
+
*/
|
281
|
+
type TranslateManyResult = Array<TranslationResult>;
|
282
|
+
|
283
|
+
type CustomMapping = Record<string, string | Partial<LocaleProperties>>;
|
284
|
+
|
285
|
+
/**
|
286
|
+
* @deprecated Use {@link Content} instead.
|
287
|
+
*/
|
288
|
+
type _Content = string | Array<string | Variable>;
|
289
|
+
/**
|
290
|
+
* Transformations are made from a prefix and a suffix.
|
291
|
+
*/
|
292
|
+
type Transformation = 'translate-client' | 'translate-server' | 'translate-runtime' | 'variable-variable' | 'variable-currency' | 'variable-datetime' | 'variable-number' | 'plural' | 'branch';
|
293
|
+
type TransformationPrefix = 'translate' | 'variable' | 'plural' | 'branch' | 'fragment';
|
294
|
+
type VariableTransformationSuffix = 'variable' | 'number' | 'datetime' | 'currency';
|
63
295
|
type Metadata = {
|
64
296
|
context?: string;
|
65
297
|
id?: string;
|
@@ -67,12 +299,11 @@ type Metadata = {
|
|
67
299
|
actionType?: 'standard' | 'fast' | string;
|
68
300
|
[key: string]: any;
|
69
301
|
};
|
70
|
-
type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';
|
71
302
|
type FormatVariables = Record<string, string | number | boolean | null | undefined | Date>;
|
72
303
|
type Update = {
|
73
304
|
type: 'content';
|
74
305
|
data: {
|
75
|
-
source:
|
306
|
+
source: _Content;
|
76
307
|
metadata: Metadata;
|
77
308
|
};
|
78
309
|
} | {
|
@@ -85,7 +316,7 @@ type Update = {
|
|
85
316
|
type Request = {
|
86
317
|
type: 'content';
|
87
318
|
data: {
|
88
|
-
source:
|
319
|
+
source: _Content;
|
89
320
|
targetLocale: string;
|
90
321
|
metadata: Metadata;
|
91
322
|
};
|
@@ -97,14 +328,20 @@ type Request = {
|
|
97
328
|
metadata: Metadata;
|
98
329
|
};
|
99
330
|
};
|
331
|
+
/**
|
332
|
+
* @deprecated Use {@link TranslationResult} instead.
|
333
|
+
*/
|
100
334
|
type ContentTranslationResult = {
|
101
|
-
translation:
|
335
|
+
translation: _Content;
|
102
336
|
locale: string;
|
103
337
|
reference?: {
|
104
338
|
id: string;
|
105
339
|
key: string;
|
106
340
|
};
|
107
341
|
};
|
342
|
+
/**
|
343
|
+
* @deprecated Use {@link TranslationResult} instead.
|
344
|
+
*/
|
108
345
|
type IcuTranslationResult = {
|
109
346
|
translation: string;
|
110
347
|
locale: string;
|
@@ -113,6 +350,9 @@ type IcuTranslationResult = {
|
|
113
350
|
key: string;
|
114
351
|
};
|
115
352
|
};
|
353
|
+
/**
|
354
|
+
* @deprecated Use {@link TranslationResult} instead.
|
355
|
+
*/
|
116
356
|
type JsxTranslationResult = {
|
117
357
|
translation: JsxChildren;
|
118
358
|
locale: string;
|
@@ -121,24 +361,19 @@ type JsxTranslationResult = {
|
|
121
361
|
key: string;
|
122
362
|
};
|
123
363
|
};
|
124
|
-
type TranslationError = {
|
125
|
-
error: string;
|
126
|
-
code: number;
|
127
|
-
reference?: {
|
128
|
-
id: string;
|
129
|
-
key: string;
|
130
|
-
};
|
131
|
-
};
|
132
364
|
|
133
|
-
type VariableType = 'v' | 'n' | 'd' | 'c';
|
134
365
|
/**
|
135
|
-
*
|
366
|
+
* TranslationRequestConfig is used to configure the translation request.
|
367
|
+
*
|
368
|
+
* @param projectId - The project id of the translation request.
|
369
|
+
* @param baseUrl - The base url of the translation request.
|
370
|
+
* @param apiKey - The api key of the translation request.
|
136
371
|
*/
|
137
|
-
type
|
138
|
-
|
139
|
-
|
140
|
-
|
372
|
+
type TranslationRequestConfig = {
|
373
|
+
projectId: string;
|
374
|
+
baseUrl?: string;
|
375
|
+
apiKey?: string;
|
141
376
|
};
|
142
377
|
|
143
378
|
export { HTML_CONTENT_PROPS };
|
144
|
-
export type { Content, ContentTranslationResult, CustomMapping, DataFormat, FormatVariables, GTProp, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, IcuTranslationResult, JsxChild, JsxChildren, JsxElement, JsxTranslationResult, LocaleProperties, Metadata, Request, Transformation, TransformationPrefix, TranslationError, Update, Variable, VariableTransformationSuffix, VariableType };
|
379
|
+
export type { CheckFileTranslationsOptions, CheckFileTranslationsResult, CompletedFileTranslationData, Content, ContentTranslationResult, CustomMapping, DataFormat, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, EnqueueEntriesOptions, EnqueueEntriesResult, EnqueueFilesOptions, EnqueueFilesResult, Entry, ActionType as EntryActionType, EntryMetadata, FetchTranslationsOptions, FetchTranslationsResult, FileFormat, FileToTranslate, FileTranslationQuery, FormatVariables, GTProp, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, IcuMessage, IcuTranslationResult, JsxChild, JsxChildren, JsxElement, JsxTranslationResult, LocaleProperties, Metadata, Request, RetrievedTranslations, Transformation, TransformationPrefix, TranslateManyResult, TranslationError, TranslationRequestConfig, TranslationResult, TranslationResultReference, TranslationStatusResult, Update, Updates, Variable, VariableTransformationSuffix, VariableType, _Content };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.esm.min.mjs","sources":["../src/types.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"file":"types.esm.min.mjs","sources":["../src/types-dir/content.ts"],"sourcesContent":["import { Variable } from './variables';\n\n/**\n * Map of data-_gt properties to their corresponding React props\n */\nexport const HTML_CONTENT_PROPS = {\n pl: 'placeholder',\n ti: 'title',\n alt: 'alt',\n arl: 'aria-label',\n arb: 'aria-labelledby',\n ard: 'aria-describedby',\n} as const;\n\nexport type HtmlContentPropKeysRecord = Partial<\n Record<keyof typeof HTML_CONTENT_PROPS, string>\n>;\nexport type HtmlContentPropValuesRecord = Partial<\n Record<(typeof HTML_CONTENT_PROPS)[keyof typeof HTML_CONTENT_PROPS], string>\n>;\n\n/**\n * GTProp is an internal property used to contain data for translating and rendering elements.\n * note, transformations are only read on the server side if they are 'plural' or 'branch'\n */\nexport type GTProp = {\n b?: Record<string, JsxChildren>; // Branches\n t?: 'p' | 'b'; // Branch Transformation\n} & HtmlContentPropKeysRecord;\n\nexport type JsxElement = {\n t?: string; // tag name\n i?: number; // id\n d?: GTProp; // GT data\n c?: JsxChildren; // children\n};\n\nexport type JsxChild = string | JsxElement | Variable;\n\n/**\n * The format of the content\n */\nexport type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';\n\n/**\n * A content type representing JSX, ICU, and I18next messages\n */\nexport type Content = JsxChildren | IcuMessage | I18nextMessage;\n\n/**\n * A content type representing JSX elements\n */\nexport type JsxChildren = JsxChild | JsxChild[];\n\n/**\n * A content type representing ICU messages\n */\nexport type IcuMessage = string;\n\n/**\n * A content type representing I18next messages\n */\nexport type I18nextMessage = string;\n"],"names":["HTML_CONTENT_PROPS","pl","ti","alt","arl","arb","ard"],"mappings":"AAKa,IAAAA,EAAqB,CAChCC,GAAI,cACJC,GAAI,QACJC,IAAK,MACLC,IAAK,aACLC,IAAK,kBACLC,IAAK"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "generaltranslation",
|
3
|
-
"version": "7.0.0",
|
3
|
+
"version": "7.1.0-alpha.0",
|
4
4
|
"description": "A language toolkit for AI developers",
|
5
5
|
"main": "dist/index.cjs.min.cjs",
|
6
6
|
"module": "dist/index.esm.min.mjs",
|
@@ -13,10 +13,10 @@
|
|
13
13
|
"build:release": "npm run build:clean",
|
14
14
|
"build:clean": "rm -rf dist; npm run build",
|
15
15
|
"build": "rollup -c",
|
16
|
-
"lint": "eslint \"src/**/*.{js,ts}\" \"__tests__/**/*.{js,ts}\"",
|
17
|
-
"lint:fix": "eslint \"src/**/*.{js,ts}\" \"__tests__/**/*.{js,ts}\" --fix",
|
18
|
-
"test": "vitest run",
|
19
|
-
"test:watch": "vitest",
|
16
|
+
"lint": "eslint \"src/**/*.{js,ts}\" \"./__e2e__/**/*.{js,ts}\" \"./**/__tests__/**/*.{js,ts}\"",
|
17
|
+
"lint:fix": "eslint \"src/**/*.{js,ts}\" \"./__e2e__/**/*.{js,ts}\" \"./**/__tests__/**/*.{js,ts}\" --fix",
|
18
|
+
"test": "vitest run --config=./vitest.config.ts",
|
19
|
+
"test:watch": "vitest --config=./vitest.config.ts",
|
20
20
|
"release": "npm run build:clean && npm publish",
|
21
21
|
"release:alpha": "npm run build:clean && npm publish --tag alpha",
|
22
22
|
"release:beta": "npm run build:clean && npm publish --tag beta",
|
@@ -1,4 +0,0 @@
|
|
1
|
-
export declare const noTargetLocaleProvidedError: (functionName: string) => string;
|
2
|
-
export declare const noSourceLocaleProvidedError: (functionName: string) => string;
|
3
|
-
export declare const invalidLocaleError: (locale: string) => string;
|
4
|
-
export declare const invalidLocalesError: (locales: string[]) => string;
|