generaltranslation
Version:
A language toolkit for AI developers
386 lines (368 loc) • 10.5 kB
TypeScript
type LocaleProperties = {
code: string;
name: string;
nativeName: string;
languageCode: string;
languageName: string;
nativeLanguageName: string;
nameWithRegionCode: string;
nativeNameWithRegionCode: string;
regionCode: string;
regionName: string;
nativeRegionName: string;
scriptCode: string;
scriptName: string;
nativeScriptName: string;
maximizedCode: string;
maximizedName: string;
nativeMaximizedName: string;
minimizedCode: string;
minimizedName: string;
nativeMinimizedName: string;
emoji: string;
};
type VariableType = 'v' | 'n' | 'd' | 'c';
/**
* Variables are used to store the variable name and type.
*/
type Variable = {
k: string;
i?: number;
v?: VariableType;
};
/**
* Map of data-_gt properties to their corresponding React props
*/
declare const HTML_CONTENT_PROPS: {
readonly pl: "placeholder";
readonly ti: "title";
readonly alt: "alt";
readonly arl: "aria-label";
readonly arb: "aria-labelledby";
readonly ard: "aria-describedby";
};
type HtmlContentPropKeysRecord = Partial<Record<keyof typeof HTML_CONTENT_PROPS, string>>;
type HtmlContentPropValuesRecord = Partial<Record<(typeof HTML_CONTENT_PROPS)[keyof typeof HTML_CONTENT_PROPS], string>>;
/**
* GTProp is an internal property used to contain data for translating and rendering elements.
* note, transformations are only read on the server side if they are 'plural' or 'branch'
*/
type GTProp = {
b?: Record<string, JsxChildren>;
t?: 'p' | 'b';
} & HtmlContentPropKeysRecord;
type JsxElement = {
t?: string;
i?: number;
d?: GTProp;
c?: JsxChildren;
};
type JsxChild = string | JsxElement | Variable;
/**
* The format of the content
*/
type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';
/**
* A content type representing JSX, ICU, and I18next messages
*/
type Content = JsxChildren | IcuMessage | I18nextMessage;
/**
* A content type representing JSX elements
*/
type JsxChildren = JsxChild | JsxChild[];
/**
* A content type representing ICU messages
*/
type IcuMessage = string;
/**
* A content type representing I18next messages
*/
type I18nextMessage = string;
/**
* ActionType is the type of action to perform on the request.
*
* @param standard - The standard action type (standard model).
* @param fast - The fast action type (mini model).
* @param string - Other model
*/
type ActionType = 'standard' | 'fast' | string;
/**
* EntryMetadata is the metadata for a GTRequest.
*
* @param context - The context of the request.
* @param id - The id of the request.
* @param hash - The hash of the request.
*/
type EntryMetadata = {
context?: string;
id?: string;
hash?: string;
dataFormat?: DataFormat;
sourceLocale?: string;
actionType?: ActionType;
timeout?: number;
};
/**
* GTRequest is a translation request object for {@link JsxChildren} | {@link IcuMessage} | {@link I18nextMessage}
*
* @param source - The source content to translate.
* @param targetLocale - The target locale to translate to.
* @param metadata - The metadata for the request.
*/
type Entry = {
source: Content;
targetLocale?: string;
metadata?: EntryMetadata;
};
type TranslationStatusResult = {
count: number;
availableLocales: string[];
locales: string[];
localesWaitingForApproval: any[];
};
type FileFormat = 'JSON' | 'YAML' | 'MDX' | 'MD' | 'TS' | 'JS';
type CompletedFileTranslationData = {
locale: string;
metadata: any;
fileId: string;
fileName: string;
versionId: string;
id: string;
isReady: boolean;
downloadUrl: string;
};
type FileTranslationQuery = {
versionId: string;
fileName: string;
locale: string;
};
type CheckFileTranslationsOptions = {
timeout?: number;
};
type CheckFileTranslationsResult = {
translations: CompletedFileTranslationData[];
};
type DownloadFileBatchOptions = {
timeout?: number;
};
type File = {
id: string;
fileName: string;
data: string;
metadata: any;
};
type DownloadFileBatchResult = {
files: File[];
count: number;
};
type FetchTranslationsOptions = {
timeout?: number;
};
type RetrievedTranslation = {
locale: string;
translation: any;
};
type RetrievedTranslations = RetrievedTranslation[];
type FetchTranslationsResult = {
translations: RetrievedTranslations;
};
type Updates = ({
metadata: Record<string, any>;
} & ({
dataFormat: 'JSX';
source: JsxChildren;
} | {
dataFormat: 'ICU';
source: string;
} | {
dataFormat: 'I18NEXT';
source: string;
}))[];
/**
* File object structure for enqueueing files
* @param content - The content of the file
* @param fileName - The name of the file
* @param fileFormat - The format of the file (JSON, MDX, MD, etc.)
* @param dataFormat - The format of the data within the file
*/
type FileToTranslate = {
content: string;
fileName: string;
fileFormat: FileFormat;
dataFormat?: DataFormat;
};
type EnqueueFilesOptions = {
publish: boolean;
description?: string;
sourceLocale?: string;
targetLocales: string[];
_versionId?: string;
timeout?: number;
};
type EnqueueFilesResult = {
translations: CompletedFileTranslationData[];
data: Record<string, {
fileName: string;
versionId: string;
}>;
locales: string[];
message: string;
};
type EnqueueEntriesOptions = {
timeout?: number;
sourceLocale?: string;
targetLocales?: string[];
dataFormat?: DataFormat;
version?: string;
description?: string;
requireApproval?: boolean;
};
type EnqueueEntriesResult = {
versionId: string;
locales: string[];
message: string;
projectSettings: {
cdnEnabled: boolean;
requireApproval: boolean;
};
};
type DownloadFileOptions = {
timeout?: number;
};
/**
* TranslationResultReference is used to store the reference for a translation result.
*/
type TranslationResultReference = {
id?: string;
hash: string;
};
/**
* TypedResult is a union type that represents the different types of translations that can be returned.
*/
type TypedResult = {
translation: JsxChildren;
dataFormat: 'JSX';
} | {
translation: I18nextMessage | IcuMessage;
dataFormat: 'ICU' | 'I18NEXT';
};
/**
* RequestError is a type that represents an error that occurred during a translation request.
*/
type TranslationError = {
error: string;
code: number;
reference?: TranslationResultReference;
};
/**
* RequestSuccess is a type that represents a successful translation request.
*/
type RequestSuccess = TypedResult & {
locale: string;
reference: TranslationResultReference;
};
type TranslationResult = RequestSuccess | TranslationError;
/**
* BatchTranslationResult is the result of a batch translation request.
*/
type TranslateManyResult = Array<TranslationResult>;
type CustomMapping = Record<string, string | Partial<LocaleProperties>>;
/**
* @deprecated Use {@link Content} instead.
*/
type _Content = string | Array<string | Variable>;
/**
* Transformations are made from a prefix and a suffix.
*/
type Transformation = 'translate-client' | 'translate-server' | 'translate-runtime' | 'variable-variable' | 'variable-currency' | 'variable-datetime' | 'variable-number' | 'plural' | 'branch';
type TransformationPrefix = 'translate' | 'variable' | 'plural' | 'branch' | 'fragment';
type VariableTransformationSuffix = 'variable' | 'number' | 'datetime' | 'currency';
type Metadata = {
context?: string;
id?: string;
sourceLocale?: string;
actionType?: 'standard' | 'fast' | string;
[key: string]: any;
};
type FormatVariables = Record<string, string | number | boolean | null | undefined | Date>;
/**
* @deprecated This type is deprecated and will be removed in a future version.
*/
type Update = {
type: 'content';
data: {
source: _Content;
metadata: Metadata;
};
} | {
type: 'jsx';
data: {
source: JsxChildren;
metadata: Metadata;
};
};
/**
* @deprecated This type is deprecated and will be removed in a future version.
*/
type Request = {
type: 'content';
data: {
source: _Content;
targetLocale: string;
metadata: Metadata;
};
} | {
type: 'jsx';
data: {
source: JsxChildren;
targetLocale: string;
metadata: Metadata;
};
};
/**
* @deprecated Use {@link TranslationResult} instead.
*/
type ContentTranslationResult = {
translation: _Content;
locale: string;
reference?: {
id: string;
key: string;
};
};
/**
* @deprecated Use {@link TranslationResult} instead.
*/
type IcuTranslationResult = {
translation: string;
locale: string;
reference?: {
id: string;
key: string;
};
};
/**
* @deprecated Use {@link TranslationResult} instead.
*/
type JsxTranslationResult = {
translation: JsxChildren;
locale: string;
reference?: {
id: string;
key: string;
};
};
/**
* TranslationRequestConfig is used to configure the translation request.
*
* @param projectId - The project id of the translation request.
* @param baseUrl - The base url of the translation request.
* @param apiKey - The api key of the translation request.
*/
type TranslationRequestConfig = {
projectId: string;
baseUrl?: string;
apiKey?: string;
};
export { HTML_CONTENT_PROPS };
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 };