import { CustomMapping, FormatVariables, TranslateManyResult, TranslationError, TranslationResult, EnqueueFilesResult, CheckFileTranslationsOptions, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, TranslateManyEntry } from './types'; import { LocaleProperties } from './locales/getLocaleProperties'; import { SetupProjectResult, SetupProjectOptions } from './translate/setupProject'; import { EnqueueOptions } from './translate/enqueueFiles'; import { CreateTagOptions, CreateTagResult } from './translate/createTag'; import { FileQuery, FileQueryResult } from './types-dir/api/checkFileTranslations'; import { SubmitUserEditDiffsPayload } from './translate/submitUserEditDiffs'; import { CustomRegionMapping } from './locales/getRegionProperties'; import { FileUpload, UploadFilesOptions, UploadFilesResponse } from './types-dir/api/uploadFiles'; import { ProjectData } from './types-dir/api/project'; import { DownloadFileBatchRequest } from './types-dir/api/downloadFileBatch'; import { CheckJobStatusResult } from './translate/checkJobStatus'; import { AwaitJobsOptions, AwaitJobsResult } from './translate/awaitJobs'; import type { FileDataQuery, FileDataResult } from './translate/queryFileData'; import type { BranchQuery } from './translate/queryBranchData'; import type { BranchDataResult } from './types-dir/api/branch'; import type { CreateBranchQuery, CreateBranchResult } from './translate/createBranch'; import type { FileReference, FileReferenceIds } from './types-dir/api/file'; import { type MoveMapping, type ProcessMovesResponse, type ProcessMovesOptions } from './translate/processFileMoves'; import { type GetOrphanedFilesResult } from './translate/getOrphanedFiles'; import { type PublishFileEntry, type PublishFilesResult } from './translate/publishFiles'; import { CutoffFormatOptions } from './formatting/custom-formats/CutoffFormat/types'; import { TranslateOptions } from './types-dir/api/entry'; import { StringFormat } from './types-dir/jsx/content'; import { LocaleConfig } from './LocaleConfig'; export { LocaleConfig, type LocaleConfigConstructorParams, } from './LocaleConfig'; export { formatCutoff, formatMessage, isValidLocale, resolveCanonicalLocale, standardizeLocale, } from './core'; /** * Type representing the constructor parameters for the GT class. * @typedef {Object} GTConstructorParams * @property {string} [apiKey] - The API key for accessing the translation service * @property {string} [devApiKey] - The development API key for accessing the translation service * @property {string} [sourceLocale] - The default source locale for translations * @property {string} [targetLocale] - The default target locale for translations * @property {string[]} [locales] - Array of supported locales * @property {string} [projectId] - The project ID for the translation service * @property {string} [baseUrl] - The base URL for the translation service * @property {CustomMapping} [customMapping] - Custom mapping of locale codes to their names */ type GTConstructorParams = { apiKey?: string; devApiKey?: string; sourceLocale?: string; targetLocale?: string; locales?: string[]; projectId?: string; baseUrl?: string; customMapping?: CustomMapping; }; /** * GT is the core driver for the General Translation library. * This class provides functionality for locale management, formatting, and translation operations. * * @class GT * @description A comprehensive toolkit for handling internationalization and localization. * * @example * const gt = new GT({ * sourceLocale: 'en-US', * targetLocale: 'es-ES', * locales: ['en-US', 'es-ES', 'fr-FR'] * }); */ export declare class GT { /** Base URL for the translation service API */ baseUrl?: string; /** Project ID for the translation service */ projectId?: string; /** API key for accessing the translation service */ apiKey?: string; /** Development API key for accessing the translation service */ devApiKey?: string; /** Source locale for translations */ sourceLocale?: string; /** Target locale for translations */ targetLocale?: string; /** Array of supported locales */ locales?: string[]; /** Custom mapping for locale codes to their names */ customMapping?: CustomMapping; /** Lazily derived reverse custom mapping for alias locales */ reverseCustomMapping?: Record; /** Lazily derived custom mapping for regions */ customRegionMapping?: CustomRegionMapping; /** Runtime-safe locale and formatting helpers (backing field) */ private _localeConfig; /** Runtime-safe locale and formatting helpers */ get localeConfig(): LocaleConfig; /** * Constructs an instance of the GT class. * * @param {GTConstructorParams} [params] - The parameters for initializing the GT instance * @throws {Error} If an invalid locale is provided * @throws {Error} If any of the provided locales are invalid * * @example * const gt = new GT({ * apiKey: 'your-api-key', * sourceLocale: 'en-US', * targetLocale: 'es-ES', * locales: ['en-US', 'es-ES', 'fr-FR'] * }); */ constructor(params?: GTConstructorParams); setConfig({ apiKey, devApiKey, sourceLocale, targetLocale, locales, projectId, customMapping, baseUrl, }: GTConstructorParams): void; private _getTranslationConfig; private _validateAuth; /** * Queries branch information from the API. * * @param {BranchQuery} query - Object mapping the current branch and incoming branches * @returns {Promise} The branch information. */ queryBranchData(query: BranchQuery): Promise; /** * Creates a new branch in the API. If the branch already exists, it will be returned. * * @param {CreateBranchQuery} query - Object mapping the branch name and default branch flag * @returns {Promise} The created branch information. */ createBranch(query: CreateBranchQuery): Promise; /** * Processes file moves by cloning source files and translations with new fileIds. * This is called when files have been moved/renamed and we want to preserve translations. * * @param {MoveMapping[]} moves - Array of move mappings (old fileId to new fileId) * @param {ProcessMovesOptions} options - Options including branchId and timeout * @returns {Promise} The move processing results. * * @example * const result = await gt.processFileMoves([ * { oldFileId: 'abc123', newFileId: 'def456', newFileName: 'locales/en.json' } * ], { branchId: 'main' }); */ processFileMoves(moves: MoveMapping[], options?: ProcessMovesOptions): Promise; /** * Gets orphaned files for a branch - files that exist on the branch * but whose fileIds are not in the provided list. * Used for move detection. * * @param {string} branchId - The branch to check for orphaned files. * @param {string[]} fileIds - List of current file IDs (files that are NOT orphaned) * @param {Object} options - Options including timeout. * @returns {Promise} The orphaned files. * * @example * const result = await gt.getOrphanedFiles('branch-id', ['file-1', 'file-2']); */ getOrphanedFiles(branchId: string, fileIds: string[], options?: { timeout?: number; }): Promise; /** * Enqueues project setup job using the specified file references * * This method creates setup jobs that will process source file references * and generate a project setup. The files parameter contains references (IDs) to source * files that have already been uploaded via uploadSourceFiles. The setup jobs are queued * for processing and will generate a project setup based on the source files. * * @param {FileReference[]} files - Array of file references containing IDs of previously uploaded source files * @param {SetupProjectOptions} [options] - Optional settings for target locales and timeout. * @returns {Promise} Object containing the jobId and status */ setupProject(files: FileReference[], options?: SetupProjectOptions): Promise; /** * Checks the current status of one or more project jobs by their unique identifiers. * * This method polls the API to determine whether one or more jobs are still running, * have completed successfully, or have failed. Jobs are created after calling either enqueueFiles or setupProject. * * @param {string[]} jobIds - The unique identifiers of the jobs to check. * @param {number} [timeoutMs] - Optional timeout in milliseconds for the API request. * @returns {Promise} Object containing the job status. * * @example * const result = await gt.checkJobStatus([ * 'job-123', * 'job-456', * ], { * timeout: 10000, * }); */ checkJobStatus(jobIds: string[], timeoutMs?: number): Promise; /** * Polls job statuses until all jobs from enqueueFiles are finished or the timeout is reached. * * @param {EnqueueFilesResult} enqueueResult - The result returned from enqueueFiles. * @param {AwaitJobsOptions} [options] - Polling configuration (interval, timeout). * @returns {Promise} The final status of all jobs and whether they all completed. */ awaitJobs(enqueueResult: EnqueueFilesResult, options?: AwaitJobsOptions): Promise; /** * Enqueues translation jobs for previously uploaded source files. * * This method creates translation jobs that will process existing source files * and generate translations in the specified target languages. The files parameter * contains references (IDs) to source files that have already been uploaded via * uploadSourceFiles. The translation jobs are queued for processing and will * generate translated content based on the source files and target locales provided. * * @param {FileReferenceIds[]} files - Array of file references containing IDs of previously uploaded source files * @param {EnqueueOptions} options - Configuration options including source locale, target locales, and job settings. * @returns {Promise} Result containing job IDs, queue status, and processing information. */ enqueueFiles(files: FileReferenceIds[], options: EnqueueOptions): Promise; /** * Creates or upserts a file tag, associating a set of source files * with a user-defined tag ID and optional message. * * @param {CreateTagOptions} options - Tag creation options including tagId, sourceFileIds, and optional message * @returns {Promise} The created or updated tag. */ createTag(options: CreateTagOptions): Promise; /** * Publishes or unpublishes files on the CDN. * * @param {PublishFileEntry[]} files - Array of file entries with publish flags * @returns {Promise} Result containing per-file success/failure */ publishFiles(files: PublishFileEntry[]): Promise; /** * Submits user edit diffs for existing translations so future generations preserve user intent. * * @param {SubmitUserEditDiffsPayload} payload - Project-scoped diff payload. * @returns {Promise} Resolves when submission succeeds. */ submitUserEditDiffs(payload: SubmitUserEditDiffsPayload): Promise; /** * Queries data about one or more source or translation files. * * @param {FileDataQuery} data - Object mapping source and translation file information. * @param {CheckFileTranslationsOptions} options - Options for the API call. * @returns {Promise} The source and translation file data information. * * @example * const result = await gt.queryFileData({ * sourceFiles: [ * { fileId: '1234567890', versionId: '1234567890', branchId: '1234567890' }, * ], * translatedFiles: [ * { fileId: '1234567890', versionId: '1234567890', branchId: '1234567890', locale: 'es-ES' }, * ], * }, { * timeout: 10000, * }); * */ queryFileData(data: FileDataQuery, options?: CheckFileTranslationsOptions): Promise; /** * Gets source and translation information for a given file ID and version ID. * * @param {FileQuery} data - File query containing file ID and version ID. * @param {CheckFileTranslationsOptions} options - Options for getting source and translation information. * @returns {Promise} The source file and translation information. * * @example * const result = await gt.querySourceFile( * { fileId: '1234567890', versionId: '1234567890' }, * { timeout: 10000 } * ); * */ querySourceFile(data: FileQuery, options?: CheckFileTranslationsOptions): Promise; /** * Get project data for a given project ID. * * @param {string} projectId - The ID of the project to get the data for. * @returns {Promise} The project data. * * @example * const result = await gt.getProjectData( * '1234567890' * ); * */ getProjectData(projectId: string, options?: { timeout?: number; }): Promise; /** * Downloads a single file. * * @param file - The file query object. * @param {string} file.fileId - The ID of the file to download. * @param {string} [file.branchId] - The ID of the branch to download the file from. If not provided, the default branch will be used. * @param {string} [file.locale] - The locale to download the file for. If not provided, the source file will be downloaded. * @param {string} [file.versionId] - The version ID to download the file from. If not provided, the latest version will be used. * @param {DownloadFileOptions} options - Options for downloading the file. * @returns {Promise} The downloaded file content. * * @example * const result = await gt.downloadFile({ * fileId: '1234567890', * branchId: '1234567890', * locale: 'es-ES', * versionId: '1234567890', * }, { * timeout: 10000, * }); */ downloadFile(file: { fileId: string; branchId?: string; locale?: string; versionId?: string; useLatestAvailableVersion?: boolean; }, options?: DownloadFileOptions): Promise; /** * Downloads multiple files in a batch. * * @param {DownloadFileBatchRequest} requests - Array of file query objects to download. * @param {DownloadFileBatchOptions} options - Options for the batch download. * @returns {Promise} The batch download results. * * @example * const result = await gt.downloadFileBatch([{ * fileId: '1234567890', * locale: 'es-ES', * versionId: '1234567890', * }], { * timeout: 10000, * }); */ downloadFileBatch(requests: DownloadFileBatchRequest, options?: DownloadFileBatchOptions): Promise; /** * Translates a single source string to the target locale. * Routes through {@link translateMany} under the hood. * * @param {string} source - The source string to translate. * @param {object} options - Translation options including targetLocale and optional entry metadata. * @returns {Promise} The translated content. * * @example * const result = await gt.translate('Hello, world!', { targetLocale: 'es' }); * * @example * const result = await gt.translate('Hello, world!', { * targetLocale: 'es', * dataFormat: 'ICU', * context: 'A formal greeting', * }); */ translate(source: TranslateManyEntry, options: string | TranslateOptions, timeout?: number): Promise; /** * Translates multiple source strings to the target locale. * Each entry can be a plain string or an object with source and metadata fields. * * @param {TranslateManyEntry[] | Record} sources - The source entries to translate. Can be an array or a record keyed by hash. * @param {object} options - Translation options including targetLocale. * @returns {Promise>} The translated contents. An array if sources was an array, a record if sources was a record. * * @example * const result = await gt.translateMany( * ['Hello, world!', 'Goodbye, world!'], * { targetLocale: 'es' } * ); * * @example * const result = await gt.translateMany( * [{ source: 'Hello, world!', dataFormat: 'ICU' }], * { targetLocale: 'es' } * ); * * @example * const result = await gt.translateMany( * { 'my-hash': 'Hello, world!' }, * { targetLocale: 'es' } * ); */ translateMany(sources: TranslateManyEntry[], options: string | TranslateOptions, timeout?: number): Promise; translateMany(sources: Record, options: string | TranslateOptions, timeout?: number): Promise>; /** * Uploads source files to the translation service without any translation content. * * This method creates or replaces source file entries in your project. Each uploaded * file becomes a source that can later be translated into target languages. The files * are processed and stored as base entries that serve as the foundation for generating * translations through the translation workflow. * * @param {Array<{source: FileUpload}>} files - Array of objects containing source file data to upload * @param {UploadFilesOptions} options - Configuration options including source locale and other upload settings. * @returns {Promise} Upload result containing file IDs, version information, and upload status. */ uploadSourceFiles(files: { source: FileUpload; }[], options: UploadFilesOptions): Promise; /** * Uploads translation files that correspond to previously uploaded source files. * * This method allows you to provide translated content for existing source files in your project. * Each translation must reference an existing source file and include the translated content * along with the target locale information. This is used when you have pre-existing translations * that you want to upload directly rather than generating them through the translation service. * * @param {Array<{source: FileUpload, translations: FileUpload[]}>} files - Array of file objects where: * - `source`: Reference to the existing source file (contains IDs but no content). * - `translations`: Array of translated files, each containing content, locale, and reference IDs * @param {UploadFilesOptions} options - Configuration options including source locale and upload settings. * @returns {Promise} Upload result containing translation IDs, status, and processing information. */ uploadTranslations(files: { source: FileUpload; translations: FileUpload[]; }[], options: UploadFilesOptions): Promise; /** * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit. * * This method uses the GT instance's rendering locales by default for locale-specific terminator selection, * but can be overridden with custom locales in the options. * * @param {string} value - The string value to format with cutoff behavior. * @param {Object} [options] - Configuration options for cutoff formatting. * @param {string | string[]} [options.locales] - The locales to use for terminator selection. Defaults to instance's rendering locales. * @param {number} [options.maxChars] - The maximum number of characters to display. * - Undefined values are treated as no cutoff. * - Negative values follow .slice() behavior and terminator will be added before the value. * - 0 will result in an empty string. * - If cutoff results in an empty string, no terminator is added. * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator. * @param {string} [options.terminator] - Optional override the terminator to use. * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value. * - If no terminator is provided, then separator is ignored. * @returns {string} The formatted string with terminator applied if cutoff occurs. * * @example * const gt = new GT({ targetLocale: 'en-US' }); * gt.formatCutoff('Hello, world!', { maxChars: 8 }); * // Returns: 'Hello, w...' * * @example * gt.formatCutoff('Hello, world!', { maxChars: -3 }); * // Returns: '...ld!' */ formatCutoff(value: string, options?: { locales?: string | string[]; } & CutoffFormatOptions): string; /** * Formats a message according to the specified locales and options. * * @param {string} message - The message to format. * @param {string | string[]} [locales='en'] - The locales to use for formatting. * @param {FormatVariables} [variables={}] - The variables to use for formatting. * @param {StringFormat} [dataFormat='ICU'] - The format of the message. * @returns {string} The formatted message. * * @example * gt.formatMessage('Hello {name}', { name: 'John' }); * // Returns: "Hello John" * * gt.formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] }); * // Returns: "Bonjour John" */ formatMessage(message: string, options?: { locales?: string | string[]; variables?: FormatVariables; dataFormat?: StringFormat; }): string; /** * Formats a number according to the specified locales and options. * * @param {number} number - The number to format. * @param {Object} [options] - Additional options for number formatting. * @param {string | string[]} [options.locales] - The locales to use for formatting. * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options. * @returns {string} The formatted number. * * @example * gt.formatNum(1234.56, { style: 'currency', currency: 'USD' }); * // Returns: "$1,234.56" */ formatNum(number: number, options?: { locales?: string | string[]; } & Intl.NumberFormatOptions): string; /** * Formats a date according to the specified locales and options. * * @param {Date} date - The date to format. * @param {Object} [options] - Additional options for date formatting. * @param {string | string[]} [options.locales] - The locales to use for formatting. * @param {Intl.DateTimeFormatOptions} [options] - Additional Intl.DateTimeFormat options. * @returns {string} The formatted date. * * @example * gt.formatDateTime(new Date(), { dateStyle: 'full', timeStyle: 'long' }); * // Returns: "Thursday, March 14, 2024 at 2:30:45 PM GMT-7" */ formatDateTime(date: Date, options?: { locales?: string | string[]; } & Intl.DateTimeFormatOptions): string; /** * Formats a currency value according to the specified locales and options. * * @param {number} value - The currency value to format. * @param {string} currency - The currency code (e.g., 'USD', 'EUR') * @param {Object} [options] - Additional options for currency formatting. * @param {string | string[]} [options.locales] - The locales to use for formatting. * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options. * @returns {string} The formatted currency value. * * @example * gt.formatCurrency(1234.56, 'USD', { style: 'currency' }); * // Returns: "$1,234.56" */ formatCurrency(value: number, currency: string, options?: { locales?: string | string[]; } & Intl.NumberFormatOptions): string; /** * Formats a list of items according to the specified locales and options. * * @param {Array} array - The list of items to format. * @param {Object} [options] - Additional options for list formatting. * @param {string | string[]} [options.locales] - The locales to use for formatting. * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options. * @returns {string} The formatted list. * * @example * gt.formatList(['apple', 'banana', 'orange'], { type: 'conjunction' }); * // Returns: "apple, banana, and orange" */ formatList(array: Array, options?: { locales?: string | string[]; } & Intl.ListFormatOptions): string; /** * Formats a list of items according to the specified locales and options. * @param {Array} array - The list of items to format. * @param {Object} [options] - Additional options for list formatting. * @param {string | string[]} [options.locales] - The locales to use for formatting. * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options. * @returns {Array} The formatted list parts. * * @example * gt.formatListToParts(['apple', 42, { foo: 'bar' }], { type: 'conjunction', style: 'short', locales: ['en'] }); * // Returns: ['apple', ', ', 42, ' and ', '{ foo: "bar" }'] */ formatListToParts(array: Array, options?: { locales?: string | string[]; } & Intl.ListFormatOptions): Array; /** * Formats a relative time value according to the specified locales and options. * * @param {number} value - The relative time value to format. * @param {Intl.RelativeTimeFormatUnit} unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year') * @param {Object} options - Additional options for relative time formatting. * @param {string | string[]} [options.locales] - The locales to use for formatting. * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options. * @returns {string} The formatted relative time string. * * @example * gt.formatRelativeTime(-1, 'day', { locales: ['en-US'], numeric: 'auto' }); * // Returns: "yesterday" */ formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options?: { locales?: string | string[]; } & Omit): string; /** * Formats a relative time string from a Date, automatically selecting the best unit. * * @param {Date} date - The date to format relative to now. * @param {Object} [options] - Additional options for relative time formatting. * @param {string | string[]} [options.locales] - The locales to use for formatting. * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days") * * @example * gt.formatRelativeTimeFromDate(new Date(Date.now() - 3600000)); * // Returns: "1 hour ago" */ formatRelativeTimeFromDate(date: Date, options?: { locales?: string | string[]; baseDate?: Date; } & Omit): string; /** * Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found. * * @param {string} [locale=this.targetLocale] - A BCP-47 locale code. * @returns {string} The display name corresponding to the code. * @throws {Error} If no target locale is provided. * * @example * gt.getLocaleName('es-ES'); * // Returns: "Spanish (Spain)" */ getLocaleName(locale?: string | undefined): string; /** * Retrieves an emoji based on a given locale code. * Uses the locale's region (if present) to select an emoji or falls back on default emojis. * * @param {string} [locale=this.targetLocale] - A BCP-47 locale code (e.g., 'en-US', 'fr-CA') * @returns {string} The emoji representing the locale or its region. * @throws {Error} If no target locale is provided. * * @example * gt.getLocaleEmoji('es-ES'); * // Returns: "🇪🇸" */ getLocaleEmoji(locale?: string | undefined): string; /** * Generates linguistic details for a given locale code. * * This function returns information about the locale, * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region). * The function provides these names in both your default language and native forms, and an associated emoji. * * @param {string} [locale=this.targetLocale] - The locale code to get properties for (e.g., "de-AT"). * @returns {LocaleProperties} - An object containing detailed information about the locale. * * @property {string} code - The full locale code, e.g., "de-AT". * @property {string} name - Language name in the default display language, e.g., "Austrian German". * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch". * @property {string} languageCode - The base language code, e.g., "de". * @property {string} languageName - The language name in the default display language, e.g., "German". * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch". * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)". * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)". * @property {string} regionCode - The region code from maximization, e.g., "AT". * @property {string} regionName - The region name in the default display language, e.g., "Austria". * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich". * @property {string} scriptCode - The script code from maximization, e.g., "Latn". * @property {string} scriptName - The script name in the default display language, e.g., "Latin". * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch". * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT". * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)". * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)". * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE"). * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German". * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch". * @property {string} emoji - The emoji associated with the locale's region, if applicable. */ getLocaleProperties(locale?: string | undefined): LocaleProperties; /** * Retrieves multiple properties for a given region code, including: * - `code`: the original region code * - `name`: the localized display name * - `emoji`: the associated flag or symbol * * Behavior: * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`). * - Uses the instance's `targetLocale` to localize the region name for the user. * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values. * - Otherwise, uses `Intl.DisplayNames` to get the localized region name, falling back to `libraryDefaultLocale`. * - Falls back to the region code as `name` if display name resolution fails. * - Falls back to a default emoji if no emoji mapping is found in built-in data or `customMapping`. * * @param {string} [region=this.getLocaleProperties().regionCode] - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`). * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis. * @returns {{ code: string, name: string, emoji: string }} An object containing: * - `code`: the input region code * - `name`: the localized or custom region name * - `emoji`: the matching emoji flag or symbol * * @throws {Error} If no target locale is available to determine region properties. * * @example * const gt = new GT({ targetLocale: 'en-US' }); * gt.getRegionProperties('US'); * // => { code: 'US', name: 'United States', emoji: '🇺🇸' } * * @example * const gt = new GT({ targetLocale: 'fr-FR' }); * gt.getRegionProperties('US'); * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' } * * @example * gt.getRegionProperties('US', { US: { name: 'USA', emoji: '🗽' } }); * // => { code: 'US', name: 'USA', emoji: '🗽' } */ getRegionProperties(region?: string, customMapping?: CustomRegionMapping): { code: string; name: string; emoji: string; }; /** * Determines whether a translation is required based on the source and target locales. * * @param {string} [sourceLocale=this.sourceLocale] - The locale code for the original content. * @param {string} [targetLocale=this.targetLocale] - The locale code to translate into. * @param {string[]} [approvedLocales=this.locales] - Optional array of approved target locales. * @returns {boolean} True if translation is required, false otherwise * @throws {Error} If no source locale is provided. * @throws {Error} If no target locale is provided. * * @example * gt.requiresTranslation('en-US', 'es-ES'); * // Returns: true */ requiresTranslation(sourceLocale?: string | undefined, targetLocale?: string | undefined, approvedLocales?: string[] | undefined, customMapping?: CustomMapping | undefined): boolean; /** * Determines the best matching locale from the provided approved locales list. * * @param {string | string[]} locales - A single locale or array of locales in preference order. * @param {string[]} [approvedLocales=this.locales] - Array of approved locales in preference order. * @returns {string | undefined} The best matching locale, or undefined if no match is found. * * @example * gt.determineLocale(['fr-CA', 'fr-FR'], ['en-US', 'fr-FR', 'es-ES']); * // Returns: "fr-FR" */ determineLocale(locales: string | string[], approvedLocales?: string[] | undefined, customMapping?: CustomMapping | undefined): string | undefined; /** * Gets the text direction for a given locale code. * * @param {string} [locale=this.targetLocale] - A BCP-47 locale code. * @returns {'ltr' | 'rtl'} 'rtl' if the locale is right-to-left; otherwise 'ltr'. * @throws {Error} If no target locale is provided. * * @example * gt.getLocaleDirection('ar-SA'); * // Returns: "rtl" */ getLocaleDirection(locale?: string | undefined): 'ltr' | 'rtl'; /** * Checks if a given BCP 47 locale code is valid. * * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to validate. * @param {CustomMapping} [customMapping=this.customMapping] - The custom mapping to use for validation. * @returns {boolean} True if the locale code is valid, false otherwise * @throws {Error} If no target locale is provided. * * @example * gt.isValidLocale('en-US'); * // Returns: true */ isValidLocale(locale?: string | undefined, customMapping?: CustomMapping | undefined): boolean; /** * Resolves the canonical locale for a given locale. * @param locale - The locale to resolve the canonical locale for * @param customMapping - The custom mapping to use for resolving the canonical locale * @returns The canonical locale, or the input locale when no canonical mapping exists. */ resolveCanonicalLocale(locale?: string | undefined, customMapping?: CustomMapping | undefined): string; /** * Resolves the alias locale for a given locale. * @param locale - The locale to resolve the alias locale for * @param customMapping - The custom mapping to use for resolving the alias locale * @returns The configured alias for a canonical locale, or the input locale when already an alias or no alias mapping exists. */ resolveAliasLocale(locale: string, customMapping?: CustomMapping | undefined): string; /** * Standardizes a BCP 47 locale code to ensure correct formatting. * * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to standardize. * @returns {string} The standardized locale code, or the input string if it cannot be standardized. * @throws {Error} If no target locale is provided. * * @example * gt.standardizeLocale('en_us'); * // Returns: "en-US" */ standardizeLocale(locale?: string | undefined): string; /** * Checks if multiple BCP 47 locale codes represent the same dialect. * * @param {...(string | string[])} locales - The BCP 47 locale codes to compare. * @returns {boolean} True if all codes represent the same dialect, false otherwise * * @example * gt.isSameDialect('en-US', 'en-GB'); * // Returns: false * * gt.isSameDialect('en', 'en-US'); * // Returns: true */ isSameDialect(...locales: (string | string[])[]): boolean; /** * Checks if multiple BCP 47 locale codes represent the same language. * * @param {...(string | string[])} locales - The BCP 47 locale codes to compare. * @returns {boolean} True if all codes represent the same language, false otherwise * * @example * gt.isSameLanguage('en-US', 'en-GB'); * // Returns: true */ isSameLanguage(...locales: (string | string[])[]): boolean; /** * Checks if a locale is a superset of another locale. * * @param {string} superLocale - The locale to check if it is a superset * @param {string} subLocale - The locale to check if it is a subset * @returns {boolean} True if superLocale is a superset of subLocale, false otherwise * * @example * gt.isSupersetLocale('en', 'en-US'); * // Returns: true * * gt.isSupersetLocale('en-US', 'en'); * // Returns: false */ isSupersetLocale(superLocale: string, subLocale: string): boolean; } /** * Formats a number according to the specified locales and options. * @param {Object} params - The parameters for the number formatting. * @param {number} params.value - The number to format. * @param {Intl.NumberFormatOptions} [params.options] - Additional options for number formatting. * @param {string | string[]} [params.options.locales] - The locales to use for formatting. * @returns {string} The formatted number. */ export declare function formatNum(number: number, options: { locales: string | string[]; } & Intl.NumberFormatOptions): string; /** * Formats a date according to the specified languages and options. * @param {Object} params - The parameters for the date formatting. * @param {Date} params.value - The date to format. * @param {Intl.DateTimeFormatOptions} [params.options] - Additional options for date formatting. * @param {string | string[]} [params.options.locales] - The languages to use for formatting. * @returns {string} The formatted date. */ export declare function formatDateTime(date: Date, options?: { locales?: string | string[]; } & Intl.DateTimeFormatOptions): string; /** * Formats a currency value according to the specified languages, currency, and options. * @param {Object} params - The parameters for the currency formatting. * @param {number} params.value - The currency value to format. * @param {string} params.currency - The currency code (e.g., 'USD'). * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting. * @param {string | string[]} [params.options.locales] - The locale codes to use for formatting. * @returns {string} The formatted currency value. */ export declare function formatCurrency(value: number, currency: string, options: { locales: string | string[]; } & Intl.NumberFormatOptions): string; /** * Formats a list of items according to the specified locales and options. * @param {Object} params - The parameters for the list formatting. * @param {Array} params.value - The list of items to format. * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting. * @param {string | string[]} [params.options.locales] - The locales to use for formatting. * @returns {string} The formatted list. */ export declare function formatList(array: Array, options: { locales: string | string[]; } & Intl.ListFormatOptions): string; /** * Formats a list of items according to the specified locales and options. * @param {Array} array - The list of items to format. * @param {Object} [options] - Additional options for list formatting. * @param {string | string[]} [options.locales] - The locales to use for formatting. * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options. * @returns {Array} The formatted list parts. */ export declare function formatListToParts(array: Array, options?: { locales?: string | string[]; } & Intl.ListFormatOptions): Array; /** * Formats a relative time value according to the specified locales and options. * @param {Object} params - The parameters for the relative time formatting. * @param {number} params.value - The relative time value to format. * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year'). * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting. * @param {string | string[]} [params.options.locales] - The locales to use for formatting. * @returns {string} The formatted relative time string. */ export declare function formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options: { locales: string | string[]; } & Omit): string; /** * Formats a relative time string from a Date, automatically selecting the best unit. * @param {Date} date - The date to format relative to now. * @param {Object} options - Formatting options. * @param {string | string[]} options.locales - The locales to use for formatting. * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options. * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days"). */ export declare function formatRelativeTimeFromDate(date: Date, options: { locales: string | string[]; baseDate?: Date; } & Omit): string; /** * Retrieves the display name of locale code using Intl.DisplayNames. * * @param {string} locale - A BCP-47 locale code. * @param {string} [defaultLocale] - The default locale to use for formatting. * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names. * @returns {string} The display name corresponding to the code. */ export declare function getLocaleName(locale: string, defaultLocale?: string, customMapping?: CustomMapping): string; /** * Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions. * * This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages. * * @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA'). * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names. * @returns The emoji representing the locale or its region, or a default emoji if no specific match is found. */ export declare function getLocaleEmoji(locale: string, customMapping?: CustomMapping): string; /** * Generates linguistic details for a given locale code. * * This function returns information about the locale, * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region). * The function provides these names in both your default language and native forms, and an associated emoji. * * @param {string} locale - The locale code to get properties for (e.g., "de-AT"). * @param {string} [defaultLocale] - The default locale to use for formatting. * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names. * @returns {LocaleProperties} - An object containing detailed information about the locale. * * @property {string} code - The full locale code, e.g., "de-AT". * @property {string} name - Language name in the default display language, e.g., "Austrian German". * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch". * @property {string} languageCode - The base language code, e.g., "de". * @property {string} languageName - The language name in the default display language, e.g., "German". * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch". * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)". * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)". * @property {string} regionCode - The region code from maximization, e.g., "AT". * @property {string} regionName - The region name in the default display language, e.g., "Austria". * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich". * @property {string} scriptCode - The script code from maximization, e.g., "Latn". * @property {string} scriptName - The script name in the default display language, e.g., "Latin". * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch". * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT". * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)". * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)". * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE"). * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German". * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch". * @property {string} emoji - The emoji associated with the locale's region, if applicable. */ export declare function getLocaleProperties(locale: string, defaultLocale?: string, customMapping?: CustomMapping): LocaleProperties; /** * Retrieves multiple properties for a given region code, including: * - `code`: the original region code * - `name`: the localized display name * - `emoji`: the associated flag or symbol * * Behavior: * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`). * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values. * - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`, * falling back to `libraryDefaultLocale`. * - Falls back to the region code as `name` if display name resolution fails. * - Falls back to `defaultEmoji` if no emoji mapping is found in `emojis` or `customMapping`. * * @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`). * @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name. * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis. * @returns {{ code: string, name: string, emoji: string }} An object containing: * - `code`: the input region code * - `name`: the localized or custom region name * - `emoji`: the matching emoji flag or symbol * * @example * getRegionProperties('US', 'en'); * // => { code: 'US', name: 'United States', emoji: '🇺🇸' } * * @example * getRegionProperties('US', 'fr'); * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' } * * @example * getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } }); * // => { code: 'US', name: 'USA', emoji: '🗽' } */ export declare function getRegionProperties(region: string, defaultLocale?: string, customMapping?: CustomRegionMapping): { code: string; name: string; emoji: string; }; /** * Determines whether a translation is required based on the source and target locales. * * - If the target locale is not specified, the function returns `false`, as translation is not needed. * - If the source and target locale are the same, returns `false`, indicating that no translation is necessary. * - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`. * - Otherwise, it returns `true`, meaning that a translation is required. * * @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code). * @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code). * @param {string[]} [approvedLocale] - An optional array of approved target locales. * * @returns {boolean} - Returns `true` if translation is required, otherwise `false`. */ export declare function requiresTranslation(sourceLocale: string, targetLocale: string, approvedLocales?: string[], customMapping?: CustomMapping): boolean; /** * Determines the best matching locale from the provided approved locales list. * @param {string | string[]} locales - A single locale or an array of locales sorted in preference order. * @param {string[]} [approvedLocales=this.locales] - An array of approved locales, also sorted by preference. * @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found. */ export declare function determineLocale(locales: string | string[], approvedLocales?: string[] | undefined, customMapping?: CustomMapping | undefined): string | undefined; /** * Get the text direction for a given locale code using the Intl.Locale API. * * @param {string} locale - A BCP-47 locale code. * @returns {string} 'rtl' if the locale is right-to-left; otherwise 'ltr'. */ export declare function getLocaleDirection(locale: string): 'ltr' | 'rtl'; /** * Resolves the alias locale for a given locale. * @param {string} locale - The locale to resolve the alias locale for * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale * @returns {string} The alias locale */ export declare function resolveAliasLocale(locale: string, customMapping?: CustomMapping): string; /** * Checks if multiple BCP 47 locale codes represent the same dialect. * @param {string[]} locales - The BCP 47 locale codes to compare. * @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise. */ export declare function isSameDialect(...locales: (string | string[])[]): boolean; /** * Checks if multiple BCP 47 locale codes represent the same language. * @param {string[]} locales - The BCP 47 locale codes to compare. * @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise. */ export declare function isSameLanguage(...locales: (string | string[])[]): boolean; /** * Checks if a locale is a superset of another locale. * A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical. * * @param {string} superLocale - The locale to check if it is a superset of the other locale. * @param {string} subLocale - The locale to check if it is a subset of the other locale. * @returns {boolean} True if the first locale is a superset of the second locale, false otherwise. */ export declare function isSupersetLocale(superLocale: string, subLocale: string): boolean; export declare const API_VERSION = "2026-03-06.v1";