generaltranslation 8.2.10 → 8.2.12
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 +13 -0
- package/dist/{IntlCache-k2qfrDqB.cjs → IntlCache-CAW8tKhd.cjs} +12 -12
- package/dist/IntlCache-CAW8tKhd.cjs.map +1 -0
- package/dist/{IntlCache-Ccg_cQPR.mjs → IntlCache-WZk0rKvj.mjs} +12 -12
- package/dist/IntlCache-WZk0rKvj.mjs.map +1 -0
- package/dist/{base64-CUcEPEC5.cjs → base64-2fu94Klt.cjs} +3 -3
- package/dist/base64-2fu94Klt.cjs.map +1 -0
- package/dist/{base64-C1sogiix.mjs → base64-DH0STixb.mjs} +3 -3
- package/dist/base64-DH0STixb.mjs.map +1 -0
- package/dist/{core-Bx0m6GOp.mjs → core-7RJsqw6c.mjs} +17 -19
- package/dist/core-7RJsqw6c.mjs.map +1 -0
- package/dist/{core-CJMv4fMa.d.cts → core-CGhlXrrK.d.mts} +8 -8
- package/dist/{core-3SOQ5ND6.cjs → core-CST4J4WU.cjs} +17 -19
- package/dist/core-CST4J4WU.cjs.map +1 -0
- package/dist/{core-DtPj_ruw.d.mts → core-D-E8qhLn.d.cts} +8 -8
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +1 -1
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{id-COlX5v3V.cjs → id-CyiXsQrY.cjs} +9 -9
- package/dist/id-CyiXsQrY.cjs.map +1 -0
- package/dist/{id-BmOyfaug.mjs → id-DbD7K-HL.mjs} +9 -9
- package/dist/id-DbD7K-HL.mjs.map +1 -0
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +9 -9
- package/dist/id.d.mts +9 -9
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +140 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -88
- package/dist/index.d.mts +88 -88
- package/dist/index.mjs +140 -140
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +41 -26
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +38 -23
- package/dist/internal.d.mts +38 -23
- package/dist/internal.mjs +41 -26
- package/dist/internal.mjs.map +1 -1
- package/dist/{types-Dfy_sRLD.d.mts → types-BsGsgJWF.d.mts} +36 -33
- package/dist/{types-mZeu4HS3.d.cts → types-V5rqd1WR.d.cts} +36 -33
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +3 -4
- package/dist/IntlCache-Ccg_cQPR.mjs.map +0 -1
- package/dist/IntlCache-k2qfrDqB.cjs.map +0 -1
- package/dist/base64-C1sogiix.mjs.map +0 -1
- package/dist/base64-CUcEPEC5.cjs.map +0 -1
- package/dist/core-3SOQ5ND6.cjs.map +0 -1
- package/dist/core-Bx0m6GOp.mjs.map +0 -1
- package/dist/id-BmOyfaug.mjs.map +0 -1
- package/dist/id-COlX5v3V.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# generaltranslation
|
|
2
2
|
|
|
3
|
+
## 8.2.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1364](https://github.com/generaltranslation/gt/pull/1364) [`9eae4d9`](https://github.com/generaltranslation/gt/commit/9eae4d93476688b621c739683c8bac64cbf50bf0) Thanks [@pie575](https://github.com/pie575)! - Update Derive docs comments
|
|
8
|
+
|
|
9
|
+
## 8.2.11
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1308](https://github.com/generaltranslation/gt/pull/1308) [`fecaf93`](https://github.com/generaltranslation/gt/commit/fecaf93d1dcae65598b3f81b8eeabaeb35be13c6) Thanks [@bgub](https://github.com/bgub)! - Add shared cache expiry, batching, and runtime translation configuration to I18nManager.
|
|
14
|
+
|
|
3
15
|
## 8.2.10
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -269,6 +281,7 @@
|
|
|
269
281
|
https://generaltranslation.com/blog/generaltranslation_v8
|
|
270
282
|
|
|
271
283
|
Please update the following packages to the latest version:
|
|
284
|
+
|
|
272
285
|
- generaltranslation: `7.9.1` or later
|
|
273
286
|
- gtx-cli: `2.4.15` or later
|
|
274
287
|
- gt-sanity: `1.0.11` or later
|
|
@@ -34,16 +34,16 @@ const TERMINATOR_MAP = {
|
|
|
34
34
|
var CutoffFormatConstructor = class {
|
|
35
35
|
/**
|
|
36
36
|
* Constructor
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {Intl.LocalesArgument} locales - The locales to use for formatting.
|
|
38
38
|
* @param {CutoffFormatOptions} options - The options for formatting.
|
|
39
|
-
* @param {number} [
|
|
39
|
+
* @param {number} [options.maxChars] - The maximum number of characters to display.
|
|
40
40
|
* - Undefined values are treated as no cutoff.
|
|
41
41
|
* - Negative values follow .slice() behavior and terminator will be added before the value.
|
|
42
42
|
* - 0 will result in an empty string.
|
|
43
43
|
* - If cutoff results in an empty string, no terminator is added.
|
|
44
|
-
* @param {CutoffFormatStyle} [
|
|
45
|
-
* @param {string} [
|
|
46
|
-
* @param {string} [
|
|
44
|
+
* @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
|
|
45
|
+
* @param {string} [options.terminator] - Optional override the terminator to use.
|
|
46
|
+
* @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
|
|
47
47
|
* - If no terminator is provided, then separator is ignored.
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
@@ -154,24 +154,24 @@ const CustomIntl = {
|
|
|
154
154
|
};
|
|
155
155
|
/**
|
|
156
156
|
* Cache for Intl and custom format instances to avoid repeated instantiation
|
|
157
|
-
* Uses a two-level structure: constructor name -> cache key -> instance
|
|
157
|
+
* Uses a two-level structure: constructor name -> cache key -> instance.
|
|
158
158
|
*/
|
|
159
159
|
var IntlCache = class {
|
|
160
160
|
constructor() {
|
|
161
161
|
this.cache = {};
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* Generates a consistent cache key from locales and options
|
|
165
|
-
* Handles all LocalesArgument types (string, Locale, array, undefined)
|
|
164
|
+
* Generates a consistent cache key from locales and options.
|
|
165
|
+
* Handles all LocalesArgument types (string, Locale, array, undefined).
|
|
166
166
|
*/
|
|
167
167
|
_generateKey(locales, options = {}) {
|
|
168
168
|
return `${!locales ? "undefined" : Array.isArray(locales) ? locales.map((l) => String(l)).join(",") : String(locales)}:${options ? JSON.stringify(options, Object.keys(options).sort()) : "{}"}`;
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
171
|
* Gets a cached Intl instance or creates a new one if not found
|
|
172
|
-
* @param constructor The name of the Intl constructor to use
|
|
173
|
-
* @param args Constructor arguments (locales, options)
|
|
174
|
-
* @returns Cached or newly created Intl instance
|
|
172
|
+
* @param constructor The name of the Intl constructor to use.
|
|
173
|
+
* @param args Constructor arguments (locales, options).
|
|
174
|
+
* @returns Cached or newly created Intl instance.
|
|
175
175
|
*/
|
|
176
176
|
get(constructor, ...args) {
|
|
177
177
|
const [locales = "en", options = {}] = args;
|
|
@@ -209,4 +209,4 @@ Object.defineProperty(exports, "libraryDefaultLocale", {
|
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
-
//# sourceMappingURL=IntlCache-
|
|
212
|
+
//# sourceMappingURL=IntlCache-CAW8tKhd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlCache-CAW8tKhd.cjs","names":[],"sources":["../src/settings/settings.ts","../src/errors/formattingErrors.ts","../src/formatting/custom-formats/CutoffFormat/constants.ts","../src/formatting/custom-formats/CutoffFormat/CutoffFormat.ts","../src/cache/IntlCache.ts"],"sourcesContent":["export const libraryDefaultLocale = 'en' as const;\nexport const defaultTimeout = 60000;\n","export const createInvalidCutoffStyleError = (style: string) =>\n `generaltranslation Formatting Error: Invalid cutoff style: ${style}.`;\n","import { CutoffFormatStyle, ResolvedTerminatorOptions } from './types';\n\nexport const DEFAULT_CUTOFF_FORMAT_STYLE: CutoffFormatStyle = 'ellipsis';\n\nexport const DEFAULT_TERMINATOR_KEY = 'DEFAULT_TERMINATOR_KEY';\n\nexport const TERMINATOR_MAP: Record<\n CutoffFormatStyle,\n Record<string | typeof DEFAULT_TERMINATOR_KEY, ResolvedTerminatorOptions>\n> = {\n ellipsis: {\n fr: {\n terminator: '…',\n separator: '\\u202F',\n },\n zh: {\n terminator: '……',\n separator: undefined,\n },\n ja: {\n terminator: '……',\n separator: undefined,\n },\n [DEFAULT_TERMINATOR_KEY]: {\n terminator: '…',\n separator: undefined,\n },\n },\n none: {\n [DEFAULT_TERMINATOR_KEY]: {\n terminator: undefined,\n separator: undefined,\n },\n },\n};\n","import { createInvalidCutoffStyleError } from '../../../errors/formattingErrors';\nimport { libraryDefaultLocale } from '../../../settings/settings';\nimport {\n DEFAULT_CUTOFF_FORMAT_STYLE,\n DEFAULT_TERMINATOR_KEY,\n TERMINATOR_MAP,\n} from './constants';\nimport {\n CutoffFormat,\n CutoffFormatOptions,\n CutoffFormatStyle,\n PostpendedCutoffParts,\n PrependedCutoffParts,\n ResolvedCutoffFormatOptions,\n ResolvedTerminatorOptions,\n} from './types';\n\nexport class CutoffFormatConstructor implements CutoffFormat {\n private locale: string;\n private options: ResolvedCutoffFormatOptions;\n private additionLength: number;\n /**\n * Constructor\n * @param {Intl.LocalesArgument} locales - The locales to use for formatting.\n * @param {CutoffFormatOptions} options - The options for formatting.\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 *\n * @example\n * const format = new CutoffFormat('en', { maxChars: 5 });\n * format.format('Hello, world!'); // 'Hello...'\n *\n * const format = new CutoffFormat('en', { maxChars: -3 });\n * format.format('Hello, world!'); // '...ld!'\n */\n constructor(\n locales: Intl.LocalesArgument,\n options: CutoffFormatOptions = {}\n ) {\n // Determine locale (this replicates Intl.NumberFormat behavior including silent failure)\n try {\n // Normalize locales to string\n const localesList = !locales\n ? [libraryDefaultLocale]\n : Array.isArray(locales)\n ? locales.map((l) => String(l))\n : [String(locales)];\n const canonicalLocales = Intl.getCanonicalLocales(localesList);\n this.locale = canonicalLocales.length\n ? canonicalLocales[0]\n : libraryDefaultLocale;\n } catch {\n this.locale = libraryDefaultLocale;\n }\n\n // Follows Intl.NumberFormat behavior of throwing an error when currency is invalid\n if (!TERMINATOR_MAP[options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE]) {\n throw new Error(\n createInvalidCutoffStyleError(\n options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE\n )\n );\n }\n\n // Resolve terminator options.\n let style: CutoffFormatStyle | undefined;\n let presetTerminatorOptions: ResolvedTerminatorOptions | undefined;\n if (options.maxChars !== undefined) {\n style = options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE;\n // TODO: need more sophisticated locale negotiation if we want to add support for region/script/etc.-specific terminators in the future\n const languageCode = new Intl.Locale(this.locale).language;\n presetTerminatorOptions =\n TERMINATOR_MAP[style][languageCode] ||\n TERMINATOR_MAP[style][DEFAULT_TERMINATOR_KEY];\n }\n let terminator: ResolvedTerminatorOptions['terminator'] =\n options.terminator ?? presetTerminatorOptions?.terminator;\n let separator: ResolvedTerminatorOptions['separator'] =\n terminator != null\n ? (options.separator ?? presetTerminatorOptions?.separator)\n : undefined;\n // // Remove terminator and separator if maxChars does have enough space\n this.additionLength = (terminator?.length ?? 0) + (separator?.length ?? 0);\n if (\n options.maxChars !== undefined &&\n Math.abs(options.maxChars) < this.additionLength\n ) {\n terminator = undefined;\n separator = undefined;\n }\n\n this.options = {\n maxChars: options.maxChars,\n style,\n terminator,\n separator,\n };\n }\n\n /**\n * Format a value according to the cutoff options, returning a formatted string.\n *\n * @param {string} value - The string value to format with cutoff behavior.\n * @returns {string} The formatted string with terminator applied if cutoff occurs.\n *\n * @example\n * const formatter = new CutoffFormatConstructor('en', { maxChars: 8, style: 'ellipsis' });\n * formatter.format('Hello, world!'); // Returns 'Hello, w...'\n */\n format(value: string): string {\n return this.formatToParts(value).join('');\n }\n\n /**\n * Format a value to parts according to the cutoff options, returning an array of string parts.\n * This method breaks down the formatted result into individual components for more granular control.\n *\n * @param {string} value - The string value to format with cutoff behavior.\n * @returns {PrependedCutoffParts | PostpendedCutoffParts} An array of string parts representing the formatted result.\n * - For positive maxChars: [cutoffValue, separator?, terminator?]\n * - For negative maxChars: [terminator?, separator?, cutoffValue]\n * - For no cutoff: [originalValue]\n *\n * @example\n * const formatter = new CutoffFormatConstructor('en', { maxChars: 5, style: 'ellipsis' });\n * formatter.formatToParts('Hello, world!'); // Returns ['Hello', '...']\n */\n formatToParts(value: string): PrependedCutoffParts | PostpendedCutoffParts {\n const { maxChars, terminator, separator } = this.options;\n\n // Slice our value\n // const additionLength = (terminator?.length ?? 0) + (separator?.length ?? 0);\n const adjustedChars =\n maxChars === undefined || Math.abs(maxChars) >= value.length\n ? maxChars\n : maxChars >= 0\n ? Math.max(0, maxChars - this.additionLength)\n : Math.min(0, maxChars + this.additionLength);\n const slicedValue =\n adjustedChars !== undefined && adjustedChars > -1\n ? value.slice(0, adjustedChars)\n : value.slice(adjustedChars);\n\n // No cutoff, no terminator -> value only\n if (\n maxChars == null ||\n adjustedChars == null ||\n adjustedChars === 0 ||\n terminator == null ||\n value.length <= Math.abs(maxChars)\n ) {\n return [slicedValue];\n }\n\n // Postpended cutoff.\n if (adjustedChars > 0) {\n return separator != null\n ? [slicedValue, separator, terminator]\n : [slicedValue, terminator];\n }\n // Prepended cutoff.\n else {\n return separator != null\n ? [terminator, separator, slicedValue]\n : [terminator, slicedValue];\n }\n }\n\n /**\n * Get the resolved options\n * @returns {ResolvedCutoffFormatOptions} The resolved options.\n */\n resolvedOptions(): ResolvedCutoffFormatOptions {\n return this.options;\n }\n}\n","import { libraryDefaultLocale } from '../settings/settings';\nimport { CutoffFormatConstructor } from '../formatting/custom-formats/CutoffFormat/CutoffFormat';\nimport {\n ConstructorType,\n CustomIntlConstructors,\n CustomIntlType,\n IntlCacheObject,\n} from './types';\n\n/**\n * Object mapping constructor names to their respective constructor functions\n * Includes all native Intl constructors plus custom ones like CutoffFormat\n */\nconst CustomIntl: CustomIntlType = {\n Collator: Intl.Collator,\n DateTimeFormat: Intl.DateTimeFormat,\n DisplayNames: Intl.DisplayNames,\n ListFormat: Intl.ListFormat,\n Locale: Intl.Locale,\n NumberFormat: Intl.NumberFormat,\n PluralRules: Intl.PluralRules,\n RelativeTimeFormat: Intl.RelativeTimeFormat,\n Segmenter: Intl.Segmenter,\n CutoffFormat: CutoffFormatConstructor,\n};\n\n/**\n * Cache for Intl and custom format instances to avoid repeated instantiation\n * Uses a two-level structure: constructor name -> cache key -> instance.\n */\nclass IntlCache {\n private cache: IntlCacheObject;\n\n constructor() {\n this.cache = {};\n }\n\n /**\n * Generates a consistent cache key from locales and options.\n * Handles all LocalesArgument types (string, Locale, array, undefined).\n */\n private _generateKey(locales: Intl.LocalesArgument, options = {}) {\n // Normalize locales to string representation\n const localeKey = !locales\n ? 'undefined'\n : Array.isArray(locales)\n ? locales.map((l) => String(l)).join(',')\n : String(locales);\n\n // Sort option keys to ensure consistent key generation regardless of property order\n const sortedOptions = options\n ? JSON.stringify(options, Object.keys(options).sort())\n : '{}';\n return `${localeKey}:${sortedOptions}`;\n }\n\n /**\n * Gets a cached Intl instance or creates a new one if not found\n * @param constructor The name of the Intl constructor to use.\n * @param args Constructor arguments (locales, options).\n * @returns Cached or newly created Intl instance.\n */\n get<K extends keyof CustomIntlConstructors>(\n constructor: K,\n ...args: ConstructorParameters<CustomIntlConstructors[K]>\n ): InstanceType<ConstructorType<K>> {\n const [locales = libraryDefaultLocale, options = {}] = args;\n const key = this._generateKey(locales, options);\n let intlObject = this.cache[constructor]?.[key];\n\n if (intlObject === undefined) {\n // Create new instance and cache it\n intlObject = new CustomIntl[constructor](...args);\n if (!this.cache[constructor]) this.cache[constructor] = {};\n this.cache[constructor][key] = intlObject;\n }\n\n return intlObject;\n }\n}\n\n/**\n * Global instance of the Intl cache for use throughout the application\n */\nexport const intlCache = new IntlCache();\n"],"mappings":";AAAA,MAAa,uBAAuB;AACpC,MAAa,iBAAiB;;;ACD9B,MAAa,iCAAiC,UAC5C,8DAA8D,MAAM;ACGtE,MAAa,yBAAyB;AAEtC,MAAa,iBAGT;CACF,UAAU;EACR,IAAI;GACF,YAAY;GACZ,WAAW;GACZ;EACD,IAAI;GACF,YAAY;GACZ,WAAW,KAAA;GACZ;EACD,IAAI;GACF,YAAY;GACZ,WAAW,KAAA;GACZ;GACA,yBAAyB;GACxB,YAAY;GACZ,WAAW,KAAA;GACZ;EACF;CACD,MAAM,GACH,yBAAyB;EACxB,YAAY,KAAA;EACZ,WAAW,KAAA;EACZ,EACF;CACF;;;ACjBD,IAAa,0BAAb,MAA6D;;;;;;;;;;;;;;;;;;;;;;CAyB3D,YACE,SACA,UAA+B,EAAE,EACjC;AAEA,MAAI;GAEF,MAAM,cAAc,CAAC,UACjB,CAAA,KAAsB,GACtB,MAAM,QAAQ,QAAQ,GACpB,QAAQ,KAAK,MAAM,OAAO,EAAE,CAAC,GAC7B,CAAC,OAAO,QAAQ,CAAC;GACvB,MAAM,mBAAmB,KAAK,oBAAoB,YAAY;AAC9D,QAAK,SAAS,iBAAiB,SAC3B,iBAAiB,KAAA;UAEf;AACN,QAAK,SAAA;;AAIP,MAAI,CAAC,eAAe,QAAQ,SAAA,YAC1B,OAAM,IAAI,MACR,8BACE,QAAQ,SAAA,WACT,CACF;EAIH,IAAI;EACJ,IAAI;AACJ,MAAI,QAAQ,aAAa,KAAA,GAAW;AAClC,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aAA6B;CACjC,UAAU,KAAK;CACf,gBAAgB,KAAK;CACrB,cAAc,KAAK;CACnB,YAAY,KAAK;CACjB,QAAQ,KAAK;CACb,cAAc,KAAK;CACnB,aAAa,KAAK;CAClB,oBAAoB,KAAK;CACzB,WAAW,KAAK;CAChB,cAAc;CACf;;;;;AAMD,IAAM,YAAN,MAAgB;CAGd,cAAc;AACZ,OAAK,QAAQ,EAAE;;;;;;CAOjB,aAAqB,SAA+B,UAAU,EAAE,EAAE;AAYhE,SAAO,GAVW,CAAC,UACf,cACA,MAAM,QAAQ,QAAQ,GACpB,QAAQ,KAAK,MAAM,OAAO,EAAE,CAAC,CAAC,KAAK,IAAI,GACvC,OAAO,QAAQ,CAMD,GAHE,UAClB,KAAK,UAAU,SAAS,OAAO,KAAK,QAAQ,CAAC,MAAM,CAAC,GACpD;;;;;;;;CAUN,IACE,aACA,GAAG,MAC+B;EAClC,MAAM,CAAC,UAAA,MAAgC,UAAU,EAAE,IAAI;EACvD,MAAM,MAAM,KAAK,aAAa,SAAS,QAAQ;EAC/C,IAAI,aAAa,KAAK,MAAM,eAAe;AAE3C,MAAI,eAAe,KAAA,GAAW;AAE5B,gBAAa,IAAI,WAAW,aAAa,GAAG,KAAK;AACjD,OAAI,CAAC,KAAK,MAAM,aAAc,MAAK,MAAM,eAAe,EAAE;AAC1D,QAAK,MAAM,aAAa,OAAO;;AAGjC,SAAO;;;;;;AAOX,MAAa,YAAY,IAAI,WAAW"}
|
|
@@ -34,16 +34,16 @@ const TERMINATOR_MAP = {
|
|
|
34
34
|
var CutoffFormatConstructor = class {
|
|
35
35
|
/**
|
|
36
36
|
* Constructor
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {Intl.LocalesArgument} locales - The locales to use for formatting.
|
|
38
38
|
* @param {CutoffFormatOptions} options - The options for formatting.
|
|
39
|
-
* @param {number} [
|
|
39
|
+
* @param {number} [options.maxChars] - The maximum number of characters to display.
|
|
40
40
|
* - Undefined values are treated as no cutoff.
|
|
41
41
|
* - Negative values follow .slice() behavior and terminator will be added before the value.
|
|
42
42
|
* - 0 will result in an empty string.
|
|
43
43
|
* - If cutoff results in an empty string, no terminator is added.
|
|
44
|
-
* @param {CutoffFormatStyle} [
|
|
45
|
-
* @param {string} [
|
|
46
|
-
* @param {string} [
|
|
44
|
+
* @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
|
|
45
|
+
* @param {string} [options.terminator] - Optional override the terminator to use.
|
|
46
|
+
* @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
|
|
47
47
|
* - If no terminator is provided, then separator is ignored.
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
@@ -154,24 +154,24 @@ const CustomIntl = {
|
|
|
154
154
|
};
|
|
155
155
|
/**
|
|
156
156
|
* Cache for Intl and custom format instances to avoid repeated instantiation
|
|
157
|
-
* Uses a two-level structure: constructor name -> cache key -> instance
|
|
157
|
+
* Uses a two-level structure: constructor name -> cache key -> instance.
|
|
158
158
|
*/
|
|
159
159
|
var IntlCache = class {
|
|
160
160
|
constructor() {
|
|
161
161
|
this.cache = {};
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* Generates a consistent cache key from locales and options
|
|
165
|
-
* Handles all LocalesArgument types (string, Locale, array, undefined)
|
|
164
|
+
* Generates a consistent cache key from locales and options.
|
|
165
|
+
* Handles all LocalesArgument types (string, Locale, array, undefined).
|
|
166
166
|
*/
|
|
167
167
|
_generateKey(locales, options = {}) {
|
|
168
168
|
return `${!locales ? "undefined" : Array.isArray(locales) ? locales.map((l) => String(l)).join(",") : String(locales)}:${options ? JSON.stringify(options, Object.keys(options).sort()) : "{}"}`;
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
171
|
* Gets a cached Intl instance or creates a new one if not found
|
|
172
|
-
* @param constructor The name of the Intl constructor to use
|
|
173
|
-
* @param args Constructor arguments (locales, options)
|
|
174
|
-
* @returns Cached or newly created Intl instance
|
|
172
|
+
* @param constructor The name of the Intl constructor to use.
|
|
173
|
+
* @param args Constructor arguments (locales, options).
|
|
174
|
+
* @returns Cached or newly created Intl instance.
|
|
175
175
|
*/
|
|
176
176
|
get(constructor, ...args) {
|
|
177
177
|
const [locales = "en", options = {}] = args;
|
|
@@ -192,4 +192,4 @@ const intlCache = new IntlCache();
|
|
|
192
192
|
//#endregion
|
|
193
193
|
export { defaultTimeout as n, libraryDefaultLocale as r, intlCache as t };
|
|
194
194
|
|
|
195
|
-
//# sourceMappingURL=IntlCache-
|
|
195
|
+
//# sourceMappingURL=IntlCache-WZk0rKvj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlCache-WZk0rKvj.mjs","names":[],"sources":["../src/settings/settings.ts","../src/errors/formattingErrors.ts","../src/formatting/custom-formats/CutoffFormat/constants.ts","../src/formatting/custom-formats/CutoffFormat/CutoffFormat.ts","../src/cache/IntlCache.ts"],"sourcesContent":["export const libraryDefaultLocale = 'en' as const;\nexport const defaultTimeout = 60000;\n","export const createInvalidCutoffStyleError = (style: string) =>\n `generaltranslation Formatting Error: Invalid cutoff style: ${style}.`;\n","import { CutoffFormatStyle, ResolvedTerminatorOptions } from './types';\n\nexport const DEFAULT_CUTOFF_FORMAT_STYLE: CutoffFormatStyle = 'ellipsis';\n\nexport const DEFAULT_TERMINATOR_KEY = 'DEFAULT_TERMINATOR_KEY';\n\nexport const TERMINATOR_MAP: Record<\n CutoffFormatStyle,\n Record<string | typeof DEFAULT_TERMINATOR_KEY, ResolvedTerminatorOptions>\n> = {\n ellipsis: {\n fr: {\n terminator: '…',\n separator: '\\u202F',\n },\n zh: {\n terminator: '……',\n separator: undefined,\n },\n ja: {\n terminator: '……',\n separator: undefined,\n },\n [DEFAULT_TERMINATOR_KEY]: {\n terminator: '…',\n separator: undefined,\n },\n },\n none: {\n [DEFAULT_TERMINATOR_KEY]: {\n terminator: undefined,\n separator: undefined,\n },\n },\n};\n","import { createInvalidCutoffStyleError } from '../../../errors/formattingErrors';\nimport { libraryDefaultLocale } from '../../../settings/settings';\nimport {\n DEFAULT_CUTOFF_FORMAT_STYLE,\n DEFAULT_TERMINATOR_KEY,\n TERMINATOR_MAP,\n} from './constants';\nimport {\n CutoffFormat,\n CutoffFormatOptions,\n CutoffFormatStyle,\n PostpendedCutoffParts,\n PrependedCutoffParts,\n ResolvedCutoffFormatOptions,\n ResolvedTerminatorOptions,\n} from './types';\n\nexport class CutoffFormatConstructor implements CutoffFormat {\n private locale: string;\n private options: ResolvedCutoffFormatOptions;\n private additionLength: number;\n /**\n * Constructor\n * @param {Intl.LocalesArgument} locales - The locales to use for formatting.\n * @param {CutoffFormatOptions} options - The options for formatting.\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 *\n * @example\n * const format = new CutoffFormat('en', { maxChars: 5 });\n * format.format('Hello, world!'); // 'Hello...'\n *\n * const format = new CutoffFormat('en', { maxChars: -3 });\n * format.format('Hello, world!'); // '...ld!'\n */\n constructor(\n locales: Intl.LocalesArgument,\n options: CutoffFormatOptions = {}\n ) {\n // Determine locale (this replicates Intl.NumberFormat behavior including silent failure)\n try {\n // Normalize locales to string\n const localesList = !locales\n ? [libraryDefaultLocale]\n : Array.isArray(locales)\n ? locales.map((l) => String(l))\n : [String(locales)];\n const canonicalLocales = Intl.getCanonicalLocales(localesList);\n this.locale = canonicalLocales.length\n ? canonicalLocales[0]\n : libraryDefaultLocale;\n } catch {\n this.locale = libraryDefaultLocale;\n }\n\n // Follows Intl.NumberFormat behavior of throwing an error when currency is invalid\n if (!TERMINATOR_MAP[options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE]) {\n throw new Error(\n createInvalidCutoffStyleError(\n options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE\n )\n );\n }\n\n // Resolve terminator options.\n let style: CutoffFormatStyle | undefined;\n let presetTerminatorOptions: ResolvedTerminatorOptions | undefined;\n if (options.maxChars !== undefined) {\n style = options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE;\n // TODO: need more sophisticated locale negotiation if we want to add support for region/script/etc.-specific terminators in the future\n const languageCode = new Intl.Locale(this.locale).language;\n presetTerminatorOptions =\n TERMINATOR_MAP[style][languageCode] ||\n TERMINATOR_MAP[style][DEFAULT_TERMINATOR_KEY];\n }\n let terminator: ResolvedTerminatorOptions['terminator'] =\n options.terminator ?? presetTerminatorOptions?.terminator;\n let separator: ResolvedTerminatorOptions['separator'] =\n terminator != null\n ? (options.separator ?? presetTerminatorOptions?.separator)\n : undefined;\n // // Remove terminator and separator if maxChars does have enough space\n this.additionLength = (terminator?.length ?? 0) + (separator?.length ?? 0);\n if (\n options.maxChars !== undefined &&\n Math.abs(options.maxChars) < this.additionLength\n ) {\n terminator = undefined;\n separator = undefined;\n }\n\n this.options = {\n maxChars: options.maxChars,\n style,\n terminator,\n separator,\n };\n }\n\n /**\n * Format a value according to the cutoff options, returning a formatted string.\n *\n * @param {string} value - The string value to format with cutoff behavior.\n * @returns {string} The formatted string with terminator applied if cutoff occurs.\n *\n * @example\n * const formatter = new CutoffFormatConstructor('en', { maxChars: 8, style: 'ellipsis' });\n * formatter.format('Hello, world!'); // Returns 'Hello, w...'\n */\n format(value: string): string {\n return this.formatToParts(value).join('');\n }\n\n /**\n * Format a value to parts according to the cutoff options, returning an array of string parts.\n * This method breaks down the formatted result into individual components for more granular control.\n *\n * @param {string} value - The string value to format with cutoff behavior.\n * @returns {PrependedCutoffParts | PostpendedCutoffParts} An array of string parts representing the formatted result.\n * - For positive maxChars: [cutoffValue, separator?, terminator?]\n * - For negative maxChars: [terminator?, separator?, cutoffValue]\n * - For no cutoff: [originalValue]\n *\n * @example\n * const formatter = new CutoffFormatConstructor('en', { maxChars: 5, style: 'ellipsis' });\n * formatter.formatToParts('Hello, world!'); // Returns ['Hello', '...']\n */\n formatToParts(value: string): PrependedCutoffParts | PostpendedCutoffParts {\n const { maxChars, terminator, separator } = this.options;\n\n // Slice our value\n // const additionLength = (terminator?.length ?? 0) + (separator?.length ?? 0);\n const adjustedChars =\n maxChars === undefined || Math.abs(maxChars) >= value.length\n ? maxChars\n : maxChars >= 0\n ? Math.max(0, maxChars - this.additionLength)\n : Math.min(0, maxChars + this.additionLength);\n const slicedValue =\n adjustedChars !== undefined && adjustedChars > -1\n ? value.slice(0, adjustedChars)\n : value.slice(adjustedChars);\n\n // No cutoff, no terminator -> value only\n if (\n maxChars == null ||\n adjustedChars == null ||\n adjustedChars === 0 ||\n terminator == null ||\n value.length <= Math.abs(maxChars)\n ) {\n return [slicedValue];\n }\n\n // Postpended cutoff.\n if (adjustedChars > 0) {\n return separator != null\n ? [slicedValue, separator, terminator]\n : [slicedValue, terminator];\n }\n // Prepended cutoff.\n else {\n return separator != null\n ? [terminator, separator, slicedValue]\n : [terminator, slicedValue];\n }\n }\n\n /**\n * Get the resolved options\n * @returns {ResolvedCutoffFormatOptions} The resolved options.\n */\n resolvedOptions(): ResolvedCutoffFormatOptions {\n return this.options;\n }\n}\n","import { libraryDefaultLocale } from '../settings/settings';\nimport { CutoffFormatConstructor } from '../formatting/custom-formats/CutoffFormat/CutoffFormat';\nimport {\n ConstructorType,\n CustomIntlConstructors,\n CustomIntlType,\n IntlCacheObject,\n} from './types';\n\n/**\n * Object mapping constructor names to their respective constructor functions\n * Includes all native Intl constructors plus custom ones like CutoffFormat\n */\nconst CustomIntl: CustomIntlType = {\n Collator: Intl.Collator,\n DateTimeFormat: Intl.DateTimeFormat,\n DisplayNames: Intl.DisplayNames,\n ListFormat: Intl.ListFormat,\n Locale: Intl.Locale,\n NumberFormat: Intl.NumberFormat,\n PluralRules: Intl.PluralRules,\n RelativeTimeFormat: Intl.RelativeTimeFormat,\n Segmenter: Intl.Segmenter,\n CutoffFormat: CutoffFormatConstructor,\n};\n\n/**\n * Cache for Intl and custom format instances to avoid repeated instantiation\n * Uses a two-level structure: constructor name -> cache key -> instance.\n */\nclass IntlCache {\n private cache: IntlCacheObject;\n\n constructor() {\n this.cache = {};\n }\n\n /**\n * Generates a consistent cache key from locales and options.\n * Handles all LocalesArgument types (string, Locale, array, undefined).\n */\n private _generateKey(locales: Intl.LocalesArgument, options = {}) {\n // Normalize locales to string representation\n const localeKey = !locales\n ? 'undefined'\n : Array.isArray(locales)\n ? locales.map((l) => String(l)).join(',')\n : String(locales);\n\n // Sort option keys to ensure consistent key generation regardless of property order\n const sortedOptions = options\n ? JSON.stringify(options, Object.keys(options).sort())\n : '{}';\n return `${localeKey}:${sortedOptions}`;\n }\n\n /**\n * Gets a cached Intl instance or creates a new one if not found\n * @param constructor The name of the Intl constructor to use.\n * @param args Constructor arguments (locales, options).\n * @returns Cached or newly created Intl instance.\n */\n get<K extends keyof CustomIntlConstructors>(\n constructor: K,\n ...args: ConstructorParameters<CustomIntlConstructors[K]>\n ): InstanceType<ConstructorType<K>> {\n const [locales = libraryDefaultLocale, options = {}] = args;\n const key = this._generateKey(locales, options);\n let intlObject = this.cache[constructor]?.[key];\n\n if (intlObject === undefined) {\n // Create new instance and cache it\n intlObject = new CustomIntl[constructor](...args);\n if (!this.cache[constructor]) this.cache[constructor] = {};\n this.cache[constructor][key] = intlObject;\n }\n\n return intlObject;\n }\n}\n\n/**\n * Global instance of the Intl cache for use throughout the application\n */\nexport const intlCache = new IntlCache();\n"],"mappings":";AAAA,MAAa,uBAAuB;AACpC,MAAa,iBAAiB;;;ACD9B,MAAa,iCAAiC,UAC5C,8DAA8D,MAAM;ACGtE,MAAa,yBAAyB;AAEtC,MAAa,iBAGT;CACF,UAAU;EACR,IAAI;GACF,YAAY;GACZ,WAAW;GACZ;EACD,IAAI;GACF,YAAY;GACZ,WAAW,KAAA;GACZ;EACD,IAAI;GACF,YAA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B;EAClC,MAAM,CAAC,UAAA,MAAgC,UAAU,EAAE,IAAI;EACvD,MAAM,MAAM,KAAK,aAAa,SAAS,QAAQ;EAC/C,IAAI,aAAa,KAAK,MAAM,eAAe;AAE3C,MAAI,eAAe,KAAA,GAAW;AAE5B,gBAAa,IAAI,WAAW,aAAa,GAAG,KAAK;AACjD,OAAI,CAAC,KAAK,MAAM,aAAc,MAAK,MAAM,eAAe,EAAE;AAC1D,QAAK,MAAM,aAAa,OAAO;;AAGjC,SAAO;;;;;;AAOX,MAAa,YAAY,IAAI,WAAW"}
|
|
@@ -20,8 +20,8 @@ const SUPPORTED_TRANSFORMATIONS = {
|
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* This function checks if a file format transformation is supported during translation
|
|
23
|
-
* @param from - The source file format
|
|
24
|
-
* @param to - The target file format
|
|
23
|
+
* @param from - The source file format.
|
|
24
|
+
* @param to - The target file format.
|
|
25
25
|
* @returns True if the transformation is supported, false otherwise
|
|
26
26
|
*/
|
|
27
27
|
function isSupportedFileFormatTransform(from, to) {
|
|
@@ -108,4 +108,4 @@ Object.defineProperty(exports, "validateFileFormatTransforms", {
|
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
//# sourceMappingURL=base64-
|
|
111
|
+
//# sourceMappingURL=base64-2fu94Klt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-2fu94Klt.cjs","names":[],"sources":["../src/settings/settingsUrls.ts","../src/utils/isSupportedFileFormatTransform.ts","../src/translate/utils/validateFileFormatTransform.ts","../src/utils/base64.ts"],"sourcesContent":["export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api2.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://runtime2.gtx.dev' as const;\n","import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","import type { FileFormat } from '../../types-dir/api/file';\nimport { isSupportedFileFormatTransform } from '../../utils/isSupportedFileFormatTransform';\n\nexport type FileFormatTransformInput = {\n fileFormat?: FileFormat;\n transformFormat?: FileFormat;\n fileName?: string;\n fileId?: string;\n};\n\n/**\n * Returns a user-facing validation error when a requested file format transform\n * is missing source format context or is not currently supported.\n */\nexport function getFileFormatTransformError(\n file: FileFormatTransformInput\n): string | undefined {\n if (!file.transformFormat) return undefined;\n const fileLabel = file.fileName ?? file.fileId ?? 'unknown file';\n if (!file.fileFormat) {\n return `fileFormat is required when transformFormat is provided for ${fileLabel}`;\n }\n if (!isSupportedFileFormatTransform(file.fileFormat, file.transformFormat)) {\n return `Unsupported file format transform: ${file.fileFormat} -> ${file.transformFormat}`;\n }\n return undefined;\n}\n\n/**\n * Validates file format transforms before sending upload/enqueue requests.\n */\nexport function validateFileFormatTransforms(\n files: FileFormatTransformInput[]\n): void {\n for (const file of files) {\n const error = getFileFormatTransformError(file);\n if (error) throw new Error(error);\n }\n}\n","// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n"],"mappings":";AAAA,MAAa,kBAAkB;AAC/B,MAAa,iBAAiB;AAC9B,MAAa,uBAAuB;;;ACApC,MAAM,4BAA4B;CAChC,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,OAAO;CACd,IAAI,CAAC,KAAK;CAEV,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,qBAAqB,CAAC,sBAAsB;CAC7C;;;;;;;AAQD,SAAgB,+BACd,MACA,IACS;AAET,QAD4C,0BAA0B,OACpD,SAAS,GAAG,IAAI;;;;;;;;ACfpC,SAAgB,4BACd,MACoB;AACpB,KAAI,CAAC,KAAK,gBAAiB,QAAO,KAAA;CAClC,MAAM,YAAY,KAAK,YAAY,KAAK,UAAU;AAClD,KAAI,CAAC,KAAK,WACR,QAAO,+DAA+D;AAExE,KAAI,CAAC,+BAA+B,KAAK,YAAY,KAAK,gBAAgB,CACxE,QAAO,sCAAsC,KAAK,WAAW,MAAM,KAAK;;;;;AAQ5E,SAAgB,6BACd,OACM;AACN,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,4BAA4B,KAAK;AAC/C,MAAI,MAAO,OAAM,IAAI,MAAM,MAAM;;;;;ACnCrC,SAAgB,OAAO,MAAsB;AAC3C,KAAI,OAAO,WAAW,YAEpB,QAAO,OAAO,KAAK,MAAM,OAAO,CAAC,SAAS,SAAS;CAGrD,MAAM,QAAQ,IAAI,aAAa,CAAC,OAAO,KAAK;CAC5C,IAAI,SAAS;AACb,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,WAAU,OAAO,aAAa,MAAM,GAAG;AAEzC,QAAO,KAAK,OAAO;;AAIrB,SAAgB,OAAO,QAAwB;AAC7C,KAAI,OAAO,WAAW,YAEpB,QAAO,OAAO,KAAK,QAAQ,SAAS,CAAC,SAAS,OAAO;CAGvD,MAAM,SAAS,KAAK,OAAO;CAC3B,MAAM,QAAQ,IAAI,WAAW,OAAO,OAAO;AAC3C,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,OAAM,KAAK,OAAO,WAAW,EAAE;AAEjC,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM"}
|
|
@@ -20,8 +20,8 @@ const SUPPORTED_TRANSFORMATIONS = {
|
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* This function checks if a file format transformation is supported during translation
|
|
23
|
-
* @param from - The source file format
|
|
24
|
-
* @param to - The target file format
|
|
23
|
+
* @param from - The source file format.
|
|
24
|
+
* @param to - The target file format.
|
|
25
25
|
* @returns True if the transformation is supported, false otherwise
|
|
26
26
|
*/
|
|
27
27
|
function isSupportedFileFormatTransform(from, to) {
|
|
@@ -67,4 +67,4 @@ function decode(base64) {
|
|
|
67
67
|
//#endregion
|
|
68
68
|
export { defaultBaseUrl as a, isSupportedFileFormatTransform as i, encode as n, defaultCacheUrl as o, validateFileFormatTransforms as r, defaultRuntimeApiUrl as s, decode as t };
|
|
69
69
|
|
|
70
|
-
//# sourceMappingURL=base64-
|
|
70
|
+
//# sourceMappingURL=base64-DH0STixb.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-DH0STixb.mjs","names":[],"sources":["../src/settings/settingsUrls.ts","../src/utils/isSupportedFileFormatTransform.ts","../src/translate/utils/validateFileFormatTransform.ts","../src/utils/base64.ts"],"sourcesContent":["export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api2.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://runtime2.gtx.dev' as const;\n","import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","import type { FileFormat } from '../../types-dir/api/file';\nimport { isSupportedFileFormatTransform } from '../../utils/isSupportedFileFormatTransform';\n\nexport type FileFormatTransformInput = {\n fileFormat?: FileFormat;\n transformFormat?: FileFormat;\n fileName?: string;\n fileId?: string;\n};\n\n/**\n * Returns a user-facing validation error when a requested file format transform\n * is missing source format context or is not currently supported.\n */\nexport function getFileFormatTransformError(\n file: FileFormatTransformInput\n): string | undefined {\n if (!file.transformFormat) return undefined;\n const fileLabel = file.fileName ?? file.fileId ?? 'unknown file';\n if (!file.fileFormat) {\n return `fileFormat is required when transformFormat is provided for ${fileLabel}`;\n }\n if (!isSupportedFileFormatTransform(file.fileFormat, file.transformFormat)) {\n return `Unsupported file format transform: ${file.fileFormat} -> ${file.transformFormat}`;\n }\n return undefined;\n}\n\n/**\n * Validates file format transforms before sending upload/enqueue requests.\n */\nexport function validateFileFormatTransforms(\n files: FileFormatTransformInput[]\n): void {\n for (const file of files) {\n const error = getFileFormatTransformError(file);\n if (error) throw new Error(error);\n }\n}\n","// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n"],"mappings":";AAAA,MAAa,kBAAkB;AAC/B,MAAa,iBAAiB;AAC9B,MAAa,uBAAuB;;;ACApC,MAAM,4BAA4B;CAChC,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,OAAO;CACd,IAAI,CAAC,KAAK;CAEV,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,qBAAqB,CAAC,sBAAsB;CAC7C;;;;;;;AAQD,SAAgB,+BACd,MACA,IACS;AAET,QAD4C,0BAA0B,OACpD,SAAS,GAAG,IAAI;;;;;;;;ACfpC,SAAgB,4BACd,MACoB;AACpB,KAAI,CAAC,KAAK,gBAAiB,QAAO,KAAA;CAClC,MAAM,YAAY,KAAK,YAAY,KAAK,UAAU;AAClD,KAAI,CAAC,KAAK,WACR,QAAO,+DAA+D;AAExE,KAAI,CAAC,+BAA+B,KAAK,YAAY,KAAK,gBAAgB,CACxE,QAAO,sCAAsC,KAAK,WAAW,MAAM,KAAK;;;;;AAQ5E,SAAgB,6BACd,OACM;AACN,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,4BAA4B,KAAK;AAC/C,MAAI,MAAO,OAAM,IAAI,MAAM,MAAM;;;;;ACnCrC,SAAgB,OAAO,MAAsB;AAC3C,KAAI,OAAO,WAAW,YAEpB,QAAO,OAAO,KAAK,MAAM,OAAO,CAAC,SAAS,SAAS;CAGrD,MAAM,QAAQ,IAAI,aAAa,CAAC,OAAO,KAAK;CAC5C,IAAI,SAAS;AACb,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,WAAU,OAAO,aAAa,MAAM,GAAG;AAEzC,QAAO,KAAK,OAAO;;AAIrB,SAAgB,OAAO,QAAwB;AAC7C,KAAI,OAAO,WAAW,YAEpB,QAAO,OAAO,KAAK,QAAQ,SAAS,CAAC,SAAS,OAAO;CAGvD,MAAM,SAAS,KAAK,OAAO;CAC3B,MAAM,QAAQ,IAAI,WAAW,OAAO,OAAO;AAC3C,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,OAAM,KAAK,OAAO,WAAW,EAAE;AAEjC,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as intlCache } from "./IntlCache-
|
|
1
|
+
import { t as intlCache } from "./IntlCache-WZk0rKvj.mjs";
|
|
2
2
|
import { IntlMessageFormat } from "intl-messageformat";
|
|
3
3
|
//#region src/locales/isValidLocale.ts
|
|
4
4
|
const scriptExceptions = [
|
|
@@ -44,7 +44,7 @@ const _isValidLocale = (locale, customMapping) => {
|
|
|
44
44
|
/**
|
|
45
45
|
* Standardizes a BCP 47 locale to ensure correct formatting.
|
|
46
46
|
* @param {string} locale - The BCP 47 locale to standardize.
|
|
47
|
-
* @returns {string} The standardized BCP 47 locale, or
|
|
47
|
+
* @returns {string} The standardized BCP 47 locale, or the input string if it cannot be standardized.
|
|
48
48
|
* @internal
|
|
49
49
|
*/
|
|
50
50
|
const _standardizeLocale = (locale) => {
|
|
@@ -686,7 +686,7 @@ var ConsoleLogHandler = class {
|
|
|
686
686
|
}
|
|
687
687
|
};
|
|
688
688
|
/**
|
|
689
|
-
* Main Logger class providing structured logging capabilities
|
|
689
|
+
* Main Logger class providing structured logging capabilities.
|
|
690
690
|
*/
|
|
691
691
|
var Logger = class {
|
|
692
692
|
constructor(config = {}) {
|
|
@@ -758,7 +758,7 @@ var Logger = class {
|
|
|
758
758
|
}
|
|
759
759
|
/**
|
|
760
760
|
* Log an info message
|
|
761
|
-
* Used for general information about application operation
|
|
761
|
+
* Used for general information about application operation.
|
|
762
762
|
*/
|
|
763
763
|
info(message, context, metadata) {
|
|
764
764
|
this.log("info", message, context, metadata);
|
|
@@ -772,7 +772,7 @@ var Logger = class {
|
|
|
772
772
|
}
|
|
773
773
|
/**
|
|
774
774
|
* Log an error message
|
|
775
|
-
* Used for error events that might still allow the application to continue
|
|
775
|
+
* Used for error events that might still allow the application to continue.
|
|
776
776
|
*/
|
|
777
777
|
error(message, context, metadata) {
|
|
778
778
|
this.log("error", message, context, metadata);
|
|
@@ -791,7 +791,7 @@ var Logger = class {
|
|
|
791
791
|
}
|
|
792
792
|
};
|
|
793
793
|
/**
|
|
794
|
-
* Context logger that automatically includes context information
|
|
794
|
+
* Context logger that automatically includes context information.
|
|
795
795
|
*/
|
|
796
796
|
var ContextLogger = class ContextLogger {
|
|
797
797
|
constructor(logger, context) {
|
|
@@ -844,8 +844,6 @@ const gtInstanceLogger = defaultLogger.child("GT instance");
|
|
|
844
844
|
*
|
|
845
845
|
* @example
|
|
846
846
|
* _formatCutoff({ value: 'Hello, world!', options: { maxChars: 8 } }); // Returns 'Hello, w...'
|
|
847
|
-
*
|
|
848
|
-
* Will fallback to an empty string if formatting fails.
|
|
849
847
|
*/
|
|
850
848
|
function _formatCutoff({ value, locales = "en", options = {} }) {
|
|
851
849
|
return intlCache.get("CutoffFormat", locales, options).format(value);
|
|
@@ -859,8 +857,8 @@ function _formatCutoff({ value, locales = "en", options = {} }) {
|
|
|
859
857
|
* @returns {string} The formatted message.
|
|
860
858
|
* @internal
|
|
861
859
|
*
|
|
862
|
-
*
|
|
863
|
-
* TODO:
|
|
860
|
+
* Returns an empty string if IntlMessageFormat produces no output.
|
|
861
|
+
* TODO: Add this to custom formats.
|
|
864
862
|
*/
|
|
865
863
|
function _formatMessageICU(message, locales = "en", variables = {}) {
|
|
866
864
|
return new IntlMessageFormat(message, locales).format(variables)?.toString() ?? "";
|
|
@@ -872,7 +870,7 @@ function _formatMessageICU(message, locales = "en", variables = {}) {
|
|
|
872
870
|
* @returns {string} The original message, unchanged.
|
|
873
871
|
* @internal
|
|
874
872
|
*
|
|
875
|
-
* TODO:
|
|
873
|
+
* TODO: Add this to custom formats.
|
|
876
874
|
*/
|
|
877
875
|
function _formatMessageString(message) {
|
|
878
876
|
return message;
|
|
@@ -1100,7 +1098,7 @@ function _getLocaleName(locale, defaultLocale = "en", customMapping) {
|
|
|
1100
1098
|
* Get the text direction for a given locale code using the Intl.Locale API.
|
|
1101
1099
|
*
|
|
1102
1100
|
* @param {string} code - The locale code to check.
|
|
1103
|
-
* @returns {string}
|
|
1101
|
+
* @returns {string} 'rtl' if the language is right-to-left; otherwise 'ltr'.
|
|
1104
1102
|
* @internal
|
|
1105
1103
|
*/
|
|
1106
1104
|
function _getLocaleDirection(code) {
|
|
@@ -1145,7 +1143,7 @@ const RTL_LANGUAGES = new Set([
|
|
|
1145
1143
|
]);
|
|
1146
1144
|
/**
|
|
1147
1145
|
* Handles extracting direction via textInfo property
|
|
1148
|
-
* @param
|
|
1146
|
+
* @param locale - Intl.Locale object.
|
|
1149
1147
|
* @returns {'ltr' | 'rtl'} - The direction of the locale
|
|
1150
1148
|
*
|
|
1151
1149
|
* Intl.Locale.prototype.getTextInfo() / textInfo property incorporated in ES2024 Specification.
|
|
@@ -1185,7 +1183,7 @@ function _isSupersetLocale(superLocale, subLocale) {
|
|
|
1185
1183
|
* Resolves the alias locale for a given locale.
|
|
1186
1184
|
* @param locale - The locale to resolve the alias locale for
|
|
1187
1185
|
* @param customMapping - The custom mapping to use for resolving the alias locale
|
|
1188
|
-
* @returns The alias locale
|
|
1186
|
+
* @returns The configured alias for a canonical locale, or the input locale when already an alias or no alias mapping exists.
|
|
1189
1187
|
*/
|
|
1190
1188
|
function _resolveAliasLocale(locale, customMapping) {
|
|
1191
1189
|
let reverseCustomMapping;
|
|
@@ -1198,7 +1196,7 @@ function _resolveAliasLocale(locale, customMapping) {
|
|
|
1198
1196
|
* Resolves the canonical locale for a given locale.
|
|
1199
1197
|
* @param locale - The locale to resolve the canonical locale for
|
|
1200
1198
|
* @param customMapping - The custom mapping to use for resolving the canonical locale
|
|
1201
|
-
* @returns The canonical locale
|
|
1199
|
+
* @returns The canonical locale, or the input locale when no canonical mapping exists.
|
|
1202
1200
|
*/
|
|
1203
1201
|
function _resolveCanonicalLocale(locale, customMapping) {
|
|
1204
1202
|
if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) return customMapping[locale].code;
|
|
@@ -1464,7 +1462,7 @@ function isValidLocale(locale, customMapping) {
|
|
|
1464
1462
|
*
|
|
1465
1463
|
* @param {string} locale - The locale to resolve the canonical locale for.
|
|
1466
1464
|
* @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale.
|
|
1467
|
-
* @returns {string} The canonical locale.
|
|
1465
|
+
* @returns {string} The canonical locale, or the input locale when no canonical mapping exists.
|
|
1468
1466
|
*
|
|
1469
1467
|
* @example
|
|
1470
1468
|
* resolveCanonicalLocale('en-US');
|
|
@@ -1481,7 +1479,7 @@ function resolveCanonicalLocale(locale, customMapping) {
|
|
|
1481
1479
|
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
|
1482
1480
|
*
|
|
1483
1481
|
* @param {string} locale - The BCP 47 locale code to standardize.
|
|
1484
|
-
* @returns {string} The standardized BCP 47 locale code or
|
|
1482
|
+
* @returns {string} The standardized BCP 47 locale code, or the input string if it cannot be standardized.
|
|
1485
1483
|
*
|
|
1486
1484
|
* @example
|
|
1487
1485
|
* standardizeLocale('en-us');
|
|
@@ -1489,7 +1487,7 @@ function resolveCanonicalLocale(locale, customMapping) {
|
|
|
1489
1487
|
*
|
|
1490
1488
|
* @example
|
|
1491
1489
|
* standardizeLocale('not a locale');
|
|
1492
|
-
* // Returns: ''
|
|
1490
|
+
* // Returns: 'not a locale'
|
|
1493
1491
|
*/
|
|
1494
1492
|
function standardizeLocale(locale) {
|
|
1495
1493
|
return _standardizeLocale(locale);
|
|
@@ -1497,4 +1495,4 @@ function standardizeLocale(locale) {
|
|
|
1497
1495
|
//#endregion
|
|
1498
1496
|
export { _standardizeLocale as A, _getLocaleEmoji as C, _isSameLanguage as D, _requiresTranslation as E, _isSameDialect as O, _getLocaleProperties as S, getRegionEmoji as T, _formatRelativeTime as _, standardizeLocale as a, gtInstanceLogger as b, _resolveAliasLocale as c, _getLocaleName as d, _formatCurrency as f, _formatNum as g, _formatListToParts as h, resolveCanonicalLocale as i, _isValidLocale as k, _isSupersetLocale as l, _formatList as m, formatMessage as n, LocaleConfig as o, _formatDateTime as p, isValidLocale as r, _resolveCanonicalLocale as s, formatCutoff as t, _getLocaleDirection as u, _formatRelativeTimeFromDate as v, defaultEmoji as w, _determineLocale as x, fetchLogger as y };
|
|
1499
1497
|
|
|
1500
|
-
//# sourceMappingURL=core-
|
|
1498
|
+
//# sourceMappingURL=core-7RJsqw6c.mjs.map
|