generaltranslation 9.4.2 → 9.5.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 +34 -0
- package/README.md +2 -1
- package/dist/{ApiError-BcjcnTAr.cjs → ApiError-BCjEo_CM.cjs} +1 -1
- package/dist/{ApiError-BcjcnTAr.cjs.map → ApiError-BCjEo_CM.cjs.map} +1 -1
- package/dist/{ApiError-CUKcz3YS.mjs → ApiError-DxWKM0Xt.mjs} +1 -1
- package/dist/{ApiError-CUKcz3YS.mjs.map → ApiError-DxWKM0Xt.mjs.map} +1 -1
- package/dist/adapter/createGtApi.d.ts +196 -27
- package/dist/adapter/createGtApi.js +561 -117
- package/dist/adapter/modelProvider.d.ts +4 -0
- package/dist/adapter/modelProvider.js +6 -0
- package/dist/derive-Cv5_y8Tf.mjs +656 -0
- package/dist/derive-Cv5_y8Tf.mjs.map +1 -0
- package/dist/{derive-DBCCXTmL.d.cts → derive-J2NQLqZm.d.cts} +1 -1
- package/dist/derive-t_E3ftJN.cjs +733 -0
- package/dist/derive-t_E3ftJN.cjs.map +1 -0
- package/dist/diagnostics-CqAHg_Vc.d.cts +34 -0
- package/dist/diagnostics-DKA2SkZB.mjs +45 -0
- package/dist/diagnostics-DKA2SkZB.mjs.map +1 -0
- package/dist/{unwrapApiResult-BzGfPw75.mjs → diagnostics-DKtiPUvo.cjs} +12 -31
- package/dist/diagnostics-DKtiPUvo.cjs.map +1 -0
- package/dist/diagnostics-DYtVjOm5.d.mts +34 -0
- package/dist/diagnostics.cjs +4 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.mts +2 -0
- package/dist/diagnostics.d.ts +1 -0
- package/dist/diagnostics.js +1 -0
- package/dist/diagnostics.mjs +2 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/file-B37WkCqM.cjs.map +1 -1
- package/dist/file-Dga6cyM8.mjs.map +1 -1
- package/dist/{id-X2zyx5Jk.mjs → id-B2wA7-S-.mjs} +19 -3
- package/dist/id-B2wA7-S-.mjs.map +1 -0
- package/dist/{id-pdr3R1xs.cjs → id-DJ_59q21.cjs} +25 -3
- package/dist/id-DJ_59q21.cjs.map +1 -0
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +1 -1
- package/dist/id.d.mts +1 -1
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +94 -753
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -33
- package/dist/index.d.mts +13 -32
- package/dist/index.d.ts +20 -16
- package/dist/index.js +110 -98
- package/dist/index.mjs +88 -746
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +16 -186
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +200 -62
- package/dist/internal.d.mts +199 -61
- package/dist/internal.d.ts +3 -1
- package/dist/internal.js +2 -1
- package/dist/internal.mjs +6 -178
- package/dist/internal.mjs.map +1 -1
- package/dist/logging/errors.d.ts +0 -1
- package/dist/logging/errors.js +0 -6
- package/dist/logging/logger.js +6 -4
- package/dist/openapi.json +2344 -845
- package/dist/runtime.cjs +580 -2
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +12 -6
- package/dist/runtime.d.mts +12 -6
- package/dist/runtime.d.ts +10 -4
- package/dist/runtime.js +10 -65
- package/dist/runtime.mjs +579 -1
- package/dist/runtime.mjs.map +1 -0
- package/dist/runtimeTranslate-CVw143pQ.mjs +506 -0
- package/dist/runtimeTranslate-CVw143pQ.mjs.map +1 -0
- package/dist/runtimeTranslate-DJioRjb6.cjs +601 -0
- package/dist/runtimeTranslate-DJioRjb6.cjs.map +1 -0
- package/dist/translate/awaitJobs.d.ts +2 -2
- package/dist/translate/awaitJobs.js +1 -156
- package/dist/translate/checkJobStatus.d.ts +2 -1
- package/dist/translate/checkJobStatus.js +1 -55
- package/dist/translate/createBranch.d.ts +2 -6
- package/dist/translate/createBranch.js +1 -53
- package/dist/translate/enqueueFiles.js +1 -95
- package/dist/translate/getProjectInfo.d.ts +2 -6
- package/dist/translate/getProjectInfo.js +1 -54
- package/dist/translate/processFileMoves.d.ts +3 -13
- package/dist/translate/processFileMoves.js +1 -90
- package/dist/translate/publishFiles.d.ts +3 -15
- package/dist/translate/publishFiles.js +1 -56
- package/dist/translate/queryBranchData.js +1 -53
- package/dist/translate/queryFileData.d.ts +3 -41
- package/dist/translate/queryFileData.js +1 -71
- package/dist/translate/runtimeTranslate.d.ts +6 -0
- package/dist/translate/runtimeTranslate.js +297 -0
- package/dist/translate/setupProject.d.ts +2 -6
- package/dist/translate/setupProject.js +1 -63
- package/dist/translate/submitUserEditDiffs.js +1 -68
- package/dist/translate/utils/fetchWithTimeout.js +19 -12
- package/dist/{types-bCr8pV1Z.d.cts → types-Si4UstLL.d.mts} +41 -165
- package/dist/types-dir/__tests__/runtimeTranslate.type-test.js +18 -0
- package/dist/types-dir/api/branch.d.ts +3 -9
- package/dist/types-dir/api/checkFileTranslations.d.ts +2 -22
- package/dist/types-dir/api/downloadFileBatch.d.ts +2 -7
- package/dist/types-dir/api/entry.d.ts +3 -8
- package/dist/types-dir/api/file.d.ts +2 -1
- package/dist/types-dir/api/json.d.ts +1 -4
- package/dist/types-dir/api/project.d.ts +2 -7
- package/dist/types-dir/api/uploadAssets.d.ts +3 -10
- package/dist/types-dir/api/uploadAssets.js +0 -4
- package/dist/types-dir/config.d.ts +1 -0
- package/dist/{types-Dp1drjxq.d.mts → types-yByDbKnV.d.cts} +41 -165
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +26 -7
- package/package.json +15 -2
- package/dist/derive-2CDqwrvS.cjs +0 -303
- package/dist/derive-2CDqwrvS.cjs.map +0 -1
- package/dist/derive-CTzR56T_.mjs +0 -233
- package/dist/derive-CTzR56T_.mjs.map +0 -1
- package/dist/id-X2zyx5Jk.mjs.map +0 -1
- package/dist/id-pdr3R1xs.cjs.map +0 -1
- package/dist/isVariable-8-Wy5FnX.mjs +0 -20
- package/dist/isVariable-8-Wy5FnX.mjs.map +0 -1
- package/dist/isVariable-I3nllgeI.cjs +0 -25
- package/dist/isVariable-I3nllgeI.cjs.map +0 -1
- package/dist/projects/getProjectData.js +0 -87
- package/dist/runtime-Bcp4F2ME.mjs +0 -974
- package/dist/runtime-Bcp4F2ME.mjs.map +0 -1
- package/dist/runtime-C25lwh9m.cjs +0 -1027
- package/dist/runtime-C25lwh9m.cjs.map +0 -1
- package/dist/translate/api.d.ts +0 -4
- package/dist/translate/api.js +0 -4
- package/dist/translate/createTag.d.ts +0 -19
- package/dist/translate/createTag.js +0 -67
- package/dist/translate/downloadFileBatch.d.ts +0 -1
- package/dist/translate/downloadFileBatch.js +0 -80
- package/dist/translate/getOrphanedFiles.d.ts +0 -8
- package/dist/translate/getOrphanedFiles.js +0 -97
- package/dist/translate/querySourceFile.d.ts +0 -1
- package/dist/translate/querySourceFile.js +0 -67
- package/dist/translate/translateMany.d.ts +0 -1
- package/dist/translate/translateMany.js +0 -124
- package/dist/translate/uploadFonts.d.ts +0 -1
- package/dist/translate/uploadFonts.js +0 -74
- package/dist/translate/uploadSourceFiles.d.ts +0 -1
- package/dist/translate/uploadSourceFiles.js +0 -90
- package/dist/translate/uploadTranslations.d.ts +0 -1
- package/dist/translate/uploadTranslations.js +0 -106
- package/dist/translate/utils/apiRequest.d.ts +0 -1
- package/dist/translate/utils/apiRequest.js +0 -167
- package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
- package/dist/translate/utils/generateRequestHeaders.js +0 -21
- package/dist/translate/utils/handleFetchError.d.ts +0 -1
- package/dist/translate/utils/handleFetchError.js +0 -12
- package/dist/unwrapApiResult-BzGfPw75.mjs.map +0 -1
- package/dist/unwrapApiResult-Dv6Mfw_K.cjs +0 -134
- package/dist/unwrapApiResult-Dv6Mfw_K.cjs.map +0 -1
- /package/dist/{projects/getProjectData.d.ts → types-dir/__tests__/runtimeTranslate.type-test.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.cjs","names":["invalidLocaleError","invalidLocalesError","LocaleConfig","translateWithConfig","translateManyWithConfig","noTargetLocaleProvidedError","noSourceLocaleProvidedError"],"sources":["../src/runtime.ts"],"sourcesContent":["// `generaltranslation` language toolkit\n// © 2026, General Translation, Inc.\n\n// ----- IMPORTS ----- //\n\nimport {\n LocaleConfig,\n getRegionProperties as _getRegionProperties,\n isValidLocale as _isValidLocale,\n requiresTranslation as _requiresTranslation,\n resolveAliasLocale as _resolveAliasLocale,\n resolveCanonicalLocale as _resolveCanonicalLocale,\n standardizeLocale as _standardizeLocale,\n} from '@generaltranslation/format';\nimport type {\n CustomMapping,\n CustomRegionMapping,\n CutoffFormatOptions,\n FormatVariables,\n LocaleProperties,\n StringFormat,\n} from '@generaltranslation/format/types';\nimport type { UserTokenProvider } from '@generaltranslation/api';\nimport {\n TranslateManyResult,\n TranslationError,\n TranslationRequestConfig,\n TranslationResult,\n TranslateManyEntry,\n} from './types';\nimport {\n noSourceLocaleProvidedError,\n noTargetLocaleProvidedError,\n invalidLocaleError,\n invalidLocalesError,\n} from './logging/errors';\nimport {\n translate as translateWithConfig,\n translateMany as translateManyWithConfig,\n} from './translate/runtimeTranslate';\nimport { TranslateOptions } from './types-dir/api/entry';\n\n// ============================================================ //\n// Runtime Class //\n// ============================================================ //\n/**\n * Type representing the constructor parameters for the GT and GTRuntime classes.\n * @typedef {Object} GTConstructorParams\n * @property {string} [apiKey] - The API key for accessing the translation service\n * @property {string} [devApiKey] - Deprecated alias for apiKey\n * @property {string} [sourceLocale] - The default source locale for translations\n * @property {string} [targetLocale] - The default target locale for translations\n * @property {string[]} [locales] - Array of supported locales\n * @property {string} [projectId] - The project ID for the translation service\n * @property {string} [baseUrl] - The base URL for the translation service\n * @property {CustomMapping} [customMapping] - Custom mapping of locale codes to their names\n */\nexport type GTConstructorParams = {\n apiKey?: string;\n /** @deprecated Pass the key as `apiKey`; there is one kind of API key. */\n devApiKey?: string;\n sourceLocale?: string;\n targetLocale?: string;\n locales?: string[];\n projectId?: string;\n baseUrl?: string;\n customMapping?: CustomMapping;\n userTokenProvider?: UserTokenProvider;\n};\n\n/**\n * GTRuntime is the runtime core of the GT driver: locale management,\n * formatting, and runtime translation requests.\n *\n * Browser-facing SDK code constructs this class (via `generaltranslation/runtime`)\n * so production bundles do not ship the project/file management API client\n * that lives on the GT class exported from the main entry.\n *\n * @example\n * const gt = new GTRuntime({\n * sourceLocale: 'en-US',\n * targetLocale: 'es-ES',\n * locales: ['en-US', 'es-ES', 'fr-FR']\n * });\n */\nexport class GTRuntime {\n /** Base URL for the translation service API */\n baseUrl?: string;\n\n /** Project ID for the translation service */\n projectId?: string;\n\n /** API key for accessing the translation service */\n apiKey?: string;\n\n /** @deprecated Pass the key as `apiKey`; there is one kind of API key. */\n devApiKey?: string;\n\n /** User-token provider used when no API key is configured */\n userTokenProvider?: UserTokenProvider;\n\n /** Source locale for translations */\n sourceLocale?: string;\n\n /** Target locale for translations */\n targetLocale?: string;\n\n /** Array of supported locales */\n locales?: string[];\n\n /** Custom mapping for locale codes to their names */\n customMapping?: CustomMapping;\n\n /** Lazily derived reverse custom mapping for alias locales */\n reverseCustomMapping?: Record<string, string>;\n\n /** Lazily derived custom mapping for regions */\n customRegionMapping?: CustomRegionMapping;\n\n /** Runtime-safe locale and formatting helpers (backing field) */\n private _localeConfig!: LocaleConfig;\n\n /** Runtime-safe locale and formatting helpers */\n get localeConfig() {\n return this._localeConfig;\n }\n\n /**\n * Constructs an instance of the GTRuntime class.\n *\n * @param {GTConstructorParams} [params] - The parameters for initializing the GTRuntime instance\n * @throws {Error} If an invalid locale is provided\n * @throws {Error} If any of the provided locales are invalid\n *\n * @example\n * const gt = new GTRuntime({\n * apiKey: 'your-api-key',\n * sourceLocale: 'en-US',\n * targetLocale: 'es-ES',\n * locales: ['en-US', 'es-ES', 'fr-FR']\n * });\n */\n constructor(params: GTConstructorParams = {}) {\n // Read environment\n if (typeof process !== 'undefined') {\n this.apiKey ||= process.env?.GT_API_KEY;\n // Deprecated with devApiKey; frameworks resolve the hot-reload key themselves.\n this.devApiKey ||= process.env?.GT_DEV_API_KEY;\n this.projectId ||= process.env?.GT_PROJECT_ID;\n }\n // Set up config\n this.setConfig(params);\n }\n\n setConfig({\n apiKey,\n devApiKey,\n sourceLocale,\n targetLocale,\n locales,\n projectId,\n customMapping,\n baseUrl,\n userTokenProvider,\n }: GTConstructorParams) {\n const effectiveCustomMapping = customMapping ?? this.customMapping;\n\n // ----- Environment properties ----- //\n if (apiKey) this.apiKey = apiKey;\n if (devApiKey) this.devApiKey = devApiKey;\n if (projectId) this.projectId = projectId;\n if (userTokenProvider) this.userTokenProvider = userTokenProvider;\n\n // ----- Validate configured locale identities ----- //\n\n // source locale\n if (sourceLocale) {\n this.sourceLocale = sourceLocale;\n if (!_isValidLocale(this.sourceLocale, effectiveCustomMapping))\n throw new Error(invalidLocaleError(this.sourceLocale));\n }\n\n // target locale\n if (targetLocale) {\n this.targetLocale = targetLocale;\n if (!_isValidLocale(this.targetLocale, effectiveCustomMapping))\n throw new Error(invalidLocaleError(this.targetLocale));\n }\n\n // locales\n if (locales) {\n const result: string[] = [];\n const invalidLocales: string[] = [];\n locales.forEach((locale) => {\n if (_isValidLocale(locale, effectiveCustomMapping)) {\n result.push(locale);\n } else {\n invalidLocales.push(locale);\n }\n });\n if (invalidLocales.length > 0) {\n throw new Error(invalidLocalesError(invalidLocales));\n }\n this.locales = result;\n }\n\n // ----- Other properties ----- //\n if (baseUrl) this.baseUrl = baseUrl;\n if (customMapping) {\n this.customMapping = customMapping;\n this.reverseCustomMapping = Object.fromEntries(\n Object.entries(customMapping)\n .filter(\n ([, value]) => value && typeof value === 'object' && 'code' in value\n )\n .map(([key, value]) => [(value as { code: string }).code, key])\n );\n }\n this._localeConfig = new LocaleConfig({\n defaultLocale: this.sourceLocale,\n locales: this.locales ?? [],\n customMapping: this.customMapping,\n });\n }\n\n // -------------- Private Methods -------------- //\n\n /** Convert app identity only where a GT service expects a language code. */\n protected resolveServiceLocale(locale: string): string {\n return this.standardizeLocale(this.resolveCanonicalLocale(locale));\n }\n\n /**\n * Recover configured spelling without negotiating an unrelated dialect.\n * When several identities use the same service code and there is no request\n * context to disambiguate them, the first configured identity wins.\n */\n protected resolveServiceResponseLocale(locale: string): string {\n const canonical = this.standardizeLocale(locale);\n const configured = [\n ...(this.locales ?? []),\n this.sourceLocale,\n this.targetLocale,\n ...Object.keys(this.customMapping ?? {}),\n ];\n return (\n configured.find(\n (candidate) =>\n candidate && this.resolveServiceLocale(candidate) === canonical\n ) ?? locale\n );\n }\n\n protected _getTranslationConfig(): TranslationRequestConfig {\n return {\n baseUrl: this.baseUrl,\n apiKey: this.apiKey || this.devApiKey,\n projectId: this.projectId || '',\n userTokenProvider: this.userTokenProvider,\n };\n }\n\n /**\n * Translates a single source string to the target locale.\n * Routes through {@link translateMany} under the hood.\n *\n * @param {string} source - The source string to translate.\n * @param {object} options - Translation options including targetLocale and optional entry metadata.\n * @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.\n * @returns {Promise<TranslationResult | TranslationError>} The translated content.\n *\n * @example\n * const result = await gt.translate('Hello, world!', { targetLocale: 'es' });\n *\n * @example\n * const result = await gt.translate('Hello, world!', {\n * targetLocale: 'es',\n * dataFormat: 'ICU',\n * context: 'A formal greeting',\n * });\n */\n async translate(\n source: TranslateManyEntry,\n options: string | TranslateOptions,\n timeout?: number\n ): Promise<TranslationResult | TranslationError> {\n return translateWithConfig(\n source,\n options,\n {\n ...this._getTranslationConfig(),\n customMapping: this.customMapping,\n timeoutMs: timeout || undefined,\n },\n this\n );\n }\n\n /**\n * Translates multiple source strings to the target locale.\n * Each entry can be a plain string or an object with source and metadata fields.\n *\n * @param {TranslateManyEntry[] | Record<string, TranslateManyEntry>} sources - The source entries to translate. Can be an array or a record keyed by hash.\n * @param {object} options - Translation options including targetLocale.\n * @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.\n * @returns {Promise<TranslateManyResult | Record<string, TranslationResult>>} The translated contents. An array if sources was an array, a record if sources was a record.\n *\n * @example\n * const result = await gt.translateMany(\n * ['Hello, world!', 'Goodbye, world!'],\n * { targetLocale: 'es' }\n * );\n *\n * @example\n * const result = await gt.translateMany(\n * [{ source: 'Hello, world!', dataFormat: 'ICU' }],\n * { targetLocale: 'es' }\n * );\n *\n * @example\n * const result = await gt.translateMany(\n * { 'my-hash': 'Hello, world!' },\n * { targetLocale: 'es' }\n * );\n */\n async translateMany(\n sources: TranslateManyEntry[],\n options: string | TranslateOptions,\n timeout?: number\n ): Promise<TranslateManyResult>;\n async translateMany(\n sources: Record<string, TranslateManyEntry>,\n options: string | TranslateOptions,\n timeout?: number\n ): Promise<Record<string, TranslationResult>>;\n async translateMany(\n sources: TranslateManyEntry[] | Record<string, TranslateManyEntry>,\n options: string | TranslateOptions,\n timeout?: number\n ): Promise<TranslateManyResult | Record<string, TranslationResult>> {\n return translateManyWithConfig(\n sources,\n options,\n {\n ...this._getTranslationConfig(),\n customMapping: this.customMapping,\n timeoutMs: timeout || undefined,\n },\n this\n );\n }\n\n // -------------- Formatting -------------- //\n\n /**\n * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.\n *\n * This method uses the GT instance's rendering locales by default for locale-specific terminator selection,\n * but can be overridden with custom locales in the options.\n *\n * @param {string} value - The string value to format with cutoff behavior.\n * @param {Object} [options] - Configuration options for cutoff formatting.\n * @param {string | string[]} [options.locales] - The locales to use for terminator selection. Defaults to instance's rendering locales.\n * @param {number} [options.maxChars] - The maximum number of characters to display.\n * - Undefined values are treated as no cutoff.\n * - Negative values follow .slice() behavior and terminator will be added before the value.\n * - 0 will result in an empty string.\n * - If cutoff results in an empty string, no terminator is added.\n * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.\n * @param {string} [options.terminator] - Optional override the terminator to use.\n * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.\n * - If no terminator is provided, then separator is ignored.\n * @returns {string} The formatted string with terminator applied if cutoff occurs.\n *\n * @example\n * const gt = new GTRuntime({ targetLocale: 'en-US' });\n * gt.formatCutoff('Hello, world!', { maxChars: 8 });\n * // Returns: 'Hello, w...'\n *\n * @example\n * gt.formatCutoff('Hello, world!', { maxChars: -3 });\n * // Returns: '...ld!'\n */\n formatCutoff(\n value: string,\n options?: {\n locales?: string | string[];\n } & CutoffFormatOptions\n ): string {\n return this.localeConfig.formatCutoff(value, this.targetLocale, options);\n }\n\n /**\n * Formats a message according to the specified locales and options.\n *\n * @param {string} message - The message to format.\n * @param {string | string[]} [locales=libraryDefaultLocale] - The locales to use for formatting.\n * @param {FormatVariables} [variables={}] - The variables to use for formatting.\n * @param {StringFormat} [dataFormat='ICU'] - The format of the message.\n * @returns {string} The formatted message.\n *\n * @example\n * gt.formatMessage('Hello {name}', { name: 'John' });\n * // Returns: \"Hello John\"\n *\n * gt.formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });\n * // Returns: \"Bonjour John\"\n */\n formatMessage(\n message: string,\n options?: {\n locales?: string | string[];\n variables?: FormatVariables;\n dataFormat?: StringFormat;\n }\n ): string {\n return this.localeConfig.formatMessage(message, this.targetLocale, options);\n }\n /**\n * Formats a number according to the specified locales and options.\n *\n * @param {number} number - The number to format.\n * @param {Object} [options] - Additional options for number formatting.\n * @param {string | string[]} [options.locales] - The locales to use for formatting.\n * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options.\n * @returns {string} The formatted number.\n *\n * @example\n * gt.formatNum(1234.56, { style: 'currency', currency: 'USD' });\n * // Returns: \"$1,234.56\"\n */\n formatNum(\n number: number,\n options?: {\n locales?: string | string[];\n } & Intl.NumberFormatOptions\n ): string {\n return this.localeConfig.formatNum(number, this.targetLocale, options);\n }\n\n /**\n * Formats a date according to the specified locales and options.\n *\n * @param {Date} date - The date to format.\n * @param {Object} [options] - Additional options for date formatting.\n * @param {string | string[]} [options.locales] - The locales to use for formatting.\n * @param {Intl.DateTimeFormatOptions} [options] - Additional Intl.DateTimeFormat options.\n * @returns {string} The formatted date.\n *\n * @example\n * gt.formatDateTime(new Date(), { dateStyle: 'full', timeStyle: 'long' });\n * // Returns: \"Thursday, March 14, 2024 at 2:30:45 PM GMT-7\"\n */\n formatDateTime(\n date: Date,\n options?: {\n locales?: string | string[];\n } & Intl.DateTimeFormatOptions\n ): string {\n return this.localeConfig.formatDateTime(date, this.targetLocale, options);\n }\n\n /**\n * Formats a currency value according to the specified locales and options.\n *\n * @param {number} value - The currency value to format.\n * @param {string} currency - The currency code (e.g., 'USD', 'EUR')\n * @param {Object} [options] - Additional options for currency formatting.\n * @param {string | string[]} [options.locales] - The locales to use for formatting.\n * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options.\n * @returns {string} The formatted currency value.\n *\n * @example\n * gt.formatCurrency(1234.56, 'USD', { style: 'currency' });\n * // Returns: \"$1,234.56\"\n */\n formatCurrency(\n value: number,\n currency: string,\n options?: {\n locales?: string | string[];\n } & Intl.NumberFormatOptions\n ): string {\n return this.localeConfig.formatCurrency(\n value,\n currency,\n this.targetLocale,\n options\n );\n }\n\n /**\n * Formats a list of items according to the specified locales and options.\n *\n * @param {Array<string | number>} array - The list of items to format.\n * @param {Object} [options] - Additional options for list formatting.\n * @param {string | string[]} [options.locales] - The locales to use for formatting.\n * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.\n * @returns {string} The formatted list.\n *\n * @example\n * gt.formatList(['apple', 'banana', 'orange'], { type: 'conjunction' });\n * // Returns: \"apple, banana, and orange\"\n */\n formatList(\n array: Array<string | number>,\n options?: {\n locales?: string | string[];\n } & Intl.ListFormatOptions\n ) {\n return this.localeConfig.formatList(array, this.targetLocale, options);\n }\n\n /**\n * Formats a list of items according to the specified locales and options.\n * @param {Array<T>} array - The list of items to format.\n * @param {Object} [options] - Additional options for list formatting.\n * @param {string | string[]} [options.locales] - The locales to use for formatting.\n * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.\n * @returns {Array<T | string>} The formatted list parts.\n *\n * @example\n * gt.formatListToParts(['apple', 42, { foo: 'bar' }], { type: 'conjunction', style: 'short', locales: ['en'] });\n * // Returns: ['apple', ', ', 42, ' and ', '{ foo: \"bar\" }']\n */\n formatListToParts<T>(\n array: Array<T>,\n options?: {\n locales?: string | string[];\n } & Intl.ListFormatOptions\n ): Array<T | string> {\n return this.localeConfig.formatListToParts<T>(\n array,\n this.targetLocale,\n options\n );\n }\n\n /**\n * Formats a relative time value according to the specified locales and options.\n *\n * @param {number} value - The relative time value to format.\n * @param {Intl.RelativeTimeFormatUnit} unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year')\n * @param {Object} options - Additional options for relative time formatting.\n * @param {string | string[]} [options.locales] - The locales to use for formatting.\n * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.\n * @returns {string} The formatted relative time string.\n *\n * @example\n * gt.formatRelativeTime(-1, 'day', { locales: ['en-US'], numeric: 'auto' });\n * // Returns: \"yesterday\"\n */\n formatRelativeTime(\n value: number,\n unit: Intl.RelativeTimeFormatUnit,\n options?: {\n locales?: string | string[];\n } & Omit<Intl.RelativeTimeFormatOptions, 'locales'>\n ): string {\n return this.localeConfig.formatRelativeTime(\n value,\n unit,\n this.targetLocale,\n options\n );\n }\n\n /**\n * Formats a relative time string from a Date, automatically selecting the best unit.\n *\n * @param {Date} date - The date to format relative to now.\n * @param {Object} [options] - Additional options for relative time formatting.\n * @param {string | string[]} [options.locales] - The locales to use for formatting.\n * @returns {string} The formatted relative time string (e.g., \"2 hours ago\", \"in 3 days\")\n *\n * @example\n * gt.formatRelativeTimeFromDate(new Date(Date.now() - 3600000));\n * // Returns: \"1 hour ago\"\n */\n formatRelativeTimeFromDate(\n date: Date,\n options?: {\n locales?: string | string[];\n baseDate?: Date;\n } & Omit<Intl.RelativeTimeFormatOptions, 'locales'>\n ): string {\n return this.localeConfig.formatRelativeTimeFromDate(\n date,\n this.targetLocale,\n options\n );\n }\n\n // -------------- Locale Properties -------------- //\n\n /**\n * Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found.\n *\n * @param {string} [locale=this.targetLocale] - A BCP-47 locale code.\n * @returns {string} The display name corresponding to the code.\n * @throws {Error} If no target locale is provided.\n *\n * @example\n * gt.getLocaleName('es-ES');\n * // Returns: \"Spanish (Spain)\"\n */\n getLocaleName(locale = this.targetLocale): string {\n if (!locale) throw new Error(noTargetLocaleProvidedError('getLocaleName'));\n return this.localeConfig.getLocaleName(locale);\n }\n\n /**\n * Retrieves an emoji based on a given locale code.\n * Uses the locale's region (if present) to select an emoji or falls back on default emojis.\n *\n * @param {string} [locale=this.targetLocale] - A BCP-47 locale code (e.g., 'en-US', 'fr-CA')\n * @returns {string} The emoji representing the locale or its region.\n * @throws {Error} If no target locale is provided.\n *\n * @example\n * gt.getLocaleEmoji('es-ES');\n * // Returns: \"🇪🇸\"\n */\n getLocaleEmoji(locale = this.targetLocale): string {\n if (!locale) throw new Error(noTargetLocaleProvidedError('getLocaleEmoji'));\n return this.localeConfig.getLocaleEmoji(locale);\n }\n\n /**\n * Generates linguistic details for a given locale code.\n *\n * This function returns information about the locale,\n * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).\n * The function provides these names in both your default language and native forms, and an associated emoji.\n *\n * @param {string} [locale=this.targetLocale] - The locale code to get properties for (e.g., \"de-AT\").\n * @returns {LocaleProperties} - An object containing detailed information about the locale.\n *\n * @property {string} code - The full locale code, e.g., \"de-AT\".\n * @property {string} name - Language name in the default display language, e.g., \"Austrian German\".\n * @property {string} nativeName - Language name in the locale's native language, e.g., \"Österreichisches Deutsch\".\n * @property {string} languageCode - The base language code, e.g., \"de\".\n * @property {string} languageName - The language name in the default display language, e.g., \"German\".\n * @property {string} nativeLanguageName - The language name in the native language, e.g., \"Deutsch\".\n * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., \"German (AT)\".\n * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., \"Deutsch (AT)\".\n * @property {string} regionCode - The region code from maximization, e.g., \"AT\".\n * @property {string} regionName - The region name in the default display language, e.g., \"Austria\".\n * @property {string} nativeRegionName - The region name in the native language, e.g., \"Österreich\".\n * @property {string} scriptCode - The script code from maximization, e.g., \"Latn\".\n * @property {string} scriptName - The script name in the default display language, e.g., \"Latin\".\n * @property {string} nativeScriptName - The script name in the native language, e.g., \"Lateinisch\".\n * @property {string} maximizedCode - The maximized locale code, e.g., \"de-Latn-AT\".\n * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., \"Austrian German (Latin)\".\n * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., \"Österreichisches Deutsch (Lateinisch)\".\n * @property {string} minimizedCode - Minimized locale code, e.g., \"de-AT\" (or \"de\" for \"de-DE\").\n * @property {string} minimizedName - Minimized language name in the default language, e.g., \"Austrian German\".\n * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., \"Österreichisches Deutsch\".\n * @property {string} emoji - The emoji associated with the locale's region, if applicable.\n */\n getLocaleProperties(locale = this.targetLocale): LocaleProperties {\n if (!locale)\n throw new Error(noTargetLocaleProvidedError('getLocaleProperties'));\n return this.localeConfig.getLocaleProperties(locale);\n }\n\n /**\n * Retrieves multiple properties for a given region code, including:\n * - `code`: the original region code\n * - `name`: the localized display name\n * - `emoji`: the associated flag or symbol\n *\n * Behavior:\n * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `\"US\"`, `\"FR\"`, `\"419\"`).\n * - Uses the instance's `targetLocale` to localize the region name for the user.\n * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.\n * - Otherwise, uses `Intl.DisplayNames` to get the localized region name, falling back to `libraryDefaultLocale`.\n * - Falls back to the region code as `name` if display name resolution fails.\n * - Falls back to a default emoji if no emoji mapping is found in built-in data or `customMapping`.\n *\n * @param {string} [region=this.getLocaleProperties().regionCode] - The region code to look up (e.g., `\"US\"`, `\"GB\"`, `\"DE\"`).\n * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.\n * @returns {{ code: string, name: string, emoji: string }} An object containing:\n * - `code`: the input region code\n * - `name`: the localized or custom region name\n * - `emoji`: the matching emoji flag or symbol\n *\n * @throws {Error} If no target locale is available to determine region properties.\n *\n * @example\n * const gt = new GTRuntime({ targetLocale: 'en-US' });\n * gt.getRegionProperties('US');\n * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }\n *\n * @example\n * const gt = new GTRuntime({ targetLocale: 'fr-FR' });\n * gt.getRegionProperties('US');\n * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }\n *\n * @example\n * gt.getRegionProperties('US', { US: { name: 'USA', emoji: '🗽' } });\n * // => { code: 'US', name: 'USA', emoji: '🗽' }\n */\n getRegionProperties(\n region = this.getLocaleProperties().regionCode,\n customMapping?: CustomRegionMapping\n ): { code: string; name: string; emoji: string } {\n if (!customMapping) {\n if (this.customMapping && !this.customRegionMapping) {\n // Lazy derive custom region mapping from customMapping\n const customRegionMapping: CustomRegionMapping = {};\n for (const [locale, lp] of Object.entries(this.customMapping)) {\n if (\n lp &&\n typeof lp === 'object' &&\n lp.regionCode &&\n !customRegionMapping[lp.regionCode]\n ) {\n const { regionName: name, emoji } = lp;\n customRegionMapping[lp.regionCode] = {\n locale,\n ...(name && { name }),\n ...(emoji && { emoji }),\n };\n }\n }\n this.customRegionMapping = customRegionMapping;\n }\n customMapping = this.customRegionMapping;\n }\n return _getRegionProperties(\n region,\n this.targetLocale, // this.targetLocale because we want it in the user's language\n customMapping\n );\n }\n\n /**\n * Determines whether a translation is required based on the source and target locales.\n *\n * @param {string} [sourceLocale=this.sourceLocale] - The locale code for the original content.\n * @param {string} [targetLocale=this.targetLocale] - The locale code to translate into.\n * @param {string[]} [approvedLocales=this.locales] - Optional array of approved target locales.\n * @returns {boolean} True if translation is required, false otherwise\n * @throws {Error} If no source locale is provided.\n * @throws {Error} If no target locale is provided.\n *\n * @example\n * gt.requiresTranslation('en-US', 'es-ES');\n * // Returns: true\n */\n requiresTranslation(\n sourceLocale = this.sourceLocale,\n targetLocale = this.targetLocale,\n approvedLocales: string[] | undefined = this.locales,\n customMapping: CustomMapping | undefined = this.customMapping\n ): boolean {\n if (!sourceLocale)\n throw new Error(noSourceLocaleProvidedError('requiresTranslation'));\n if (!targetLocale)\n throw new Error(noTargetLocaleProvidedError('requiresTranslation'));\n if (customMapping === this.customMapping) {\n return this.localeConfig.requiresTranslation(\n targetLocale,\n sourceLocale,\n approvedLocales\n );\n }\n return _requiresTranslation(\n sourceLocale,\n targetLocale,\n approvedLocales,\n customMapping\n );\n }\n\n /**\n * Determines the best matching locale from the provided approved locales list.\n *\n * @param {string | string[]} locales - A single locale or array of locales in preference order.\n * @param {string[]} [approvedLocales=this.locales] - Array of approved locales in preference order.\n * @returns {string | undefined} The best matching locale, or undefined if no match is found.\n *\n * @example\n * gt.determineLocale(['fr-CA', 'fr-FR'], ['en-US', 'fr-FR', 'es-ES']);\n * // Returns: \"fr-FR\"\n */\n determineLocale(\n locales: string | string[],\n approvedLocales: string[] | undefined = this.locales || [],\n customMapping: CustomMapping | undefined = this.customMapping\n ): string | undefined {\n if (customMapping === this.customMapping) {\n return this.localeConfig.determineLocale(locales, approvedLocales ?? []);\n }\n return new LocaleConfig({ customMapping }).determineLocale(\n locales,\n approvedLocales ?? []\n );\n }\n\n /**\n * Gets the text direction for a given locale code.\n *\n * @param {string} [locale=this.targetLocale] - A BCP-47 locale code.\n * @returns {'ltr' | 'rtl'} 'rtl' if the locale is right-to-left; otherwise 'ltr'.\n * @throws {Error} If no target locale is provided.\n *\n * @example\n * gt.getLocaleDirection('ar-SA');\n * // Returns: \"rtl\"\n */\n getLocaleDirection(locale = this.targetLocale): 'ltr' | 'rtl' {\n if (!locale)\n throw new Error(noTargetLocaleProvidedError('getLocaleDirection'));\n return this.localeConfig.getLocaleDirection(locale);\n }\n\n /**\n * Checks if a given BCP 47 locale code is valid.\n *\n * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to validate.\n * @param {CustomMapping} [customMapping=this.customMapping] - The custom mapping to use for validation.\n * @returns {boolean} True if the locale code is valid, false otherwise\n * @throws {Error} If no target locale is provided.\n *\n * @example\n * gt.isValidLocale('en-US');\n * // Returns: true\n */\n isValidLocale(\n locale = this.targetLocale,\n customMapping: CustomMapping | undefined = this.customMapping\n ): boolean {\n if (!locale) throw new Error(noTargetLocaleProvidedError('isValidLocale'));\n if (customMapping === this.customMapping) {\n return this.localeConfig.isValidLocale(locale);\n }\n return _isValidLocale(locale, customMapping);\n }\n\n /**\n * Resolves the canonical locale for a given locale.\n * @param locale - The locale to resolve the canonical locale for\n * @param customMapping - The custom mapping to use for resolving the canonical locale\n * @returns The canonical locale, or the input locale when no canonical mapping exists.\n */\n resolveCanonicalLocale(\n locale: string | undefined = this.targetLocale,\n customMapping: CustomMapping | undefined = this.customMapping\n ): string {\n if (!locale)\n throw new Error(noTargetLocaleProvidedError('resolveCanonicalLocale'));\n if (customMapping === this.customMapping) {\n return this.localeConfig.resolveCanonicalLocale(locale);\n }\n return _resolveCanonicalLocale(locale, customMapping);\n }\n\n /**\n * Resolves the alias locale for a given locale.\n * @param locale - The locale to resolve the alias locale for\n * @param customMapping - The custom mapping to use for resolving the alias locale\n * @returns The configured alias for a canonical locale, or the input locale when already an alias or no alias mapping exists.\n */\n resolveAliasLocale(\n locale: string,\n customMapping: CustomMapping | undefined = this.customMapping\n ): string {\n if (!locale)\n throw new Error(noTargetLocaleProvidedError('resolveAliasLocale'));\n if (customMapping === this.customMapping) {\n return this.localeConfig.resolveAliasLocale(locale);\n }\n return _resolveAliasLocale(locale, customMapping);\n }\n\n /**\n * Standardizes a BCP 47 locale code to ensure correct formatting.\n *\n * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to standardize.\n * @returns {string} The standardized locale code, or the input string if it cannot be standardized.\n * @throws {Error} If no target locale is provided.\n *\n * @example\n * gt.standardizeLocale('en_us');\n * // Returns: \"en-US\"\n */\n standardizeLocale(locale = this.targetLocale): string {\n if (!locale)\n throw new Error(noTargetLocaleProvidedError('standardizeLocale'));\n return this.localeConfig.standardizeLocale(locale);\n }\n\n /**\n * Checks if multiple BCP 47 locale codes represent the same dialect.\n *\n * @param {...(string | string[])} locales - The BCP 47 locale codes to compare.\n * @returns {boolean} True if all codes represent the same dialect, false otherwise\n *\n * @example\n * gt.isSameDialect('en-US', 'en-GB');\n * // Returns: false\n *\n * gt.isSameDialect('en', 'en-US');\n * // Returns: true\n */\n isSameDialect(...locales: (string | string[])[]): boolean {\n return this.localeConfig.isSameDialect(...locales);\n }\n\n /**\n * Checks if multiple BCP 47 locale codes represent the same language.\n *\n * @param {...(string | string[])} locales - The BCP 47 locale codes to compare.\n * @returns {boolean} True if all codes represent the same language, false otherwise\n *\n * @example\n * gt.isSameLanguage('en-US', 'en-GB');\n * // Returns: true\n */\n isSameLanguage(...locales: (string | string[])[]): boolean {\n return this.localeConfig.isSameLanguage(...locales);\n }\n\n /**\n * Checks if a locale is a superset of another locale.\n *\n * @param {string} superLocale - The locale to check if it is a superset\n * @param {string} subLocale - The locale to check if it is a subset\n * @returns {boolean} True if superLocale is a superset of subLocale, false otherwise\n *\n * @example\n * gt.isSupersetLocale('en', 'en-US');\n * // Returns: true\n *\n * gt.isSupersetLocale('en-US', 'en');\n * // Returns: false\n */\n isSupersetLocale(superLocale: string, subLocale: string): boolean {\n return this.localeConfig.isSupersetLocale(superLocale, subLocale);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqFA,IAAa,YAAb,MAAuB;;CAsCrB,IAAI,eAAe;AACjB,SAAO,KAAK;;;;;;;;;;;;;;;;;CAkBd,YAAY,SAA8B,EAAE,EAAE;AAE5C,MAAI,OAAO,YAAY,aAAa;AAClC,QAAK,WAAW,QAAQ,KAAK;AAE7B,QAAK,cAAc,QAAQ,KAAK;AAChC,QAAK,cAAc,QAAQ,KAAK;;AAGlC,OAAK,UAAU,OAAO;;CAGxB,UAAU,EACR,QACA,WACA,c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,KAAK,aAAa,cAAc,OAAO;AAEhD,UAAA,GAAA,2BAAA,eAAsB,QAAQ,cAAc;;;;;;;;CAS9C,uBACE,SAA6B,KAAK,cAClC,gBAA2C,KAAK,eACxC;AACR,MAAI,CAAC,OACH,OAAM,IAAI,MAAMA,yBAAAA,4BAA4B,yBAAyB,CAAC;AACxE,MAAI,kBAAkB,KAAK,cACzB,QAAO,KAAK,aAAa,uBAAuB,OAAO;AAEzD,UAAA,GAAA,2BAAA,wBAA+B,QAAQ,cAAc;;;;;;;;CASvD,mBACE,QACA,gBAA2C,KAAK,eACxC;AACR,MAAI,CAAC,OACH,OAAM,IAAI,MAAMA,yBAAAA,4BAA4B,qBAAqB,CAAC;AACpE,MAAI,kBAAkB,KAAK,cACzB,QAAO,KAAK,aAAa,mBAAmB,OAAO;AAErD,UAAA,GAAA,2BAAA,oBAA2B,QAAQ,cAAc;;;;;;;;;;;;;CAcnD,kBAAkB,SAAS,KAAK,cAAsB;AACpD,MAAI,CAAC,OACH,OAAM,IAAI,MAAMA,yBAAAA,4BAA4B,oBAAoB,CAAC;AACnE,SAAO,KAAK,aAAa,kBAAkB,OAAO;;;;;;;;;;;;;;;CAgBpD,cAAc,GAAG,SAAyC;AACxD,SAAO,KAAK,aAAa,cAAc,GAAG,QAAQ;;;;;;;;;;;;CAapD,eAAe,GAAG,SAAyC;AACzD,SAAO,KAAK,aAAa,eAAe,GAAG,QAAQ;;;;;;;;;;;;;;;;CAiBrD,iBAAiB,aAAqB,WAA4B;AAChE,SAAO,KAAK,aAAa,iBAAiB,aAAa,UAAU"}
|
package/dist/runtime.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as TranslationRequestConfig, Ft as TranslateManyEntry, It as TranslateOptions, X as TranslationError, Y as TranslateManyResult, Z as TranslationResult } from "./types-yByDbKnV.cjs";
|
|
2
|
+
import { UserTokenProvider } from "@generaltranslation/api";
|
|
2
3
|
import { CustomMapping, CustomRegionMapping, CutoffFormatOptions, FormatVariables, LocaleProperties, StringFormat } from "@generaltranslation/format/types";
|
|
3
4
|
import { LocaleConfig } from "@generaltranslation/format";
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ import { LocaleConfig } from "@generaltranslation/format";
|
|
|
7
8
|
* Type representing the constructor parameters for the GT and GTRuntime classes.
|
|
8
9
|
* @typedef {Object} GTConstructorParams
|
|
9
10
|
* @property {string} [apiKey] - The API key for accessing the translation service
|
|
10
|
-
* @property {string} [devApiKey] -
|
|
11
|
+
* @property {string} [devApiKey] - Deprecated alias for apiKey
|
|
11
12
|
* @property {string} [sourceLocale] - The default source locale for translations
|
|
12
13
|
* @property {string} [targetLocale] - The default target locale for translations
|
|
13
14
|
* @property {string[]} [locales] - Array of supported locales
|
|
@@ -16,7 +17,7 @@ import { LocaleConfig } from "@generaltranslation/format";
|
|
|
16
17
|
* @property {CustomMapping} [customMapping] - Custom mapping of locale codes to their names
|
|
17
18
|
*/
|
|
18
19
|
type GTConstructorParams = {
|
|
19
|
-
apiKey?: string;
|
|
20
|
+
apiKey?: string; /** @deprecated Pass the key as `apiKey`; there is one kind of API key. */
|
|
20
21
|
devApiKey?: string;
|
|
21
22
|
sourceLocale?: string;
|
|
22
23
|
targetLocale?: string;
|
|
@@ -24,6 +25,7 @@ type GTConstructorParams = {
|
|
|
24
25
|
projectId?: string;
|
|
25
26
|
baseUrl?: string;
|
|
26
27
|
customMapping?: CustomMapping;
|
|
28
|
+
userTokenProvider?: UserTokenProvider;
|
|
27
29
|
};
|
|
28
30
|
/**
|
|
29
31
|
* GTRuntime is the runtime core of the GT driver: locale management,
|
|
@@ -47,8 +49,10 @@ declare class GTRuntime {
|
|
|
47
49
|
projectId?: string;
|
|
48
50
|
/** API key for accessing the translation service */
|
|
49
51
|
apiKey?: string;
|
|
50
|
-
/**
|
|
52
|
+
/** @deprecated Pass the key as `apiKey`; there is one kind of API key. */
|
|
51
53
|
devApiKey?: string;
|
|
54
|
+
/** User-token provider used when no API key is configured */
|
|
55
|
+
userTokenProvider?: UserTokenProvider;
|
|
52
56
|
/** Source locale for translations */
|
|
53
57
|
sourceLocale?: string;
|
|
54
58
|
/** Target locale for translations */
|
|
@@ -89,7 +93,8 @@ declare class GTRuntime {
|
|
|
89
93
|
locales,
|
|
90
94
|
projectId,
|
|
91
95
|
customMapping,
|
|
92
|
-
baseUrl
|
|
96
|
+
baseUrl,
|
|
97
|
+
userTokenProvider
|
|
93
98
|
}: GTConstructorParams): void;
|
|
94
99
|
/** Convert app identity only where a GT service expects a language code. */
|
|
95
100
|
protected resolveServiceLocale(locale: string): string;
|
|
@@ -100,13 +105,13 @@ declare class GTRuntime {
|
|
|
100
105
|
*/
|
|
101
106
|
protected resolveServiceResponseLocale(locale: string): string;
|
|
102
107
|
protected _getTranslationConfig(): TranslationRequestConfig;
|
|
103
|
-
protected _validateAuth(functionName: string): void;
|
|
104
108
|
/**
|
|
105
109
|
* Translates a single source string to the target locale.
|
|
106
110
|
* Routes through {@link translateMany} under the hood.
|
|
107
111
|
*
|
|
108
112
|
* @param {string} source - The source string to translate.
|
|
109
113
|
* @param {object} options - Translation options including targetLocale and optional entry metadata.
|
|
114
|
+
* @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.
|
|
110
115
|
* @returns {Promise<TranslationResult | TranslationError>} The translated content.
|
|
111
116
|
*
|
|
112
117
|
* @example
|
|
@@ -126,6 +131,7 @@ declare class GTRuntime {
|
|
|
126
131
|
*
|
|
127
132
|
* @param {TranslateManyEntry[] | Record<string, TranslateManyEntry>} sources - The source entries to translate. Can be an array or a record keyed by hash.
|
|
128
133
|
* @param {object} options - Translation options including targetLocale.
|
|
134
|
+
* @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.
|
|
129
135
|
* @returns {Promise<TranslateManyResult | Record<string, TranslationResult>>} The translated contents. An array if sources was an array, a record if sources was a record.
|
|
130
136
|
*
|
|
131
137
|
* @example
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as TranslationRequestConfig, Ft as TranslateManyEntry, It as TranslateOptions, X as TranslationError, Y as TranslateManyResult, Z as TranslationResult } from "./types-Si4UstLL.mjs";
|
|
2
|
+
import { UserTokenProvider } from "@generaltranslation/api";
|
|
2
3
|
import { LocaleConfig } from "@generaltranslation/format";
|
|
3
4
|
import { CustomMapping, CustomRegionMapping, CutoffFormatOptions, FormatVariables, LocaleProperties, StringFormat } from "@generaltranslation/format/types";
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ import { CustomMapping, CustomRegionMapping, CutoffFormatOptions, FormatVariable
|
|
|
7
8
|
* Type representing the constructor parameters for the GT and GTRuntime classes.
|
|
8
9
|
* @typedef {Object} GTConstructorParams
|
|
9
10
|
* @property {string} [apiKey] - The API key for accessing the translation service
|
|
10
|
-
* @property {string} [devApiKey] -
|
|
11
|
+
* @property {string} [devApiKey] - Deprecated alias for apiKey
|
|
11
12
|
* @property {string} [sourceLocale] - The default source locale for translations
|
|
12
13
|
* @property {string} [targetLocale] - The default target locale for translations
|
|
13
14
|
* @property {string[]} [locales] - Array of supported locales
|
|
@@ -16,7 +17,7 @@ import { CustomMapping, CustomRegionMapping, CutoffFormatOptions, FormatVariable
|
|
|
16
17
|
* @property {CustomMapping} [customMapping] - Custom mapping of locale codes to their names
|
|
17
18
|
*/
|
|
18
19
|
type GTConstructorParams = {
|
|
19
|
-
apiKey?: string;
|
|
20
|
+
apiKey?: string; /** @deprecated Pass the key as `apiKey`; there is one kind of API key. */
|
|
20
21
|
devApiKey?: string;
|
|
21
22
|
sourceLocale?: string;
|
|
22
23
|
targetLocale?: string;
|
|
@@ -24,6 +25,7 @@ type GTConstructorParams = {
|
|
|
24
25
|
projectId?: string;
|
|
25
26
|
baseUrl?: string;
|
|
26
27
|
customMapping?: CustomMapping;
|
|
28
|
+
userTokenProvider?: UserTokenProvider;
|
|
27
29
|
};
|
|
28
30
|
/**
|
|
29
31
|
* GTRuntime is the runtime core of the GT driver: locale management,
|
|
@@ -47,8 +49,10 @@ declare class GTRuntime {
|
|
|
47
49
|
projectId?: string;
|
|
48
50
|
/** API key for accessing the translation service */
|
|
49
51
|
apiKey?: string;
|
|
50
|
-
/**
|
|
52
|
+
/** @deprecated Pass the key as `apiKey`; there is one kind of API key. */
|
|
51
53
|
devApiKey?: string;
|
|
54
|
+
/** User-token provider used when no API key is configured */
|
|
55
|
+
userTokenProvider?: UserTokenProvider;
|
|
52
56
|
/** Source locale for translations */
|
|
53
57
|
sourceLocale?: string;
|
|
54
58
|
/** Target locale for translations */
|
|
@@ -89,7 +93,8 @@ declare class GTRuntime {
|
|
|
89
93
|
locales,
|
|
90
94
|
projectId,
|
|
91
95
|
customMapping,
|
|
92
|
-
baseUrl
|
|
96
|
+
baseUrl,
|
|
97
|
+
userTokenProvider
|
|
93
98
|
}: GTConstructorParams): void;
|
|
94
99
|
/** Convert app identity only where a GT service expects a language code. */
|
|
95
100
|
protected resolveServiceLocale(locale: string): string;
|
|
@@ -100,13 +105,13 @@ declare class GTRuntime {
|
|
|
100
105
|
*/
|
|
101
106
|
protected resolveServiceResponseLocale(locale: string): string;
|
|
102
107
|
protected _getTranslationConfig(): TranslationRequestConfig;
|
|
103
|
-
protected _validateAuth(functionName: string): void;
|
|
104
108
|
/**
|
|
105
109
|
* Translates a single source string to the target locale.
|
|
106
110
|
* Routes through {@link translateMany} under the hood.
|
|
107
111
|
*
|
|
108
112
|
* @param {string} source - The source string to translate.
|
|
109
113
|
* @param {object} options - Translation options including targetLocale and optional entry metadata.
|
|
114
|
+
* @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.
|
|
110
115
|
* @returns {Promise<TranslationResult | TranslationError>} The translated content.
|
|
111
116
|
*
|
|
112
117
|
* @example
|
|
@@ -126,6 +131,7 @@ declare class GTRuntime {
|
|
|
126
131
|
*
|
|
127
132
|
* @param {TranslateManyEntry[] | Record<string, TranslateManyEntry>} sources - The source entries to translate. Can be an array or a record keyed by hash.
|
|
128
133
|
* @param {object} options - Translation options including targetLocale.
|
|
134
|
+
* @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.
|
|
129
135
|
* @returns {Promise<TranslateManyResult | Record<string, TranslationResult>>} The translated contents. An array if sources was an array, a record if sources was a record.
|
|
130
136
|
*
|
|
131
137
|
* @example
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { LocaleConfig } from '@generaltranslation/format';
|
|
2
2
|
import type { CustomMapping, CustomRegionMapping, CutoffFormatOptions, FormatVariables, LocaleProperties, StringFormat } from '@generaltranslation/format/types';
|
|
3
|
+
import type { UserTokenProvider } from '@generaltranslation/api';
|
|
3
4
|
import { TranslateManyResult, TranslationError, TranslationRequestConfig, TranslationResult, TranslateManyEntry } from './types';
|
|
4
5
|
import { TranslateOptions } from './types-dir/api/entry';
|
|
5
6
|
/**
|
|
6
7
|
* Type representing the constructor parameters for the GT and GTRuntime classes.
|
|
7
8
|
* @typedef {Object} GTConstructorParams
|
|
8
9
|
* @property {string} [apiKey] - The API key for accessing the translation service
|
|
9
|
-
* @property {string} [devApiKey] -
|
|
10
|
+
* @property {string} [devApiKey] - Deprecated alias for apiKey
|
|
10
11
|
* @property {string} [sourceLocale] - The default source locale for translations
|
|
11
12
|
* @property {string} [targetLocale] - The default target locale for translations
|
|
12
13
|
* @property {string[]} [locales] - Array of supported locales
|
|
@@ -16,6 +17,7 @@ import { TranslateOptions } from './types-dir/api/entry';
|
|
|
16
17
|
*/
|
|
17
18
|
export type GTConstructorParams = {
|
|
18
19
|
apiKey?: string;
|
|
20
|
+
/** @deprecated Pass the key as `apiKey`; there is one kind of API key. */
|
|
19
21
|
devApiKey?: string;
|
|
20
22
|
sourceLocale?: string;
|
|
21
23
|
targetLocale?: string;
|
|
@@ -23,6 +25,7 @@ export type GTConstructorParams = {
|
|
|
23
25
|
projectId?: string;
|
|
24
26
|
baseUrl?: string;
|
|
25
27
|
customMapping?: CustomMapping;
|
|
28
|
+
userTokenProvider?: UserTokenProvider;
|
|
26
29
|
};
|
|
27
30
|
/**
|
|
28
31
|
* GTRuntime is the runtime core of the GT driver: locale management,
|
|
@@ -46,8 +49,10 @@ export declare class GTRuntime {
|
|
|
46
49
|
projectId?: string;
|
|
47
50
|
/** API key for accessing the translation service */
|
|
48
51
|
apiKey?: string;
|
|
49
|
-
/**
|
|
52
|
+
/** @deprecated Pass the key as `apiKey`; there is one kind of API key. */
|
|
50
53
|
devApiKey?: string;
|
|
54
|
+
/** User-token provider used when no API key is configured */
|
|
55
|
+
userTokenProvider?: UserTokenProvider;
|
|
51
56
|
/** Source locale for translations */
|
|
52
57
|
sourceLocale?: string;
|
|
53
58
|
/** Target locale for translations */
|
|
@@ -80,7 +85,7 @@ export declare class GTRuntime {
|
|
|
80
85
|
* });
|
|
81
86
|
*/
|
|
82
87
|
constructor(params?: GTConstructorParams);
|
|
83
|
-
setConfig({ apiKey, devApiKey, sourceLocale, targetLocale, locales, projectId, customMapping, baseUrl, }: GTConstructorParams): void;
|
|
88
|
+
setConfig({ apiKey, devApiKey, sourceLocale, targetLocale, locales, projectId, customMapping, baseUrl, userTokenProvider, }: GTConstructorParams): void;
|
|
84
89
|
/** Convert app identity only where a GT service expects a language code. */
|
|
85
90
|
protected resolveServiceLocale(locale: string): string;
|
|
86
91
|
/**
|
|
@@ -90,13 +95,13 @@ export declare class GTRuntime {
|
|
|
90
95
|
*/
|
|
91
96
|
protected resolveServiceResponseLocale(locale: string): string;
|
|
92
97
|
protected _getTranslationConfig(): TranslationRequestConfig;
|
|
93
|
-
protected _validateAuth(functionName: string): void;
|
|
94
98
|
/**
|
|
95
99
|
* Translates a single source string to the target locale.
|
|
96
100
|
* Routes through {@link translateMany} under the hood.
|
|
97
101
|
*
|
|
98
102
|
* @param {string} source - The source string to translate.
|
|
99
103
|
* @param {object} options - Translation options including targetLocale and optional entry metadata.
|
|
104
|
+
* @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.
|
|
100
105
|
* @returns {Promise<TranslationResult | TranslationError>} The translated content.
|
|
101
106
|
*
|
|
102
107
|
* @example
|
|
@@ -116,6 +121,7 @@ export declare class GTRuntime {
|
|
|
116
121
|
*
|
|
117
122
|
* @param {TranslateManyEntry[] | Record<string, TranslateManyEntry>} sources - The source entries to translate. Can be an array or a record keyed by hash.
|
|
118
123
|
* @param {object} options - Translation options including targetLocale.
|
|
124
|
+
* @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.
|
|
119
125
|
* @returns {Promise<TranslateManyResult | Record<string, TranslationResult>>} The translated contents. An array if sources was an array, a record if sources was a record.
|
|
120
126
|
*
|
|
121
127
|
* @example
|
package/dist/runtime.js
CHANGED
|
@@ -58,10 +58,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
58
58
|
};
|
|
59
59
|
// ----- IMPORTS ----- //
|
|
60
60
|
import { LocaleConfig, getRegionProperties as _getRegionProperties, isValidLocale as _isValidLocale, requiresTranslation as _requiresTranslation, resolveAliasLocale as _resolveAliasLocale, resolveCanonicalLocale as _resolveCanonicalLocale, } from '@generaltranslation/format';
|
|
61
|
-
import {
|
|
62
|
-
import {
|
|
63
|
-
import { gtInstanceLogger } from './logging/logger';
|
|
64
|
-
import { _translateMany } from './translate/translateMany';
|
|
61
|
+
import { noSourceLocaleProvidedError, noTargetLocaleProvidedError, invalidLocaleError, invalidLocalesError, } from './logging/errors';
|
|
62
|
+
import { translate as translateWithConfig, translateMany as translateManyWithConfig, } from './translate/runtimeTranslate';
|
|
65
63
|
/**
|
|
66
64
|
* GTRuntime is the runtime core of the GT driver: locale management,
|
|
67
65
|
* formatting, and runtime translation requests.
|
|
@@ -99,6 +97,7 @@ var GTRuntime = /** @class */ (function () {
|
|
|
99
97
|
// Read environment
|
|
100
98
|
if (typeof process !== 'undefined') {
|
|
101
99
|
this.apiKey || (this.apiKey = (_a = process.env) === null || _a === void 0 ? void 0 : _a.GT_API_KEY);
|
|
100
|
+
// Deprecated with devApiKey; frameworks resolve the hot-reload key themselves.
|
|
102
101
|
this.devApiKey || (this.devApiKey = (_b = process.env) === null || _b === void 0 ? void 0 : _b.GT_DEV_API_KEY);
|
|
103
102
|
this.projectId || (this.projectId = (_c = process.env) === null || _c === void 0 ? void 0 : _c.GT_PROJECT_ID);
|
|
104
103
|
}
|
|
@@ -115,7 +114,7 @@ var GTRuntime = /** @class */ (function () {
|
|
|
115
114
|
});
|
|
116
115
|
GTRuntime.prototype.setConfig = function (_a) {
|
|
117
116
|
var _b;
|
|
118
|
-
var apiKey = _a.apiKey, devApiKey = _a.devApiKey, sourceLocale = _a.sourceLocale, targetLocale = _a.targetLocale, locales = _a.locales, projectId = _a.projectId, customMapping = _a.customMapping, baseUrl = _a.baseUrl;
|
|
117
|
+
var apiKey = _a.apiKey, devApiKey = _a.devApiKey, sourceLocale = _a.sourceLocale, targetLocale = _a.targetLocale, locales = _a.locales, projectId = _a.projectId, customMapping = _a.customMapping, baseUrl = _a.baseUrl, userTokenProvider = _a.userTokenProvider;
|
|
119
118
|
var effectiveCustomMapping = customMapping !== null && customMapping !== void 0 ? customMapping : this.customMapping;
|
|
120
119
|
// ----- Environment properties ----- //
|
|
121
120
|
if (apiKey)
|
|
@@ -124,6 +123,8 @@ var GTRuntime = /** @class */ (function () {
|
|
|
124
123
|
this.devApiKey = devApiKey;
|
|
125
124
|
if (projectId)
|
|
126
125
|
this.projectId = projectId;
|
|
126
|
+
if (userTokenProvider)
|
|
127
|
+
this.userTokenProvider = userTokenProvider;
|
|
127
128
|
// ----- Validate configured locale identities ----- //
|
|
128
129
|
// source locale
|
|
129
130
|
if (sourceLocale) {
|
|
@@ -202,28 +203,16 @@ var GTRuntime = /** @class */ (function () {
|
|
|
202
203
|
baseUrl: this.baseUrl,
|
|
203
204
|
apiKey: this.apiKey || this.devApiKey,
|
|
204
205
|
projectId: this.projectId || '',
|
|
206
|
+
userTokenProvider: this.userTokenProvider,
|
|
205
207
|
};
|
|
206
208
|
};
|
|
207
|
-
GTRuntime.prototype._validateAuth = function (functionName) {
|
|
208
|
-
var errors = [];
|
|
209
|
-
if (!this.apiKey && !this.devApiKey) {
|
|
210
|
-
var error = noApiKeyProvidedError(functionName);
|
|
211
|
-
errors.push(error);
|
|
212
|
-
}
|
|
213
|
-
if (!this.projectId) {
|
|
214
|
-
var error = noProjectIdProvidedError(functionName);
|
|
215
|
-
errors.push(error);
|
|
216
|
-
}
|
|
217
|
-
if (errors.length) {
|
|
218
|
-
throw new Error(errors.join('\n'));
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
209
|
/**
|
|
222
210
|
* Translates a single source string to the target locale.
|
|
223
211
|
* Routes through {@link translateMany} under the hood.
|
|
224
212
|
*
|
|
225
213
|
* @param {string} source - The source string to translate.
|
|
226
214
|
* @param {object} options - Translation options including targetLocale and optional entry metadata.
|
|
215
|
+
* @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.
|
|
227
216
|
* @returns {Promise<TranslationResult | TranslationError>} The translated content.
|
|
228
217
|
*
|
|
229
218
|
* @example
|
|
@@ -238,59 +227,15 @@ var GTRuntime = /** @class */ (function () {
|
|
|
238
227
|
*/
|
|
239
228
|
GTRuntime.prototype.translate = function (source, options, timeout) {
|
|
240
229
|
return __awaiter(this, void 0, void 0, function () {
|
|
241
|
-
var targetLocale, error, sourceLocale, results;
|
|
242
230
|
return __generator(this, function (_a) {
|
|
243
|
-
|
|
244
|
-
case 0:
|
|
245
|
-
// Normalize string shorthand to options object
|
|
246
|
-
if (typeof options === 'string') {
|
|
247
|
-
options = { targetLocale: options };
|
|
248
|
-
}
|
|
249
|
-
// Validation
|
|
250
|
-
this._validateAuth('translate');
|
|
251
|
-
targetLocale = (options === null || options === void 0 ? void 0 : options.targetLocale) || this.targetLocale;
|
|
252
|
-
if (!targetLocale) {
|
|
253
|
-
error = noTargetLocaleProvidedError('translate');
|
|
254
|
-
gtInstanceLogger.error(error);
|
|
255
|
-
throw new Error(error);
|
|
256
|
-
}
|
|
257
|
-
// Replace target locale with canonical locale
|
|
258
|
-
targetLocale = this.resolveServiceLocale(targetLocale);
|
|
259
|
-
sourceLocale = this.resolveServiceLocale((options === null || options === void 0 ? void 0 : options.sourceLocale) || this.sourceLocale || libraryDefaultLocale);
|
|
260
|
-
return [4 /*yield*/, _translateMany([source], __assign(__assign({}, options), { targetLocale: targetLocale, sourceLocale: sourceLocale }), this._getTranslationConfig(), timeout)];
|
|
261
|
-
case 1:
|
|
262
|
-
results = _a.sent();
|
|
263
|
-
return [2 /*return*/, results[0]];
|
|
264
|
-
}
|
|
231
|
+
return [2 /*return*/, translateWithConfig(source, options, __assign(__assign({}, this._getTranslationConfig()), { customMapping: this.customMapping, timeoutMs: timeout || undefined }), this)];
|
|
265
232
|
});
|
|
266
233
|
});
|
|
267
234
|
};
|
|
268
235
|
GTRuntime.prototype.translateMany = function (sources, options, timeout) {
|
|
269
236
|
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
-
var targetLocale, error, sourceLocale;
|
|
271
237
|
return __generator(this, function (_a) {
|
|
272
|
-
|
|
273
|
-
case 0:
|
|
274
|
-
// Normalize string shorthand to options object
|
|
275
|
-
if (typeof options === 'string') {
|
|
276
|
-
options = { targetLocale: options };
|
|
277
|
-
}
|
|
278
|
-
// Validation
|
|
279
|
-
this._validateAuth('translateMany');
|
|
280
|
-
targetLocale = (options === null || options === void 0 ? void 0 : options.targetLocale) || this.targetLocale;
|
|
281
|
-
if (!targetLocale) {
|
|
282
|
-
error = noTargetLocaleProvidedError('translateMany');
|
|
283
|
-
gtInstanceLogger.error(error);
|
|
284
|
-
throw new Error(error);
|
|
285
|
-
}
|
|
286
|
-
// Replace target locale with canonical locale
|
|
287
|
-
targetLocale = this.resolveServiceLocale(targetLocale);
|
|
288
|
-
sourceLocale = this.resolveServiceLocale((options === null || options === void 0 ? void 0 : options.sourceLocale) || this.sourceLocale || libraryDefaultLocale);
|
|
289
|
-
return [4 /*yield*/, _translateMany(sources, __assign(__assign({}, options), { targetLocale: targetLocale, sourceLocale: sourceLocale }), this._getTranslationConfig(), timeout)];
|
|
290
|
-
case 1:
|
|
291
|
-
// Request the translation.
|
|
292
|
-
return [2 /*return*/, _a.sent()];
|
|
293
|
-
}
|
|
238
|
+
return [2 /*return*/, translateManyWithConfig(sources, options, __assign(__assign({}, this._getTranslationConfig()), { customMapping: this.customMapping, timeoutMs: timeout || undefined }), this)];
|
|
294
239
|
});
|
|
295
240
|
});
|
|
296
241
|
};
|