generaltranslation 8.2.7 → 8.2.9
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 +12 -0
- package/dist/{ApiError-4zIP-twr.cjs → ApiError-CZ45tkW6.cjs} +1 -1
- package/dist/{ApiError-4zIP-twr.cjs.map → ApiError-CZ45tkW6.cjs.map} +1 -1
- package/dist/{ApiError-Bv7vlzyQ.mjs → ApiError-IYfaOR30.mjs} +1 -1
- package/dist/{ApiError-Bv7vlzyQ.mjs.map → ApiError-IYfaOR30.mjs.map} +1 -1
- package/dist/IntlCache-Ccg_cQPR.mjs +195 -0
- package/dist/IntlCache-Ccg_cQPR.mjs.map +1 -0
- package/dist/IntlCache-k2qfrDqB.cjs +212 -0
- package/dist/IntlCache-k2qfrDqB.cjs.map +1 -0
- package/dist/base64-C1sogiix.mjs +70 -0
- package/dist/base64-C1sogiix.mjs.map +1 -0
- package/dist/base64-CUcEPEC5.cjs +111 -0
- package/dist/base64-CUcEPEC5.cjs.map +1 -0
- package/dist/core-CJMv4fMa.d.cts +209 -0
- package/dist/core-DOrYXXpO.mjs +1487 -0
- package/dist/core-DOrYXXpO.mjs.map +1 -0
- package/dist/core-DtPj_ruw.d.mts +209 -0
- package/dist/core-LS3Pia40.cjs +1666 -0
- package/dist/core-LS3Pia40.cjs.map +1 -0
- package/dist/core.cjs +8 -0
- package/dist/core.d.cts +2 -0
- package/dist/core.d.mts +2 -0
- package/dist/core.mjs +2 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{id-CPbVYREY.mjs → id-BmOyfaug.mjs} +2 -2
- package/dist/{id-CPbVYREY.mjs.map → id-BmOyfaug.mjs.map} +1 -1
- package/dist/{id-VXBgyXu2.cjs → id-COlX5v3V.cjs} +6 -6
- package/dist/{id-VXBgyXu2.cjs.map → id-COlX5v3V.cjs.map} +1 -1
- 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 +91 -1413
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -103
- package/dist/index.d.mts +7 -103
- package/dist/index.mjs +43 -1342
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +602 -42
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +23 -2
- package/dist/internal.d.mts +23 -2
- package/dist/internal.mjs +563 -3
- package/dist/internal.mjs.map +1 -0
- package/dist/{sha2-DKowBr6H.cjs → isVariable-B08mggBy.cjs} +18 -18
- package/dist/isVariable-B08mggBy.cjs.map +1 -0
- package/dist/{stableStringify-DgDlE_pD.mjs → isVariable-CYsKFHvR.mjs} +19 -19
- package/dist/isVariable-CYsKFHvR.mjs.map +1 -0
- package/dist/{types-fUW4_Ole.d.mts → types-Dfy_sRLD.d.mts} +6 -2
- package/dist/{types-D2fTTTvZ.d.cts → types-mZeu4HS3.d.cts} +6 -2
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +17 -1
- package/dist/internal-CTeI8uLd.mjs +0 -774
- package/dist/internal-CTeI8uLd.mjs.map +0 -1
- package/dist/internal-PCKq4YMW.cjs +0 -1012
- package/dist/internal-PCKq4YMW.cjs.map +0 -1
- package/dist/sha2-DKowBr6H.cjs.map +0 -1
- package/dist/stableStringify-DgDlE_pD.mjs.map +0 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//#region src/settings/settingsUrls.ts
|
|
2
|
+
const defaultCacheUrl = "https://cdn.gtx.dev";
|
|
3
|
+
const defaultBaseUrl = "https://api2.gtx.dev";
|
|
4
|
+
const defaultRuntimeApiUrl = "https://runtime2.gtx.dev";
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/utils/isSupportedFileFormatTransform.ts
|
|
7
|
+
const SUPPORTED_TRANSFORMATIONS = {
|
|
8
|
+
GTJSON: ["GTJSON"],
|
|
9
|
+
JSON: ["JSON"],
|
|
10
|
+
PO: ["PO"],
|
|
11
|
+
POT: ["POT", "PO"],
|
|
12
|
+
YAML: ["YAML"],
|
|
13
|
+
MDX: ["MDX"],
|
|
14
|
+
MD: ["MD"],
|
|
15
|
+
TS: ["TS"],
|
|
16
|
+
JS: ["JS"],
|
|
17
|
+
HTML: ["HTML"],
|
|
18
|
+
TXT: ["TXT"],
|
|
19
|
+
TWILIO_CONTENT_JSON: ["TWILIO_CONTENT_JSON"]
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
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
|
|
25
|
+
* @returns True if the transformation is supported, false otherwise
|
|
26
|
+
*/
|
|
27
|
+
function isSupportedFileFormatTransform(from, to) {
|
|
28
|
+
return SUPPORTED_TRANSFORMATIONS[from]?.includes(to) ?? false;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/translate/utils/validateFileFormatTransform.ts
|
|
32
|
+
/**
|
|
33
|
+
* Returns a user-facing validation error when a requested file format transform
|
|
34
|
+
* is missing source format context or is not currently supported.
|
|
35
|
+
*/
|
|
36
|
+
function getFileFormatTransformError(file) {
|
|
37
|
+
if (!file.transformFormat) return void 0;
|
|
38
|
+
const fileLabel = file.fileName ?? file.fileId ?? "unknown file";
|
|
39
|
+
if (!file.fileFormat) return `fileFormat is required when transformFormat is provided for ${fileLabel}`;
|
|
40
|
+
if (!isSupportedFileFormatTransform(file.fileFormat, file.transformFormat)) return `Unsupported file format transform: ${file.fileFormat} -> ${file.transformFormat}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates file format transforms before sending upload/enqueue requests.
|
|
44
|
+
*/
|
|
45
|
+
function validateFileFormatTransforms(files) {
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
const error = getFileFormatTransformError(file);
|
|
48
|
+
if (error) throw new Error(error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/utils/base64.ts
|
|
53
|
+
function encode(data) {
|
|
54
|
+
if (typeof Buffer !== "undefined") return Buffer.from(data, "utf8").toString("base64");
|
|
55
|
+
const bytes = new TextEncoder().encode(data);
|
|
56
|
+
let binary = "";
|
|
57
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
58
|
+
return btoa(binary);
|
|
59
|
+
}
|
|
60
|
+
function decode(base64) {
|
|
61
|
+
if (typeof Buffer !== "undefined") return Buffer.from(base64, "base64").toString("utf8");
|
|
62
|
+
const binary = atob(base64);
|
|
63
|
+
const bytes = new Uint8Array(binary.length);
|
|
64
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
65
|
+
return new TextDecoder().decode(bytes);
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
Object.defineProperty(exports, "decode", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function() {
|
|
71
|
+
return decode;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(exports, "defaultBaseUrl", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function() {
|
|
77
|
+
return defaultBaseUrl;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "defaultCacheUrl", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function() {
|
|
83
|
+
return defaultCacheUrl;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, "defaultRuntimeApiUrl", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function() {
|
|
89
|
+
return defaultRuntimeApiUrl;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, "encode", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function() {
|
|
95
|
+
return encode;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, "isSupportedFileFormatTransform", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return isSupportedFileFormatTransform;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "validateFileFormatTransforms", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function() {
|
|
107
|
+
return validateFileFormatTransforms;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=base64-CUcEPEC5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-CUcEPEC5.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"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { Dt as StringFormat, Mt as CustomMapping, jt as LocaleProperties, n as FormatVariables } from "./types-mZeu4HS3.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/formatting/custom-formats/CutoffFormat/types.d.ts
|
|
4
|
+
/** Type of terminator */
|
|
5
|
+
type CutoffFormatStyle = 'none' | 'ellipsis';
|
|
6
|
+
/** Terminator options */
|
|
7
|
+
interface TerminatorOptions {
|
|
8
|
+
/** The terminator to use */
|
|
9
|
+
terminator?: string;
|
|
10
|
+
/** An optional separator between the terminator and the value */
|
|
11
|
+
separator?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Input formatting options (for constructor) */
|
|
14
|
+
interface CutoffFormatOptions extends TerminatorOptions {
|
|
15
|
+
/** Cutoff length */
|
|
16
|
+
maxChars?: number;
|
|
17
|
+
/** Type of terminator */
|
|
18
|
+
style?: CutoffFormatStyle;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/LocaleConfig.d.ts
|
|
22
|
+
type LocaleConfigConstructorParams = {
|
|
23
|
+
defaultLocale?: string;
|
|
24
|
+
locales?: string[];
|
|
25
|
+
customMapping?: CustomMapping;
|
|
26
|
+
};
|
|
27
|
+
type LocalesOption = {
|
|
28
|
+
locales?: string | string[];
|
|
29
|
+
};
|
|
30
|
+
type WithLocales<T = object> = T & LocalesOption;
|
|
31
|
+
/**
|
|
32
|
+
* LocaleConfig contains the locale and formatting primitives exposed through
|
|
33
|
+
* the core entrypoint.
|
|
34
|
+
*
|
|
35
|
+
* It intentionally does not store project IDs, API keys, runtime URLs, or any
|
|
36
|
+
* translation credentials. It only stores locale metadata needed to resolve
|
|
37
|
+
* aliases, choose formatting fallbacks, and format values with Intl.
|
|
38
|
+
*/
|
|
39
|
+
declare class LocaleConfig {
|
|
40
|
+
readonly defaultLocale: string;
|
|
41
|
+
readonly locales: string[];
|
|
42
|
+
readonly customMapping?: CustomMapping;
|
|
43
|
+
constructor({
|
|
44
|
+
defaultLocale,
|
|
45
|
+
locales,
|
|
46
|
+
customMapping
|
|
47
|
+
}?: LocaleConfigConstructorParams);
|
|
48
|
+
private get translationLocales();
|
|
49
|
+
private resolveCanonicalLocaleList;
|
|
50
|
+
private resolveCanonicalLocaleArgs;
|
|
51
|
+
private toLocaleList;
|
|
52
|
+
private getFormattingLocales;
|
|
53
|
+
formatNum(value: number, targetLocale?: string, options?: WithLocales<Intl.NumberFormatOptions>): string;
|
|
54
|
+
formatDateTime(value: Date, targetLocale?: string, options?: WithLocales<Intl.DateTimeFormatOptions>): string;
|
|
55
|
+
formatCurrency(value: number, currency: string, targetLocale?: string, options?: WithLocales<Intl.NumberFormatOptions>): string;
|
|
56
|
+
formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, targetLocale?: string, options?: WithLocales<Intl.RelativeTimeFormatOptions>): string;
|
|
57
|
+
formatRelativeTimeFromDate(date: Date, targetLocale?: string, options?: WithLocales<Intl.RelativeTimeFormatOptions & {
|
|
58
|
+
baseDate?: Date;
|
|
59
|
+
}>): string;
|
|
60
|
+
formatCutoff(value: string, targetLocale?: string, options?: WithLocales<CutoffFormatOptions>): string;
|
|
61
|
+
formatMessage(message: string, targetLocale?: string, options?: WithLocales<{
|
|
62
|
+
variables?: FormatVariables;
|
|
63
|
+
dataFormat?: StringFormat;
|
|
64
|
+
}>): string;
|
|
65
|
+
formatList(array: Array<string | number>, targetLocale?: string, options?: WithLocales<Intl.ListFormatOptions>): string;
|
|
66
|
+
formatListToParts<T>(array: Array<T>, targetLocale?: string, options?: WithLocales<Intl.ListFormatOptions>): (string | T)[];
|
|
67
|
+
getLocaleName(locale: string): string;
|
|
68
|
+
getLocaleEmoji(locale: string): string;
|
|
69
|
+
getLocaleProperties(locale: string): LocaleProperties;
|
|
70
|
+
requiresTranslation(targetLocale: string, sourceLocale?: string, approvedLocales?: string[] | undefined): boolean;
|
|
71
|
+
determineLocale(locales: string | string[], approvedLocales?: string[]): string | undefined;
|
|
72
|
+
getLocaleDirection(locale: string): "ltr" | "rtl";
|
|
73
|
+
isValidLocale(locale: string): boolean;
|
|
74
|
+
resolveCanonicalLocale(locale: string): string;
|
|
75
|
+
resolveAliasLocale(locale: string): string;
|
|
76
|
+
standardizeLocale(locale: string): string;
|
|
77
|
+
isSameDialect(...locales: (string | string[])[]): boolean;
|
|
78
|
+
isSameLanguage(...locales: (string | string[])[]): boolean;
|
|
79
|
+
isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/core.d.ts
|
|
83
|
+
/**
|
|
84
|
+
* Core formatting and locale helpers.
|
|
85
|
+
*
|
|
86
|
+
* This entry point exposes deterministic locale and formatting primitives. It
|
|
87
|
+
* does not export the GT service client, project credentials, network
|
|
88
|
+
* translation methods, file APIs, or other server/service concerns from the
|
|
89
|
+
* root `generaltranslation` facade.
|
|
90
|
+
*
|
|
91
|
+
* This entry point is intended for framework and shared packages that need
|
|
92
|
+
* locale metadata or formatting behavior without pulling in the full
|
|
93
|
+
* translation API surface.
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
|
|
97
|
+
*
|
|
98
|
+
* This standalone function provides cutoff formatting functionality without requiring a GT instance.
|
|
99
|
+
* The locales parameter is required for proper terminator selection based on the target language.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} value - The string value to format with cutoff behavior.
|
|
102
|
+
* @param {Object} [options] - Configuration options for cutoff formatting.
|
|
103
|
+
* @param {string | string[]} [options.locales] - The locales to use for terminator selection.
|
|
104
|
+
* @param {number} [options.maxChars] - The maximum number of characters to display.
|
|
105
|
+
* - Undefined values are treated as no cutoff.
|
|
106
|
+
* - Negative values follow .slice() behavior and terminator will be added before the value.
|
|
107
|
+
* - 0 will result in an empty string.
|
|
108
|
+
* - If cutoff results in an empty string, no terminator is added.
|
|
109
|
+
* @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
|
|
110
|
+
* @param {string} [options.terminator] - Optional override the terminator to use.
|
|
111
|
+
* @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
|
|
112
|
+
* - If no terminator is provided, then separator is ignored.
|
|
113
|
+
* @returns {string} The formatted string with terminator applied if cutoff occurs.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
|
|
117
|
+
* // Returns: 'Hello, …'
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
|
|
121
|
+
* // Returns: '…d!'
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* formatCutoff('Very long text that needs cutting', {
|
|
125
|
+
* locales: 'en-US',
|
|
126
|
+
* maxChars: 15,
|
|
127
|
+
* style: 'ellipsis',
|
|
128
|
+
* separator: ' '
|
|
129
|
+
* });
|
|
130
|
+
* // Returns: 'Very long tex …'
|
|
131
|
+
*/
|
|
132
|
+
declare function formatCutoff(value: string, options?: {
|
|
133
|
+
locales?: string | string[];
|
|
134
|
+
} & CutoffFormatOptions): string;
|
|
135
|
+
/**
|
|
136
|
+
* Formats a message according to the specified locales and options.
|
|
137
|
+
*
|
|
138
|
+
* @param {string} message - The message to format.
|
|
139
|
+
* @param {Object} [options] - Configuration options for message formatting.
|
|
140
|
+
* @param {string | string[]} [options.locales] - The locales to use for formatting.
|
|
141
|
+
* @param {FormatVariables} [options.variables] - The variables to use for formatting.
|
|
142
|
+
* @param {StringFormat} [options.dataFormat='ICU'] - The format of the message. When STRING, the message is returned as is.
|
|
143
|
+
* @returns {string} The formatted message.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* formatMessage('Hello {name}', { variables: { name: 'John' } });
|
|
147
|
+
* // Returns: "Hello John"
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* formatMessage('Hello {name}', {
|
|
151
|
+
* locales: ['fr'],
|
|
152
|
+
* variables: { name: 'John' }
|
|
153
|
+
* });
|
|
154
|
+
*/
|
|
155
|
+
declare function formatMessage(message: string, options?: {
|
|
156
|
+
locales?: string | string[];
|
|
157
|
+
variables?: FormatVariables;
|
|
158
|
+
dataFormat?: StringFormat;
|
|
159
|
+
}): string;
|
|
160
|
+
/**
|
|
161
|
+
* Checks if a given BCP 47 locale code is valid.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} locale - The BCP 47 locale code to validate.
|
|
164
|
+
* @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
|
|
165
|
+
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* isValidLocale('en-US');
|
|
169
|
+
* // Returns: true
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* isValidLocale('en_US');
|
|
173
|
+
* // Returns: false
|
|
174
|
+
*/
|
|
175
|
+
declare function isValidLocale(locale: string, customMapping?: CustomMapping): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Resolves the canonical locale for a given locale.
|
|
178
|
+
*
|
|
179
|
+
* @param {string} locale - The locale to resolve the canonical locale for.
|
|
180
|
+
* @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale.
|
|
181
|
+
* @returns {string} The canonical locale.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* resolveCanonicalLocale('en-US');
|
|
185
|
+
* // Returns: 'en-US'
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* resolveCanonicalLocale('en', { en: 'en-US' });
|
|
189
|
+
* // Returns: 'en-US'
|
|
190
|
+
*/
|
|
191
|
+
declare function resolveCanonicalLocale(locale: string, customMapping?: CustomMapping): string;
|
|
192
|
+
/**
|
|
193
|
+
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
|
194
|
+
*
|
|
195
|
+
* @param {string} locale - The BCP 47 locale code to standardize.
|
|
196
|
+
* @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* standardizeLocale('en-us');
|
|
200
|
+
* // Returns: 'en-US'
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* standardizeLocale('not a locale');
|
|
204
|
+
* // Returns: ''
|
|
205
|
+
*/
|
|
206
|
+
declare function standardizeLocale(locale: string): string;
|
|
207
|
+
//#endregion
|
|
208
|
+
export { standardizeLocale as a, CutoffFormatOptions as c, resolveCanonicalLocale as i, formatMessage as n, LocaleConfig as o, isValidLocale as r, LocaleConfigConstructorParams as s, formatCutoff as t };
|
|
209
|
+
//# sourceMappingURL=core-CJMv4fMa.d.cts.map
|