generaltranslation 8.2.13 → 8.2.15
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 +22 -1
- package/dist/{ApiError-IYfaOR30.mjs → ApiError-0DxxIHLp.mjs} +1 -1
- package/dist/{ApiError-CZ45tkW6.cjs.map → ApiError-0DxxIHLp.mjs.map} +1 -1
- package/dist/{ApiError-CZ45tkW6.cjs → ApiError-D-IBuHj6.cjs} +1 -1
- package/dist/{ApiError-IYfaOR30.mjs.map → ApiError-D-IBuHj6.cjs.map} +1 -1
- package/dist/LocaleConfig.d.ts +1 -59
- package/dist/LocaleConfig.js +1 -225
- package/dist/{base64-2fu94Klt.cjs → base64-YBGAXkqy.cjs} +74 -1
- package/dist/base64-YBGAXkqy.cjs.map +1 -0
- package/dist/{base64-DH0STixb.mjs → base64-r7YWJYWt.mjs} +51 -2
- package/dist/base64-r7YWJYWt.mjs.map +1 -0
- package/dist/core.cjs +9 -8
- package/dist/core.d.cts +1 -2
- package/dist/core.d.mts +1 -2
- package/dist/core.d.ts +1 -128
- package/dist/core.js +1 -137
- package/dist/core.mjs +2 -2
- package/dist/derive/indexVars.d.ts +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/id/types.d.ts +1 -1
- package/dist/{id-CyiXsQrY.cjs → id-C2orn1MA.cjs} +2 -2
- package/dist/{id-CyiXsQrY.cjs.map → id-C2orn1MA.cjs.map} +1 -1
- package/dist/{id-DbD7K-HL.mjs → id-DEaFhGqX.mjs} +2 -2
- package/dist/{id-DbD7K-HL.mjs.map → id-DEaFhGqX.mjs.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 +431 -396
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -242
- package/dist/index.d.mts +4 -242
- package/dist/index.d.ts +5 -238
- package/dist/index.js +3 -322
- package/dist/index.mjs +278 -363
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +8 -6
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +37 -6
- package/dist/internal.d.mts +37 -6
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +1 -0
- package/dist/internal.mjs +5 -5
- package/dist/internal.mjs.map +1 -1
- package/dist/{isVariable-B08mggBy.cjs → isVariable-Ba1gLXdB.cjs} +1 -1
- package/dist/{isVariable-B08mggBy.cjs.map → isVariable-Ba1gLXdB.cjs.map} +1 -1
- package/dist/{isVariable-CYsKFHvR.mjs → isVariable-fAKEB7gF.mjs} +1 -1
- package/dist/{isVariable-CYsKFHvR.mjs.map → isVariable-fAKEB7gF.mjs.map} +1 -1
- package/dist/locales/getPluralForm.js +2 -2
- package/dist/logging/diagnostics.d.ts +18 -0
- package/dist/logging/diagnostics.js +64 -0
- package/dist/logging/errors.d.ts +1 -1
- package/dist/logging/errors.js +64 -11
- package/dist/logging/logger.d.ts +0 -3
- package/dist/logging/logger.js +0 -3
- package/dist/{types-AHtYZIP-.d.mts → types-CdRgQtET.d.cts} +6 -106
- package/dist/{types-Bf8_Apq_.d.cts → types-Db2Dn3oN.d.mts} +6 -106
- package/dist/types-dir/api/enqueueEntries.d.ts +1 -1
- package/dist/types-dir/api/enqueueFiles.d.ts +1 -1
- package/dist/types-dir/api/fetchTranslations.d.ts +1 -1
- package/dist/types-dir/api/file.d.ts +1 -1
- package/dist/types-dir/api/translate.d.ts +1 -1
- package/dist/types-dir/api/uploadFiles.d.ts +1 -1
- package/dist/types.cjs +7 -16
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +10 -13
- package/dist/types.js +1 -2
- package/dist/types.mjs +1 -15
- package/package.json +3 -2
- package/dist/IntlCache-CAW8tKhd.cjs +0 -212
- package/dist/IntlCache-CAW8tKhd.cjs.map +0 -1
- package/dist/IntlCache-WZk0rKvj.mjs +0 -195
- package/dist/IntlCache-WZk0rKvj.mjs.map +0 -1
- package/dist/base64-2fu94Klt.cjs.map +0 -1
- package/dist/base64-DH0STixb.mjs.map +0 -1
- package/dist/cache/IntlCache.d.ts +0 -26
- package/dist/cache/IntlCache.js +0 -84
- package/dist/cache/types.d.ts +0 -32
- package/dist/cache/types.js +0 -1
- package/dist/core-7RP541eY.cjs +0 -1677
- package/dist/core-7RP541eY.cjs.map +0 -1
- package/dist/core-I9pWGafA.d.mts +0 -209
- package/dist/core-TLJoDpJP.d.cts +0 -209
- package/dist/core-isLphYAZ.mjs +0 -1498
- package/dist/core-isLphYAZ.mjs.map +0 -1
- package/dist/errors/formattingErrors.d.ts +0 -1
- package/dist/errors/formattingErrors.js +0 -3
- package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
- package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +0 -147
- package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
- package/dist/formatting/custom-formats/CutoffFormat/constants.js +0 -30
- package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
- package/dist/formatting/custom-formats/CutoffFormat/types.js +0 -2
- package/dist/formatting/format.d.ts +0 -1
- package/dist/formatting/format.js +0 -257
- package/dist/locales/customLocaleMapping.d.ts +0 -11
- package/dist/locales/customLocaleMapping.js +0 -23
- package/dist/locales/determineLocale.d.ts +0 -1
- package/dist/locales/determineLocale.js +0 -72
- package/dist/locales/getLocaleDirection.d.ts +0 -1
- package/dist/locales/getLocaleDirection.js +0 -89
- package/dist/locales/getLocaleEmoji.d.ts +0 -2
- package/dist/locales/getLocaleEmoji.js +0 -319
- package/dist/locales/getLocaleName.d.ts +0 -1
- package/dist/locales/getLocaleName.js +0 -45
- package/dist/locales/getLocaleProperties.d.ts +0 -32
- package/dist/locales/getLocaleProperties.js +0 -220
- package/dist/locales/getRegionProperties.d.ts +0 -7
- package/dist/locales/getRegionProperties.js +0 -61
- package/dist/locales/isSameDialect.d.ts +0 -1
- package/dist/locales/isSameDialect.js +0 -41
- package/dist/locales/isSameLanguage.d.ts +0 -1
- package/dist/locales/isSameLanguage.js +0 -20
- package/dist/locales/isSupersetLocale.d.ts +0 -1
- package/dist/locales/isSupersetLocale.js +0 -22
- package/dist/locales/isValidLocale.d.ts +0 -1
- package/dist/locales/isValidLocale.js +0 -75
- package/dist/locales/requiresTranslation.d.ts +0 -1
- package/dist/locales/requiresTranslation.js +0 -32
- package/dist/locales/resolveAliasLocale.d.ts +0 -8
- package/dist/locales/resolveAliasLocale.js +0 -21
- package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
- package/dist/locales/resolveCanonicalLocale.js +0 -13
- package/dist/logging/warnings.d.ts +0 -2
- package/dist/logging/warnings.js +0 -2
- package/dist/types-dir/jsx/content.d.ts +0 -61
- package/dist/types-dir/jsx/content.js +0 -11
- package/dist/types-dir/jsx/variables.d.ts +0 -9
- package/dist/types-dir/jsx/variables.js +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# generaltranslation
|
|
2
2
|
|
|
3
|
+
## 8.2.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1416](https://github.com/generaltranslation/gt/pull/1416) [`bb3624e`](https://github.com/generaltranslation/gt/commit/bb3624e58546c334c04370a1f5a262238bd040fa) Thanks [@bgub](https://github.com/bgub)! - Honor custom locale region display-name overrides and simplify shared locale formatting helpers.
|
|
8
|
+
|
|
9
|
+
- [#1419](https://github.com/generaltranslation/gt/pull/1419) [`a877a2a`](https://github.com/generaltranslation/gt/commit/a877a2a5bd5ca47b199c6caf53a6d60d96e3a300) Thanks [@bgub](https://github.com/bgub)! - Improve diagnostic messages and package-local diagnostic formatting.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`bb3624e`](https://github.com/generaltranslation/gt/commit/bb3624e58546c334c04370a1f5a262238bd040fa)]:
|
|
12
|
+
- @generaltranslation/format@0.1.1
|
|
13
|
+
|
|
14
|
+
## 8.2.14
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#1397](https://github.com/generaltranslation/gt/pull/1397) [`73f3ac1`](https://github.com/generaltranslation/gt/commit/73f3ac1308df11c1e6230c13c1999bfc5f6afc99) Thanks [@bgub](https://github.com/bgub)! - Extract locale and formatting primitives into the new `@generaltranslation/format` package and update `generaltranslation/core` to re-export the shared helpers.
|
|
19
|
+
|
|
20
|
+
- [#1408](https://github.com/generaltranslation/gt/pull/1408) [`425d3e4`](https://github.com/generaltranslation/gt/commit/425d3e4e6c61afd108c65c27f7693ba2470b33c6) Thanks [@bgub](https://github.com/bgub)! - Use @generaltranslation/format directly for shared formatting and locale helpers.
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`73f3ac1`](https://github.com/generaltranslation/gt/commit/73f3ac1308df11c1e6230c13c1999bfc5f6afc99)]:
|
|
23
|
+
- @generaltranslation/format@0.1.0
|
|
24
|
+
|
|
3
25
|
## 8.2.13
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -289,7 +311,6 @@
|
|
|
289
311
|
https://generaltranslation.com/blog/generaltranslation_v8
|
|
290
312
|
|
|
291
313
|
Please update the following packages to the latest version:
|
|
292
|
-
|
|
293
314
|
- generaltranslation: `7.9.1` or later
|
|
294
315
|
- gtx-cli: `2.4.15` or later
|
|
295
316
|
- gt-sanity: `1.0.11` or later
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiError-
|
|
1
|
+
{"version":3,"file":"ApiError-0DxxIHLp.mjs","names":[],"sources":["../src/errors/ApiError.ts"],"sourcesContent":["export class ApiError extends Error {\n public code: number;\n public message: string;\n\n constructor(error: string, code: number, message: string) {\n super(error);\n this.name = 'ApiError';\n this.code = code;\n this.message = message;\n }\n\n getCode() {\n return this.code;\n }\n\n getMessage() {\n return this.message;\n }\n}\n"],"mappings":";AAAA,IAAa,WAAb,cAA8B,MAAM;CAIlC,YAAY,OAAe,MAAc,SAAiB;AACxD,QAAM,MAAM;AACZ,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,UAAU;;CAGjB,UAAU;AACR,SAAO,KAAK;;CAGd,aAAa;AACX,SAAO,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiError-
|
|
1
|
+
{"version":3,"file":"ApiError-D-IBuHj6.cjs","names":[],"sources":["../src/errors/ApiError.ts"],"sourcesContent":["export class ApiError extends Error {\n public code: number;\n public message: string;\n\n constructor(error: string, code: number, message: string) {\n super(error);\n this.name = 'ApiError';\n this.code = code;\n this.message = message;\n }\n\n getCode() {\n return this.code;\n }\n\n getMessage() {\n return this.message;\n }\n}\n"],"mappings":";AAAA,IAAa,WAAb,cAA8B,MAAM;CAIlC,YAAY,OAAe,MAAc,SAAiB;AACxD,QAAM,MAAM;AACZ,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,UAAU;;CAGjB,UAAU;AACR,SAAO,KAAK;;CAGd,aAAa;AACX,SAAO,KAAK"}
|
package/dist/LocaleConfig.d.ts
CHANGED
|
@@ -1,59 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { CutoffFormatOptions } from './formatting/custom-formats/CutoffFormat/types';
|
|
3
|
-
import { StringFormat } from './types-dir/jsx/content';
|
|
4
|
-
export type LocaleConfigConstructorParams = {
|
|
5
|
-
defaultLocale?: string;
|
|
6
|
-
locales?: string[];
|
|
7
|
-
customMapping?: CustomMapping;
|
|
8
|
-
};
|
|
9
|
-
type LocalesOption = {
|
|
10
|
-
locales?: string | string[];
|
|
11
|
-
};
|
|
12
|
-
type WithLocales<T = object> = T & LocalesOption;
|
|
13
|
-
/**
|
|
14
|
-
* LocaleConfig contains the locale and formatting primitives exposed through
|
|
15
|
-
* the core entrypoint.
|
|
16
|
-
*
|
|
17
|
-
* It intentionally does not store project IDs, API keys, runtime URLs, or any
|
|
18
|
-
* translation credentials. It only stores locale metadata needed to resolve
|
|
19
|
-
* aliases, choose formatting fallbacks, and format values with Intl.
|
|
20
|
-
*/
|
|
21
|
-
export declare class LocaleConfig {
|
|
22
|
-
readonly defaultLocale: string;
|
|
23
|
-
readonly locales: string[];
|
|
24
|
-
readonly customMapping?: CustomMapping;
|
|
25
|
-
constructor({ defaultLocale, locales, customMapping, }?: LocaleConfigConstructorParams);
|
|
26
|
-
private get translationLocales();
|
|
27
|
-
private resolveCanonicalLocaleList;
|
|
28
|
-
private resolveCanonicalLocaleArgs;
|
|
29
|
-
private toLocaleList;
|
|
30
|
-
private getFormattingLocales;
|
|
31
|
-
formatNum(value: number, targetLocale?: string, options?: WithLocales<Intl.NumberFormatOptions>): string;
|
|
32
|
-
formatDateTime(value: Date, targetLocale?: string, options?: WithLocales<Intl.DateTimeFormatOptions>): string;
|
|
33
|
-
formatCurrency(value: number, currency: string, targetLocale?: string, options?: WithLocales<Intl.NumberFormatOptions>): string;
|
|
34
|
-
formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, targetLocale?: string, options?: WithLocales<Intl.RelativeTimeFormatOptions>): string;
|
|
35
|
-
formatRelativeTimeFromDate(date: Date, targetLocale?: string, options?: WithLocales<Intl.RelativeTimeFormatOptions & {
|
|
36
|
-
baseDate?: Date;
|
|
37
|
-
}>): string;
|
|
38
|
-
formatCutoff(value: string, targetLocale?: string, options?: WithLocales<CutoffFormatOptions>): string;
|
|
39
|
-
formatMessage(message: string, targetLocale?: string, options?: WithLocales<{
|
|
40
|
-
variables?: FormatVariables;
|
|
41
|
-
dataFormat?: StringFormat;
|
|
42
|
-
}>): string;
|
|
43
|
-
formatList(array: Array<string | number>, targetLocale?: string, options?: WithLocales<Intl.ListFormatOptions>): string;
|
|
44
|
-
formatListToParts<T>(array: Array<T>, targetLocale?: string, options?: WithLocales<Intl.ListFormatOptions>): (string | T)[];
|
|
45
|
-
getLocaleName(locale: string): string;
|
|
46
|
-
getLocaleEmoji(locale: string): string;
|
|
47
|
-
getLocaleProperties(locale: string): import("./types").LocaleProperties;
|
|
48
|
-
requiresTranslation(targetLocale: string, sourceLocale?: string, approvedLocales?: string[] | undefined): boolean;
|
|
49
|
-
determineLocale(locales: string | string[], approvedLocales?: string[]): string | undefined;
|
|
50
|
-
getLocaleDirection(locale: string): "ltr" | "rtl";
|
|
51
|
-
isValidLocale(locale: string): boolean;
|
|
52
|
-
resolveCanonicalLocale(locale: string): string;
|
|
53
|
-
resolveAliasLocale(locale: string): string;
|
|
54
|
-
standardizeLocale(locale: string): string;
|
|
55
|
-
isSameDialect(...locales: (string | string[])[]): boolean;
|
|
56
|
-
isSameLanguage(...locales: (string | string[])[]): boolean;
|
|
57
|
-
isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
|
58
|
-
}
|
|
59
|
-
export {};
|
|
1
|
+
export { LocaleConfig, type LocaleConfigConstructorParams, } from '@generaltranslation/format';
|
package/dist/LocaleConfig.js
CHANGED
|
@@ -1,225 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { _formatCurrency, _formatCutoff, _formatDateTime, _formatList, _formatListToParts, _formatMessageICU, _formatMessageString, _formatNum, _formatRelativeTime, _formatRelativeTimeFromDate, } from './formatting/format';
|
|
13
|
-
import _requiresTranslation from './locales/requiresTranslation';
|
|
14
|
-
import _determineLocale from './locales/determineLocale';
|
|
15
|
-
import _isSameLanguage from './locales/isSameLanguage';
|
|
16
|
-
import _getLocaleProperties from './locales/getLocaleProperties';
|
|
17
|
-
import _getLocaleEmoji from './locales/getLocaleEmoji';
|
|
18
|
-
import { _isValidLocale, _standardizeLocale } from './locales/isValidLocale';
|
|
19
|
-
import { _getLocaleName } from './locales/getLocaleName';
|
|
20
|
-
import { _getLocaleDirection } from './locales/getLocaleDirection';
|
|
21
|
-
import { libraryDefaultLocale } from './settings/settings';
|
|
22
|
-
import _isSameDialect from './locales/isSameDialect';
|
|
23
|
-
import _isSupersetLocale from './locales/isSupersetLocale';
|
|
24
|
-
import { _resolveAliasLocale } from './locales/resolveAliasLocale';
|
|
25
|
-
import { _resolveCanonicalLocale } from './locales/resolveCanonicalLocale';
|
|
26
|
-
/**
|
|
27
|
-
* LocaleConfig contains the locale and formatting primitives exposed through
|
|
28
|
-
* the core entrypoint.
|
|
29
|
-
*
|
|
30
|
-
* It intentionally does not store project IDs, API keys, runtime URLs, or any
|
|
31
|
-
* translation credentials. It only stores locale metadata needed to resolve
|
|
32
|
-
* aliases, choose formatting fallbacks, and format values with Intl.
|
|
33
|
-
*/
|
|
34
|
-
var LocaleConfig = /** @class */ (function () {
|
|
35
|
-
function LocaleConfig(_a) {
|
|
36
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.defaultLocale, defaultLocale = _c === void 0 ? libraryDefaultLocale : _c, _d = _b.locales, locales = _d === void 0 ? [] : _d, customMapping = _b.customMapping;
|
|
37
|
-
this.defaultLocale = defaultLocale;
|
|
38
|
-
this.locales = locales;
|
|
39
|
-
this.customMapping = customMapping;
|
|
40
|
-
}
|
|
41
|
-
Object.defineProperty(LocaleConfig.prototype, "translationLocales", {
|
|
42
|
-
get: function () {
|
|
43
|
-
return this.locales.length ? this.locales : undefined;
|
|
44
|
-
},
|
|
45
|
-
enumerable: false,
|
|
46
|
-
configurable: true
|
|
47
|
-
});
|
|
48
|
-
LocaleConfig.prototype.resolveCanonicalLocaleList = function (locales) {
|
|
49
|
-
var _this = this;
|
|
50
|
-
return locales.map(function (locale) { return _this.resolveCanonicalLocale(locale); });
|
|
51
|
-
};
|
|
52
|
-
LocaleConfig.prototype.resolveCanonicalLocaleArgs = function (locales) {
|
|
53
|
-
var _this = this;
|
|
54
|
-
return locales.map(function (locale) {
|
|
55
|
-
return Array.isArray(locale)
|
|
56
|
-
? _this.resolveCanonicalLocaleList(locale)
|
|
57
|
-
: _this.resolveCanonicalLocale(locale);
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
LocaleConfig.prototype.toLocaleList = function (locales) {
|
|
61
|
-
return Array.isArray(locales) ? locales : [locales];
|
|
62
|
-
};
|
|
63
|
-
LocaleConfig.prototype.getFormattingLocales = function (targetLocale, locales) {
|
|
64
|
-
var _this = this;
|
|
65
|
-
var localeList = locales !== undefined
|
|
66
|
-
? this.toLocaleList(locales)
|
|
67
|
-
: [targetLocale, this.defaultLocale, libraryDefaultLocale];
|
|
68
|
-
return localeList
|
|
69
|
-
.filter(function (locale) { return !!locale; })
|
|
70
|
-
.map(function (locale) { return _this.resolveCanonicalLocale(locale); });
|
|
71
|
-
};
|
|
72
|
-
LocaleConfig.prototype.formatNum = function (value, targetLocale, options) {
|
|
73
|
-
if (options === void 0) { options = {}; }
|
|
74
|
-
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
75
|
-
return _formatNum({
|
|
76
|
-
value: value,
|
|
77
|
-
locales: this.getFormattingLocales(targetLocale, locales),
|
|
78
|
-
options: intlOptions,
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
LocaleConfig.prototype.formatDateTime = function (value, targetLocale, options) {
|
|
82
|
-
if (options === void 0) { options = {}; }
|
|
83
|
-
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
84
|
-
return _formatDateTime({
|
|
85
|
-
value: value,
|
|
86
|
-
locales: this.getFormattingLocales(targetLocale, locales),
|
|
87
|
-
options: intlOptions,
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
LocaleConfig.prototype.formatCurrency = function (value, currency, targetLocale, options) {
|
|
91
|
-
if (options === void 0) { options = {}; }
|
|
92
|
-
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
93
|
-
return _formatCurrency({
|
|
94
|
-
value: value,
|
|
95
|
-
currency: currency,
|
|
96
|
-
locales: this.getFormattingLocales(targetLocale, locales),
|
|
97
|
-
options: intlOptions,
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
LocaleConfig.prototype.formatRelativeTime = function (value, unit, targetLocale, options) {
|
|
101
|
-
if (options === void 0) { options = {}; }
|
|
102
|
-
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
103
|
-
return _formatRelativeTime({
|
|
104
|
-
value: value,
|
|
105
|
-
unit: unit,
|
|
106
|
-
locales: this.getFormattingLocales(targetLocale, locales),
|
|
107
|
-
options: intlOptions,
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
LocaleConfig.prototype.formatRelativeTimeFromDate = function (date, targetLocale, options) {
|
|
111
|
-
if (options === void 0) { options = {}; }
|
|
112
|
-
var locales = options.locales, baseDate = options.baseDate, intlOptions = __rest(options, ["locales", "baseDate"]);
|
|
113
|
-
return _formatRelativeTimeFromDate({
|
|
114
|
-
date: date,
|
|
115
|
-
baseDate: baseDate !== null && baseDate !== void 0 ? baseDate : new Date(),
|
|
116
|
-
locales: this.getFormattingLocales(targetLocale, locales),
|
|
117
|
-
options: intlOptions,
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
LocaleConfig.prototype.formatCutoff = function (value, targetLocale, options) {
|
|
121
|
-
if (options === void 0) { options = {}; }
|
|
122
|
-
var locales = options.locales, formatOptions = __rest(options, ["locales"]);
|
|
123
|
-
return _formatCutoff({
|
|
124
|
-
value: value,
|
|
125
|
-
locales: this.getFormattingLocales(targetLocale, locales),
|
|
126
|
-
options: formatOptions,
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
LocaleConfig.prototype.formatMessage = function (message, targetLocale, options) {
|
|
130
|
-
if (options === void 0) { options = {}; }
|
|
131
|
-
var locales = options.locales, variables = options.variables, dataFormat = options.dataFormat;
|
|
132
|
-
if (dataFormat === 'STRING')
|
|
133
|
-
return _formatMessageString(message);
|
|
134
|
-
return _formatMessageICU(message, this.getFormattingLocales(targetLocale, locales), variables);
|
|
135
|
-
};
|
|
136
|
-
LocaleConfig.prototype.formatList = function (array, targetLocale, options) {
|
|
137
|
-
if (options === void 0) { options = {}; }
|
|
138
|
-
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
139
|
-
return _formatList({
|
|
140
|
-
value: array,
|
|
141
|
-
locales: this.getFormattingLocales(targetLocale, locales),
|
|
142
|
-
options: intlOptions,
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
LocaleConfig.prototype.formatListToParts = function (array, targetLocale, options) {
|
|
146
|
-
if (options === void 0) { options = {}; }
|
|
147
|
-
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
148
|
-
return _formatListToParts({
|
|
149
|
-
value: array,
|
|
150
|
-
locales: this.getFormattingLocales(targetLocale, locales),
|
|
151
|
-
options: intlOptions,
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
LocaleConfig.prototype.getLocaleName = function (locale) {
|
|
155
|
-
return _getLocaleName(locale, this.defaultLocale, this.customMapping);
|
|
156
|
-
};
|
|
157
|
-
LocaleConfig.prototype.getLocaleEmoji = function (locale) {
|
|
158
|
-
return _getLocaleEmoji(locale, this.customMapping);
|
|
159
|
-
};
|
|
160
|
-
LocaleConfig.prototype.getLocaleProperties = function (locale) {
|
|
161
|
-
return _getLocaleProperties(locale, this.defaultLocale, this.customMapping);
|
|
162
|
-
};
|
|
163
|
-
LocaleConfig.prototype.requiresTranslation = function (targetLocale, sourceLocale, approvedLocales) {
|
|
164
|
-
if (sourceLocale === void 0) { sourceLocale = this.defaultLocale; }
|
|
165
|
-
if (approvedLocales === void 0) { approvedLocales = this.translationLocales; }
|
|
166
|
-
return _requiresTranslation(this.resolveCanonicalLocale(sourceLocale), this.resolveCanonicalLocale(targetLocale), approvedLocales
|
|
167
|
-
? this.resolveCanonicalLocaleList(approvedLocales)
|
|
168
|
-
: undefined, this.customMapping);
|
|
169
|
-
};
|
|
170
|
-
LocaleConfig.prototype.determineLocale = function (locales, approvedLocales) {
|
|
171
|
-
var _this = this;
|
|
172
|
-
var _a;
|
|
173
|
-
if (approvedLocales === void 0) { approvedLocales = this.locales; }
|
|
174
|
-
var approvedLocalePairs = approvedLocales.map(function (locale) { return ({
|
|
175
|
-
locale: locale,
|
|
176
|
-
canonicalLocale: _this.resolveCanonicalLocale(locale),
|
|
177
|
-
}); });
|
|
178
|
-
var resolvedLocale = _determineLocale(Array.isArray(locales)
|
|
179
|
-
? this.resolveCanonicalLocaleList(locales)
|
|
180
|
-
: this.resolveCanonicalLocale(locales), approvedLocalePairs.map(function (_a) {
|
|
181
|
-
var canonicalLocale = _a.canonicalLocale;
|
|
182
|
-
return canonicalLocale;
|
|
183
|
-
}), this.customMapping);
|
|
184
|
-
if (!resolvedLocale)
|
|
185
|
-
return undefined;
|
|
186
|
-
return (((_a = approvedLocalePairs.find(function (_a) {
|
|
187
|
-
var canonicalLocale = _a.canonicalLocale;
|
|
188
|
-
return canonicalLocale === resolvedLocale;
|
|
189
|
-
})) === null || _a === void 0 ? void 0 : _a.locale) || this.resolveAliasLocale(resolvedLocale));
|
|
190
|
-
};
|
|
191
|
-
LocaleConfig.prototype.getLocaleDirection = function (locale) {
|
|
192
|
-
return _getLocaleDirection(this.resolveCanonicalLocale(locale));
|
|
193
|
-
};
|
|
194
|
-
LocaleConfig.prototype.isValidLocale = function (locale) {
|
|
195
|
-
return _isValidLocale(locale, this.customMapping);
|
|
196
|
-
};
|
|
197
|
-
LocaleConfig.prototype.resolveCanonicalLocale = function (locale) {
|
|
198
|
-
return _resolveCanonicalLocale(locale, this.customMapping);
|
|
199
|
-
};
|
|
200
|
-
LocaleConfig.prototype.resolveAliasLocale = function (locale) {
|
|
201
|
-
return _resolveAliasLocale(locale, this.customMapping);
|
|
202
|
-
};
|
|
203
|
-
LocaleConfig.prototype.standardizeLocale = function (locale) {
|
|
204
|
-
return _standardizeLocale(locale);
|
|
205
|
-
};
|
|
206
|
-
LocaleConfig.prototype.isSameDialect = function () {
|
|
207
|
-
var locales = [];
|
|
208
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
209
|
-
locales[_i] = arguments[_i];
|
|
210
|
-
}
|
|
211
|
-
return _isSameDialect.apply(void 0, this.resolveCanonicalLocaleArgs(locales));
|
|
212
|
-
};
|
|
213
|
-
LocaleConfig.prototype.isSameLanguage = function () {
|
|
214
|
-
var locales = [];
|
|
215
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
216
|
-
locales[_i] = arguments[_i];
|
|
217
|
-
}
|
|
218
|
-
return _isSameLanguage.apply(void 0, this.resolveCanonicalLocaleArgs(locales));
|
|
219
|
-
};
|
|
220
|
-
LocaleConfig.prototype.isSupersetLocale = function (superLocale, subLocale) {
|
|
221
|
-
return _isSupersetLocale(this.resolveCanonicalLocale(superLocale), this.resolveCanonicalLocale(subLocale));
|
|
222
|
-
};
|
|
223
|
-
return LocaleConfig;
|
|
224
|
-
}());
|
|
225
|
-
export { LocaleConfig };
|
|
1
|
+
export { LocaleConfig, } from '@generaltranslation/format';
|
|
@@ -1,3 +1,52 @@
|
|
|
1
|
+
//#region src/settings/settings.ts
|
|
2
|
+
const libraryDefaultLocale = "en";
|
|
3
|
+
const defaultTimeout = 6e4;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/logging/diagnostics.ts
|
|
6
|
+
function ensureSentence(text) {
|
|
7
|
+
const trimmed = text.trim();
|
|
8
|
+
if (!trimmed) return "";
|
|
9
|
+
return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;
|
|
10
|
+
}
|
|
11
|
+
function stripSentence(text) {
|
|
12
|
+
const trimmed = text.trim();
|
|
13
|
+
let end = trimmed.length;
|
|
14
|
+
while (end > 0) {
|
|
15
|
+
const char = trimmed[end - 1];
|
|
16
|
+
if (char !== "." && char !== "!" && char !== "?") break;
|
|
17
|
+
end -= 1;
|
|
18
|
+
}
|
|
19
|
+
return trimmed.slice(0, end);
|
|
20
|
+
}
|
|
21
|
+
function lowercaseFirstWord(text) {
|
|
22
|
+
return text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());
|
|
23
|
+
}
|
|
24
|
+
function formatDetails(details) {
|
|
25
|
+
if (!details) return "";
|
|
26
|
+
const detailText = Array.isArray(details) ? details.join(", ") : details;
|
|
27
|
+
if (!detailText.trim()) return "";
|
|
28
|
+
return ensureSentence(`Details: ${detailText}`);
|
|
29
|
+
}
|
|
30
|
+
function formatDiagnosticErrorDetails(error) {
|
|
31
|
+
if (error == null) return void 0;
|
|
32
|
+
return String(error);
|
|
33
|
+
}
|
|
34
|
+
function createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {
|
|
35
|
+
const prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : "";
|
|
36
|
+
const whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;
|
|
37
|
+
const shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));
|
|
38
|
+
const messageParts = [
|
|
39
|
+
whatAndWhy,
|
|
40
|
+
reassurance,
|
|
41
|
+
shouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,
|
|
42
|
+
shouldCombineWayOut ? void 0 : wayOut,
|
|
43
|
+
formatDetails(details)
|
|
44
|
+
].filter((part) => !!part).map(ensureSentence);
|
|
45
|
+
if (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);
|
|
46
|
+
const message = messageParts.join(" ");
|
|
47
|
+
return prefix ? `${prefix} ${message}` : message;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
1
50
|
//#region src/settings/settingsUrls.ts
|
|
2
51
|
const defaultCacheUrl = "https://cdn.gtx.dev";
|
|
3
52
|
const defaultBaseUrl = "https://api2.gtx.dev";
|
|
@@ -65,6 +114,12 @@ function decode(base64) {
|
|
|
65
114
|
return new TextDecoder().decode(bytes);
|
|
66
115
|
}
|
|
67
116
|
//#endregion
|
|
117
|
+
Object.defineProperty(exports, "createDiagnosticMessage", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function() {
|
|
120
|
+
return createDiagnosticMessage;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
68
123
|
Object.defineProperty(exports, "decode", {
|
|
69
124
|
enumerable: true,
|
|
70
125
|
get: function() {
|
|
@@ -89,18 +144,36 @@ Object.defineProperty(exports, "defaultRuntimeApiUrl", {
|
|
|
89
144
|
return defaultRuntimeApiUrl;
|
|
90
145
|
}
|
|
91
146
|
});
|
|
147
|
+
Object.defineProperty(exports, "defaultTimeout", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function() {
|
|
150
|
+
return defaultTimeout;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
92
153
|
Object.defineProperty(exports, "encode", {
|
|
93
154
|
enumerable: true,
|
|
94
155
|
get: function() {
|
|
95
156
|
return encode;
|
|
96
157
|
}
|
|
97
158
|
});
|
|
159
|
+
Object.defineProperty(exports, "formatDiagnosticErrorDetails", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function() {
|
|
162
|
+
return formatDiagnosticErrorDetails;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
98
165
|
Object.defineProperty(exports, "isSupportedFileFormatTransform", {
|
|
99
166
|
enumerable: true,
|
|
100
167
|
get: function() {
|
|
101
168
|
return isSupportedFileFormatTransform;
|
|
102
169
|
}
|
|
103
170
|
});
|
|
171
|
+
Object.defineProperty(exports, "libraryDefaultLocale", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get: function() {
|
|
174
|
+
return libraryDefaultLocale;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
104
177
|
Object.defineProperty(exports, "validateFileFormatTransforms", {
|
|
105
178
|
enumerable: true,
|
|
106
179
|
get: function() {
|
|
@@ -108,4 +181,4 @@ Object.defineProperty(exports, "validateFileFormatTransforms", {
|
|
|
108
181
|
}
|
|
109
182
|
});
|
|
110
183
|
|
|
111
|
-
//# sourceMappingURL=base64-
|
|
184
|
+
//# sourceMappingURL=base64-YBGAXkqy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-YBGAXkqy.cjs","names":[],"sources":["../src/settings/settings.ts","../src/logging/diagnostics.ts","../src/settings/settingsUrls.ts","../src/utils/isSupportedFileFormatTransform.ts","../src/translate/utils/validateFileFormatTransform.ts","../src/utils/base64.ts"],"sourcesContent":["export const libraryDefaultLocale = 'en' as const;\nexport const defaultTimeout = 60000;\n","export type DiagnosticSeverity = 'Error' | 'Warning';\n\n/**\n * Text slots follow the five-part error message model:\n * what happened, reassurance, why it happened, how to fix it, and a way out.\n */\nexport type DiagnosticMessageInput = {\n source?: string;\n severity?: DiagnosticSeverity;\n whatHappened: string;\n reassurance?: string;\n why?: string;\n fix?: string;\n wayOut?: string;\n details?: string | string[];\n docsUrl?: string;\n};\n\nfunction ensureSentence(text: string): string {\n const trimmed = text.trim();\n if (!trimmed) return '';\n return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\n\nfunction stripSentence(text: string): string {\n const trimmed = text.trim();\n let end = trimmed.length;\n while (end > 0) {\n const char = trimmed[end - 1];\n if (char !== '.' && char !== '!' && char !== '?') break;\n end -= 1;\n }\n return trimmed.slice(0, end);\n}\n\nfunction lowercaseFirstWord(text: string): string {\n return text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\n\nfunction formatDetails(details: string | string[] | undefined): string {\n if (!details) return '';\n const detailText = Array.isArray(details) ? details.join(', ') : details;\n if (!detailText.trim()) return '';\n return ensureSentence(`Details: ${detailText}`);\n}\n\nexport function formatDiagnosticErrorDetails(\n error: unknown\n): string | undefined {\n if (error == null) return undefined;\n return String(error);\n}\n\nexport function createDiagnosticMessage({\n source,\n severity,\n whatHappened,\n reassurance,\n why,\n fix,\n wayOut,\n details,\n docsUrl,\n}: DiagnosticMessageInput): string {\n const prefix = source\n ? severity\n ? `${source} ${severity}:`\n : `${source}:`\n : severity\n ? `${severity}:`\n : '';\n const whatAndWhy = why\n ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}`\n : whatHappened;\n const shouldCombineWayOut =\n !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n const fixAndWayOut = shouldCombineWayOut\n ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}`\n : fix;\n const messageParts = [\n whatAndWhy,\n reassurance,\n fixAndWayOut,\n shouldCombineWayOut ? undefined : wayOut,\n formatDetails(details),\n ]\n .filter((part): part is string => !!part)\n .map(ensureSentence);\n\n if (docsUrl) {\n messageParts.push(`Learn more: ${docsUrl}`);\n }\n\n const message = messageParts.join(' ');\n return prefix ? `${prefix} ${message}` : message;\n}\n","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,uBAAuB;AAC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AAQ,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,3 +1,52 @@
|
|
|
1
|
+
//#region src/settings/settings.ts
|
|
2
|
+
const libraryDefaultLocale = "en";
|
|
3
|
+
const defaultTimeout = 6e4;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/logging/diagnostics.ts
|
|
6
|
+
function ensureSentence(text) {
|
|
7
|
+
const trimmed = text.trim();
|
|
8
|
+
if (!trimmed) return "";
|
|
9
|
+
return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;
|
|
10
|
+
}
|
|
11
|
+
function stripSentence(text) {
|
|
12
|
+
const trimmed = text.trim();
|
|
13
|
+
let end = trimmed.length;
|
|
14
|
+
while (end > 0) {
|
|
15
|
+
const char = trimmed[end - 1];
|
|
16
|
+
if (char !== "." && char !== "!" && char !== "?") break;
|
|
17
|
+
end -= 1;
|
|
18
|
+
}
|
|
19
|
+
return trimmed.slice(0, end);
|
|
20
|
+
}
|
|
21
|
+
function lowercaseFirstWord(text) {
|
|
22
|
+
return text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());
|
|
23
|
+
}
|
|
24
|
+
function formatDetails(details) {
|
|
25
|
+
if (!details) return "";
|
|
26
|
+
const detailText = Array.isArray(details) ? details.join(", ") : details;
|
|
27
|
+
if (!detailText.trim()) return "";
|
|
28
|
+
return ensureSentence(`Details: ${detailText}`);
|
|
29
|
+
}
|
|
30
|
+
function formatDiagnosticErrorDetails(error) {
|
|
31
|
+
if (error == null) return void 0;
|
|
32
|
+
return String(error);
|
|
33
|
+
}
|
|
34
|
+
function createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {
|
|
35
|
+
const prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : "";
|
|
36
|
+
const whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;
|
|
37
|
+
const shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));
|
|
38
|
+
const messageParts = [
|
|
39
|
+
whatAndWhy,
|
|
40
|
+
reassurance,
|
|
41
|
+
shouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,
|
|
42
|
+
shouldCombineWayOut ? void 0 : wayOut,
|
|
43
|
+
formatDetails(details)
|
|
44
|
+
].filter((part) => !!part).map(ensureSentence);
|
|
45
|
+
if (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);
|
|
46
|
+
const message = messageParts.join(" ");
|
|
47
|
+
return prefix ? `${prefix} ${message}` : message;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
1
50
|
//#region src/settings/settingsUrls.ts
|
|
2
51
|
const defaultCacheUrl = "https://cdn.gtx.dev";
|
|
3
52
|
const defaultBaseUrl = "https://api2.gtx.dev";
|
|
@@ -65,6 +114,6 @@ function decode(base64) {
|
|
|
65
114
|
return new TextDecoder().decode(bytes);
|
|
66
115
|
}
|
|
67
116
|
//#endregion
|
|
68
|
-
export { defaultBaseUrl as a, isSupportedFileFormatTransform as i, encode as n, defaultCacheUrl as o, validateFileFormatTransforms as r, defaultRuntimeApiUrl as s, decode as t };
|
|
117
|
+
export { defaultBaseUrl as a, createDiagnosticMessage as c, libraryDefaultLocale as d, isSupportedFileFormatTransform as i, formatDiagnosticErrorDetails as l, encode as n, defaultCacheUrl as o, validateFileFormatTransforms as r, defaultRuntimeApiUrl as s, decode as t, defaultTimeout as u };
|
|
69
118
|
|
|
70
|
-
//# sourceMappingURL=base64-
|
|
119
|
+
//# sourceMappingURL=base64-r7YWJYWt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-r7YWJYWt.mjs","names":[],"sources":["../src/settings/settings.ts","../src/logging/diagnostics.ts","../src/settings/settingsUrls.ts","../src/utils/isSupportedFileFormatTransform.ts","../src/translate/utils/validateFileFormatTransform.ts","../src/utils/base64.ts"],"sourcesContent":["export const libraryDefaultLocale = 'en' as const;\nexport const defaultTimeout = 60000;\n","export type DiagnosticSeverity = 'Error' | 'Warning';\n\n/**\n * Text slots follow the five-part error message model:\n * what happened, reassurance, why it happened, how to fix it, and a way out.\n */\nexport type DiagnosticMessageInput = {\n source?: string;\n severity?: DiagnosticSeverity;\n whatHappened: string;\n reassurance?: string;\n why?: string;\n fix?: string;\n wayOut?: string;\n details?: string | string[];\n docsUrl?: string;\n};\n\nfunction ensureSentence(text: string): string {\n const trimmed = text.trim();\n if (!trimmed) return '';\n return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\n\nfunction stripSentence(text: string): string {\n const trimmed = text.trim();\n let end = trimmed.length;\n while (end > 0) {\n const char = trimmed[end - 1];\n if (char !== '.' && char !== '!' && char !== '?') break;\n end -= 1;\n }\n return trimmed.slice(0, end);\n}\n\nfunction lowercaseFirstWord(text: string): string {\n return text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());\n}\n\nfunction formatDetails(details: string | string[] | undefined): string {\n if (!details) return '';\n const detailText = Array.isArray(details) ? details.join(', ') : details;\n if (!detailText.trim()) return '';\n return ensureSentence(`Details: ${detailText}`);\n}\n\nexport function formatDiagnosticErrorDetails(\n error: unknown\n): string | undefined {\n if (error == null) return undefined;\n return String(error);\n}\n\nexport function createDiagnosticMessage({\n source,\n severity,\n whatHappened,\n reassurance,\n why,\n fix,\n wayOut,\n details,\n docsUrl,\n}: DiagnosticMessageInput): string {\n const prefix = source\n ? severity\n ? `${source} ${severity}:`\n : `${source}:`\n : severity\n ? `${severity}:`\n : '';\n const whatAndWhy = why\n ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}`\n : whatHappened;\n const shouldCombineWayOut =\n !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n const fixAndWayOut = shouldCombineWayOut\n ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}`\n : fix;\n const messageParts = [\n whatAndWhy,\n reassurance,\n fixAndWayOut,\n shouldCombineWayOut ? undefined : wayOut,\n formatDetails(details),\n ]\n .filter((part): part is string => !!part)\n .map(ensureSentence);\n\n if (docsUrl) {\n messageParts.push(`Learn more: ${docsUrl}`);\n }\n\n const message = messageParts.join(' ');\n return prefix ? `${prefix} ${message}` : message;\n}\n","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,uBAAuB;AACpC,MAAa,iBAAiB;;;ACiB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AAO,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"}
|
package/dist/core.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var _generaltranslation_format = require("@generaltranslation/format");
|
|
2
|
+
Object.keys(_generaltranslation_format).forEach(function(k) {
|
|
3
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _generaltranslation_format[k];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
});
|
package/dist/core.d.cts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { LocaleConfig, LocaleConfigConstructorParams, formatCutoff, formatMessage, isValidLocale, resolveCanonicalLocale, standardizeLocale };
|
|
1
|
+
export * from "@generaltranslation/format";
|
package/dist/core.d.mts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { LocaleConfig, LocaleConfigConstructorParams, formatCutoff, formatMessage, isValidLocale, resolveCanonicalLocale, standardizeLocale };
|
|
1
|
+
export * from "@generaltranslation/format";
|