generaltranslation 2.0.67 → 2.0.68

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.
Files changed (30) hide show
  1. package/README.md +1 -369
  2. package/dist/codes/{determineLanguage.js → _determineLanguage.js} +5 -2
  3. package/dist/codes/_isSameLanguage.js +22 -0
  4. package/dist/codes/codes.d.ts +1 -8
  5. package/dist/codes/codes.js +61 -287
  6. package/dist/formatting/{_format.js → format.js} +40 -3
  7. package/dist/formatting/{_string_content.js → string_content.js} +21 -12
  8. package/dist/index.d.ts +55 -72
  9. package/dist/index.js +88 -66
  10. package/dist/settings/libraryDefaultLanguage.d.ts +2 -0
  11. package/dist/settings/libraryDefaultLanguage.js +4 -0
  12. package/dist/translation/dictionaries/_translateBundle.js +2 -2
  13. package/dist/translation/dictionaries/_updateProjectDictionary.js +4 -5
  14. package/dist/translation/react/_translateReact.js +2 -2
  15. package/dist/translation/strings/_translate.js +2 -2
  16. package/package.json +2 -2
  17. package/dist/codes/15924/CodeToScript.json +0 -215
  18. package/dist/codes/15924/ScriptToCode.json +0 -215
  19. package/dist/codes/3166/CodeToRegion.json +0 -296
  20. package/dist/codes/3166/RegionToCode.json +0 -296
  21. package/dist/codes/639-1/CodeToLanguage.json +0 -185
  22. package/dist/codes/639-1/LanguageToCode.json +0 -227
  23. package/dist/codes/639-3/CodeToLanguageTriletter.json +0 -186
  24. package/dist/codes/639-3/LanguageToCodeTriletter.json +0 -228
  25. package/dist/codes/getLanguageDirection.js +0 -71
  26. package/dist/codes/predefined/Predefined.json +0 -28
  27. /package/dist/codes/{determineLanguage.d.ts → _determineLanguage.d.ts} +0 -0
  28. /package/dist/codes/{getLanguageDirection.d.ts → _isSameLanguage.d.ts} +0 -0
  29. /package/dist/formatting/{_format.d.ts → format.d.ts} +0 -0
  30. /package/dist/formatting/{_string_content.d.ts → string_content.d.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { LanguageObject } from './codes/codes';
2
1
  import { Content, Update, Request, ReactChildrenAsObject, ReactTranslationResult, ContentTranslationResult } from './types/types';
3
2
  /**
4
3
  * Type representing the constructor parameters for the GT class.
@@ -76,69 +75,42 @@ declare class GT {
76
75
  * @param {boolean} [replace=false] - Whether to replace the existing dictionary. Defaults to false.
77
76
  * @returns {Promise<string[]>} A promise that resolves to an array of strings indicating the languages which have been updated.
78
77
  */
79
- updateProjectDictionary(updates: Update[], languages?: string[], projectID?: string, replace?: boolean): Promise<string[]>;
78
+ updateProjectDictionary(updates: Update[], languages?: string[], replace?: boolean): Promise<string[]>;
80
79
  }
81
80
  export default GT;
82
81
  /**
83
- * Gets the writing direction for a given BCP 47 language code.
84
- * @param {string} code - The BCP 47 language code to check.
85
- * @returns {string} The language direction ('ltr' for left-to-right or 'rtl' for right-to-left).
82
+ * Get the text direction for a given language code using the Intl.Locale API.
83
+ *
84
+ * @param {string} code - The language code to check.
85
+ * @returns {string} - 'rtl' if the language is right-to-left, otherwise 'ltr'.
86
86
  */
87
- export declare const getLanguageDirection: (code: string) => string;
87
+ export declare function getLanguageDirection(code: string): string;
88
+ /**
89
+ * Retrieves the display name(s) of language code(s) using Intl.DisplayNames.
90
+ *
91
+ * @param {string | string[]} code - A language code or an array of codes.
92
+ * @param {string} [language = 'en'] - The language for display names.
93
+ * @returns {string | string[]} The display name(s) corresponding to the code(s), or empty string(s) if invalid.
94
+ */
95
+ export declare function getLanguageName(code: string | string[], language?: string): string | string[];
88
96
  /**
89
97
  * Checks if a given BCP 47 language code is valid.
90
98
  * @param {string} code - The BCP 47 language code to validate.
91
99
  * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
92
100
  */
93
- export declare const isValidLanguageCode: (code: string) => boolean;
101
+ export declare function isValidLanguageCode(code: string): boolean;
94
102
  /**
95
103
  * Standardizes a BCP 47 language code to ensure correct formatting.
96
104
  * @param {string} code - The BCP 47 language code to standardize.
97
105
  * @returns {string} The standardized BCP 47 language code.
98
106
  */
99
- export declare const standardizeLanguageCode: (code: string) => string;
100
- /**
101
- * Gets a language object from a BCP 47 language code.
102
- * @param {string} code - The BCP 47 language code to convert.
103
- * @returns {LanguageObject | null} The language object or null if the BCP 47 code is invalid.
104
- */
105
- export declare function getLanguageObject(code: string): LanguageObject | null;
106
- /**
107
- * Gets language objects from multiple BCP 47 language codes.
108
- * @param {string[]} codes - The BCP 47 language codes to convert.
109
- * @returns {(LanguageObject | null)[]} An array of language objects or null for each invalid BCP 47 code.
110
- */
111
- export declare function getLanguageObject(codes: string[]): (LanguageObject | null)[];
112
- /**
113
- * Gets a BCP 47 language code from a language name.
114
- * @param {string} language - The language name to convert.
115
- * @returns {string} The corresponding BCP 47 language code.
116
- */
117
- export declare function getLanguageCode(language: string): string;
118
- /**
119
- * Gets BCP 47 language codes from multiple language names.
120
- * @param {string[]} languages - The language names to convert.
121
- * @returns {string[]} The corresponding BCP 47 language codes.
122
- */
123
- export declare function getLanguageCode(languages: string[]): string[];
124
- /**
125
- * Gets a language name from a BCP 47 language code.
126
- * @param {string} code - The BCP 47 language code to convert.
127
- * @returns {string} The corresponding language name.
128
- */
129
- export declare function getLanguageName(code: string): string;
130
- /**
131
- * Gets language names from multiple BCP 47 language codes.
132
- * @param {string[]} codes - The BCP 47 language codes to convert.
133
- * @returns {string[]} The corresponding language names.
134
- */
135
- export declare function getLanguageName(codes: string[]): string[];
107
+ export declare function standardizeLanguageCode(code: string): string;
136
108
  /**
137
109
  * Checks if multiple BCP 47 language codes represent the same language.
138
110
  * @param {string[]} codes - The BCP 47 language codes to compare.
139
111
  * @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
140
112
  */
141
- export declare function isSameLanguage(...codes: string[]): boolean;
113
+ export declare function isSameLanguage(...codes: (string | string[])[]): boolean;
142
114
  /**
143
115
  * Formats a number according to the specified languages and options.
144
116
  * @param {Object} params - The parameters for the number formatting.
@@ -147,7 +119,7 @@ export declare function isSameLanguage(...codes: string[]): boolean;
147
119
  * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
148
120
  * @returns {string} The formatted number.
149
121
  */
150
- export declare function formatNum({ value, languages, options }: {
122
+ export declare function formatNum(params: {
151
123
  value: number;
152
124
  languages?: string | string[];
153
125
  options?: Intl.NumberFormatOptions;
@@ -160,7 +132,7 @@ export declare function formatNum({ value, languages, options }: {
160
132
  * @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
161
133
  * @returns {string} The formatted date.
162
134
  */
163
- export declare function formatDateTime({ value, languages, options }: {
135
+ export declare function formatDateTime(params: {
164
136
  value: Date;
165
137
  languages?: string | string[];
166
138
  options?: Intl.DateTimeFormatOptions;
@@ -174,48 +146,59 @@ export declare function formatDateTime({ value, languages, options }: {
174
146
  * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
175
147
  * @returns {string} The formatted currency value.
176
148
  */
177
- export declare function formatCurrency({ value, languages, currency, options }: {
149
+ export declare function formatCurrency(params: {
178
150
  value: number;
151
+ currency: string;
179
152
  languages?: string | string[];
180
- currency?: string;
181
153
  options?: Intl.NumberFormatOptions;
182
154
  }): string;
155
+ /**
156
+ * Formats a list of items according to the specified languages and options.
157
+ * @param {Object} params - The parameters for the list formatting.
158
+ * @param {Array<string | number>} params.value - The list of items to format.
159
+ * @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
160
+ * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
161
+ * @returns {string} The formatted list.
162
+ */
163
+ export declare function formatList(params: {
164
+ value: Array<string | number>;
165
+ languages?: string | string[];
166
+ options?: Intl.ListFormatOptions;
167
+ }): string;
168
+ /**
169
+ * Formats a relative time value according to the specified languages and options.
170
+ * @param {Object} params - The parameters for the relative time formatting.
171
+ * @param {number} params.value - The relative time value to format.
172
+ * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
173
+ * @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
174
+ * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
175
+ * @returns {string} The formatted relative time string.
176
+ */
177
+ export declare function formatRelativeTime(params: {
178
+ value: number;
179
+ unit: Intl.RelativeTimeFormatUnit;
180
+ languages?: string | string[];
181
+ options?: Intl.RelativeTimeFormatOptions;
182
+ }): string;
183
183
  /**
184
184
  * Splits a string into an array of text and variable objects.
185
- *
186
185
  * @param {string} string - The input string to split.
187
186
  * @returns {Content} - An array containing strings and VariableObjects.
188
187
  */
189
188
  export declare function splitStringToContent(string: string): Content;
190
189
  /**
191
190
  * Renders content to a string by replacing variables with their formatted values.
192
- *
193
- * @param {Content} content - The content to render, which can be a string or an array of strings and VariableObjects.
191
+ * @param {Content} content - The content to render.
194
192
  * @param {string | string[]} [languages='en'] - The language(s) to use for formatting.
195
- * @param {Record<string, any>} [variables={}] - An object containing variable values keyed by variable names.
196
- * @param {Record<string, any>} [variableOptions={}] - An object containing options for formatting variables, keyed by variable names.
193
+ * @param {Record<string, any>} [variables={}] - An object containing variable values.
194
+ * @param {Record<string, any>} [variableOptions={}] - An object containing options for formatting variables.
197
195
  * @returns {string} - The rendered string with variables replaced by their formatted values.
198
- *
199
- */
200
- export declare function renderContentToString<V extends Record<string, any>>(content: Content, languages?: string | string[], variables?: V, variableOptions?: {
201
- [key in keyof V]?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
202
- }): string;
196
+ */
197
+ export declare function renderContentToString(content: Content, languages?: string | string[], variables?: Record<string, any>, variableOptions?: Record<string, any>): string;
203
198
  /**
204
- * Determines the best matching language from the approved languages list based on a provided
205
- * list of preferred languages. The function prioritizes exact matches, but will also consider
206
- * dialects of the same language if an exact match is not available.
207
- *
208
- * It also respects the order of preference in both the provided languages list and the
209
- * approved languages list. A dialect match of a higher-preference language is considered better
210
- * than an exact match of a lower-preference language.
211
- *
212
- * For example, if the `languages` list is ['en', 'fr'], and the `approvedLanguages` list is
213
- * ['fr', 'en-GB'], it will prefer 'en-GB' over 'fr', even though 'fr' has an exact
214
- * dialect match, because 'en' appears earlier in the `languages` list.
215
- *
199
+ * Determines the best matching language from the approved languages list based on a provided list of preferred languages.
216
200
  * @param {string | string[]} languages - A single language or an array of languages sorted in preference order.
217
201
  * @param {string[]} approvedLanguages - An array of approved languages, also sorted by preference.
218
- *
219
202
  * @returns {string | undefined} - The best matching language from the approvedLanguages list, or undefined if no match is found.
220
203
  */
221
204
  export declare function determineLanguage(languages: string | string[], approvedLanguages: string[]): string | undefined;
package/dist/index.js CHANGED
@@ -22,8 +22,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  });
23
23
  };
24
24
  var __generator = (this && this.__generator) || function (thisArg, body) {
25
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
26
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
26
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
27
27
  function verb(n) { return function (v) { return step([n, v]); }; }
28
28
  function step(op) {
29
29
  if (f) throw new TypeError("Generator is already executing.");
@@ -52,27 +52,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
52
52
  return (mod && mod.__esModule) ? mod : { "default": mod };
53
53
  };
54
54
  Object.defineProperty(exports, "__esModule", { value: true });
55
- exports.standardizeLanguageCode = exports.isValidLanguageCode = exports.getLanguageDirection = void 0;
56
- exports.getLanguageObject = getLanguageObject;
57
- exports.getLanguageCode = getLanguageCode;
55
+ exports.getLanguageDirection = getLanguageDirection;
58
56
  exports.getLanguageName = getLanguageName;
57
+ exports.isValidLanguageCode = isValidLanguageCode;
58
+ exports.standardizeLanguageCode = standardizeLanguageCode;
59
59
  exports.isSameLanguage = isSameLanguage;
60
60
  exports.formatNum = formatNum;
61
61
  exports.formatDateTime = formatDateTime;
62
62
  exports.formatCurrency = formatCurrency;
63
+ exports.formatList = formatList;
64
+ exports.formatRelativeTime = formatRelativeTime;
63
65
  exports.splitStringToContent = splitStringToContent;
64
66
  exports.renderContentToString = renderContentToString;
65
67
  exports.determineLanguage = determineLanguage;
66
68
  // ----- IMPORTS ----- //
67
- var codes_1 = require("./codes/codes");
68
- var getLanguageDirection_1 = __importDefault(require("./codes/getLanguageDirection"));
69
69
  var _translateBundle_1 = __importDefault(require("./translation/dictionaries/_translateBundle"));
70
70
  var _translate_1 = __importDefault(require("./translation/strings/_translate"));
71
71
  var _translateReact_1 = __importDefault(require("./translation/react/_translateReact"));
72
72
  var _updateProjectDictionary_1 = __importDefault(require("./translation/dictionaries/_updateProjectDictionary"));
73
- var _format_1 = require("./formatting/_format");
74
- var _string_content_1 = require("./formatting/_string_content");
75
- var determineLanguage_1 = __importDefault(require("./codes/determineLanguage"));
73
+ var _determineLanguage_1 = __importDefault(require("./codes/_determineLanguage"));
74
+ var format_1 = require("./formatting/format");
75
+ var string_content_1 = require("./formatting/string_content");
76
+ var codes_1 = require("./codes/codes");
77
+ var _isSameLanguage_1 = __importDefault(require("./codes/_isSameLanguage"));
78
+ var libraryDefaultLanguage_1 = __importDefault(require("./settings/libraryDefaultLanguage"));
76
79
  // ----- CORE CLASS ----- //
77
80
  var getDefaultFromEnv = function (VARIABLE) {
78
81
  if (typeof process !== 'undefined' && process.env) {
@@ -94,7 +97,7 @@ var GT = /** @class */ (function () {
94
97
  * @param {string} [params.baseURL='https://prod.gtx.dev'] - The base URL for the translation service.
95
98
  */
96
99
  function GT(_a) {
97
- var _b = _a === void 0 ? {} : _a, _c = _b.apiKey, apiKey = _c === void 0 ? '' : _c, _d = _b.defaultLanguage, defaultLanguage = _d === void 0 ? 'en' : _d, _e = _b.projectID, projectID = _e === void 0 ? '' : _e, _f = _b.baseURL, baseURL = _f === void 0 ? 'https://prod.gtx.dev' : _f;
100
+ var _b = _a === void 0 ? {} : _a, _c = _b.apiKey, apiKey = _c === void 0 ? '' : _c, _d = _b.defaultLanguage, defaultLanguage = _d === void 0 ? libraryDefaultLanguage_1.default : _d, _e = _b.projectID, projectID = _e === void 0 ? '' : _e, _f = _b.baseURL, baseURL = _f === void 0 ? 'https://prod.gtx.dev' : _f;
98
101
  this.apiKey = apiKey || getDefaultFromEnv('GT_API_KEY');
99
102
  this.projectID = projectID || getDefaultFromEnv('GT_PROJECT_ID');
100
103
  this.defaultLanguage = defaultLanguage.toLowerCase();
@@ -163,51 +166,57 @@ var GT = /** @class */ (function () {
163
166
  * @returns {Promise<string[]>} A promise that resolves to an array of strings indicating the languages which have been updated.
164
167
  */
165
168
  GT.prototype.updateProjectDictionary = function (updates_1) {
166
- return __awaiter(this, arguments, void 0, function (updates, languages, projectID, replace) {
169
+ return __awaiter(this, arguments, void 0, function (updates, languages, replace) {
167
170
  if (languages === void 0) { languages = []; }
168
- if (projectID === void 0) { projectID = this.projectID; }
169
171
  if (replace === void 0) { replace = false; }
170
172
  return __generator(this, function (_a) {
171
- return [2 /*return*/, (0, _updateProjectDictionary_1.default)(this, updates, languages, projectID, replace)];
173
+ return [2 /*return*/, (0, _updateProjectDictionary_1.default)(this, updates, languages, replace)];
172
174
  });
173
175
  });
174
176
  };
175
177
  return GT;
176
178
  }());
177
179
  // ----- EXPORTS ----- //
178
- // Export the class
179
180
  exports.default = GT;
180
- // Export the functions
181
181
  /**
182
- * Gets the writing direction for a given BCP 47 language code.
183
- * @param {string} code - The BCP 47 language code to check.
184
- * @returns {string} The language direction ('ltr' for left-to-right or 'rtl' for right-to-left).
182
+ * Get the text direction for a given language code using the Intl.Locale API.
183
+ *
184
+ * @param {string} code - The language code to check.
185
+ * @returns {string} - 'rtl' if the language is right-to-left, otherwise 'ltr'.
185
186
  */
186
- var getLanguageDirection = function (code) { return (0, getLanguageDirection_1.default)(code); };
187
- exports.getLanguageDirection = getLanguageDirection;
187
+ function getLanguageDirection(code) {
188
+ return (0, codes_1._getLanguageDirection)(code);
189
+ }
190
+ ;
191
+ /**
192
+ * Retrieves the display name(s) of language code(s) using Intl.DisplayNames.
193
+ *
194
+ * @param {string | string[]} code - A language code or an array of codes.
195
+ * @param {string} [language = 'en'] - The language for display names.
196
+ * @returns {string | string[]} The display name(s) corresponding to the code(s), or empty string(s) if invalid.
197
+ */
198
+ function getLanguageName(code, language) {
199
+ return (0, codes_1._getLanguageName)(code, language);
200
+ }
201
+ ;
188
202
  /**
189
203
  * Checks if a given BCP 47 language code is valid.
190
204
  * @param {string} code - The BCP 47 language code to validate.
191
205
  * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
192
206
  */
193
- var isValidLanguageCode = function (code) { return (0, codes_1._isValidLanguageCode)(code); };
194
- exports.isValidLanguageCode = isValidLanguageCode;
207
+ function isValidLanguageCode(code) {
208
+ return (0, codes_1._isValidLanguageCode)(code);
209
+ }
210
+ ;
195
211
  /**
196
212
  * Standardizes a BCP 47 language code to ensure correct formatting.
197
213
  * @param {string} code - The BCP 47 language code to standardize.
198
214
  * @returns {string} The standardized BCP 47 language code.
199
215
  */
200
- var standardizeLanguageCode = function (code) { return (0, codes_1._standardizeLanguageCode)(code); };
201
- exports.standardizeLanguageCode = standardizeLanguageCode;
202
- function getLanguageObject(codes) {
203
- return Array.isArray(codes) ? (0, codes_1._getLanguageObject)(codes) : (0, codes_1._getLanguageObject)(codes);
204
- }
205
- function getLanguageCode(languages) {
206
- return (0, codes_1._getLanguageCode)(languages);
207
- }
208
- function getLanguageName(codes) {
209
- return (0, codes_1._getLanguageName)(codes);
216
+ function standardizeLanguageCode(code) {
217
+ return (0, codes_1._standardizeLanguageCode)(code);
210
218
  }
219
+ ;
211
220
  /**
212
221
  * Checks if multiple BCP 47 language codes represent the same language.
213
222
  * @param {string[]} codes - The BCP 47 language codes to compare.
@@ -218,7 +227,7 @@ function isSameLanguage() {
218
227
  for (var _i = 0; _i < arguments.length; _i++) {
219
228
  codes[_i] = arguments[_i];
220
229
  }
221
- return codes_1._isSameLanguage.apply(void 0, codes);
230
+ return _isSameLanguage_1.default.apply(void 0, codes);
222
231
  }
223
232
  ;
224
233
  /**
@@ -229,10 +238,10 @@ function isSameLanguage() {
229
238
  * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
230
239
  * @returns {string} The formatted number.
231
240
  */
232
- function formatNum(_a) {
233
- var value = _a.value, languages = _a.languages, options = _a.options;
234
- return (0, _format_1._formatNum)({ value: value, languages: languages, options: options });
241
+ function formatNum(params) {
242
+ return (0, format_1._formatNum)(params);
235
243
  }
244
+ ;
236
245
  /**
237
246
  * Formats a date according to the specified languages and options.
238
247
  * @param {Object} params - The parameters for the date formatting.
@@ -241,10 +250,10 @@ function formatNum(_a) {
241
250
  * @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
242
251
  * @returns {string} The formatted date.
243
252
  */
244
- function formatDateTime(_a) {
245
- var value = _a.value, languages = _a.languages, options = _a.options;
246
- return (0, _format_1._formatDateTime)({ value: value, languages: languages, options: options });
253
+ function formatDateTime(params) {
254
+ return (0, format_1._formatDateTime)(params);
247
255
  }
256
+ ;
248
257
  /**
249
258
  * Formats a currency value according to the specified languages, currency, and options.
250
259
  * @param {Object} params - The parameters for the currency formatting.
@@ -254,50 +263,63 @@ function formatDateTime(_a) {
254
263
  * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
255
264
  * @returns {string} The formatted currency value.
256
265
  */
257
- function formatCurrency(_a) {
258
- var value = _a.value, languages = _a.languages, currency = _a.currency, options = _a.options;
259
- return (0, _format_1._formatCurrency)({ value: value, languages: languages, currency: currency, options: options });
266
+ function formatCurrency(params) {
267
+ return (0, format_1._formatCurrency)(params);
260
268
  }
269
+ ;
270
+ /**
271
+ * Formats a list of items according to the specified languages and options.
272
+ * @param {Object} params - The parameters for the list formatting.
273
+ * @param {Array<string | number>} params.value - The list of items to format.
274
+ * @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
275
+ * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
276
+ * @returns {string} The formatted list.
277
+ */
278
+ function formatList(params) {
279
+ return (0, format_1._formatList)(params);
280
+ }
281
+ ;
282
+ /**
283
+ * Formats a relative time value according to the specified languages and options.
284
+ * @param {Object} params - The parameters for the relative time formatting.
285
+ * @param {number} params.value - The relative time value to format.
286
+ * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
287
+ * @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
288
+ * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
289
+ * @returns {string} The formatted relative time string.
290
+ */
291
+ function formatRelativeTime(params) {
292
+ return (0, format_1._formatRelativeTime)(params);
293
+ }
294
+ ;
261
295
  /**
262
296
  * Splits a string into an array of text and variable objects.
263
- *
264
297
  * @param {string} string - The input string to split.
265
298
  * @returns {Content} - An array containing strings and VariableObjects.
266
299
  */
267
300
  function splitStringToContent(string) {
268
- return (0, _string_content_1._splitStringToContent)(string);
301
+ return (0, string_content_1._splitStringToContent)(string);
269
302
  }
303
+ ;
270
304
  /**
271
305
  * Renders content to a string by replacing variables with their formatted values.
272
- *
273
- * @param {Content} content - The content to render, which can be a string or an array of strings and VariableObjects.
306
+ * @param {Content} content - The content to render.
274
307
  * @param {string | string[]} [languages='en'] - The language(s) to use for formatting.
275
- * @param {Record<string, any>} [variables={}] - An object containing variable values keyed by variable names.
276
- * @param {Record<string, any>} [variableOptions={}] - An object containing options for formatting variables, keyed by variable names.
308
+ * @param {Record<string, any>} [variables={}] - An object containing variable values.
309
+ * @param {Record<string, any>} [variableOptions={}] - An object containing options for formatting variables.
277
310
  * @returns {string} - The rendered string with variables replaced by their formatted values.
278
- *
279
- */
311
+ */
280
312
  function renderContentToString(content, languages, variables, variableOptions) {
281
- return (0, _string_content_1._renderContentToString)(content, languages, variables, variableOptions);
313
+ return (0, string_content_1._renderContentToString)(content, languages, variables, variableOptions);
282
314
  }
315
+ ;
283
316
  /**
284
- * Determines the best matching language from the approved languages list based on a provided
285
- * list of preferred languages. The function prioritizes exact matches, but will also consider
286
- * dialects of the same language if an exact match is not available.
287
- *
288
- * It also respects the order of preference in both the provided languages list and the
289
- * approved languages list. A dialect match of a higher-preference language is considered better
290
- * than an exact match of a lower-preference language.
291
- *
292
- * For example, if the `languages` list is ['en', 'fr'], and the `approvedLanguages` list is
293
- * ['fr', 'en-GB'], it will prefer 'en-GB' over 'fr', even though 'fr' has an exact
294
- * dialect match, because 'en' appears earlier in the `languages` list.
295
- *
317
+ * Determines the best matching language from the approved languages list based on a provided list of preferred languages.
296
318
  * @param {string | string[]} languages - A single language or an array of languages sorted in preference order.
297
319
  * @param {string[]} approvedLanguages - An array of approved languages, also sorted by preference.
298
- *
299
320
  * @returns {string | undefined} - The best matching language from the approvedLanguages list, or undefined if no match is found.
300
321
  */
301
322
  function determineLanguage(languages, approvedLanguages) {
302
- return (0, determineLanguage_1.default)(languages, approvedLanguages);
323
+ return (0, _determineLanguage_1.default)(languages, approvedLanguages);
303
324
  }
325
+ ;
@@ -0,0 +1,2 @@
1
+ declare const libraryDefaultLanguage = "en";
2
+ export default libraryDefaultLanguage;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var libraryDefaultLanguage = "en";
4
+ exports.default = libraryDefaultLanguage;
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -40,7 +40,7 @@ exports.default = _updateProjectDictionary;
40
40
  /**
41
41
  * @internal
42
42
  */
43
- function _updateProjectDictionary(gt, updates, languages, projectID, replace) {
43
+ function _updateProjectDictionary(gt, updates, languages, replace) {
44
44
  return __awaiter(this, void 0, void 0, function () {
45
45
  var response, _a, _b, _c, result;
46
46
  return __generator(this, function (_d) {
@@ -54,7 +54,6 @@ function _updateProjectDictionary(gt, updates, languages, projectID, replace) {
54
54
  body: JSON.stringify({
55
55
  updates: updates,
56
56
  languages: languages,
57
- projectID: projectID,
58
57
  replace: replace
59
58
  })
60
59
  })];
@@ -68,7 +67,7 @@ function _updateProjectDictionary(gt, updates, languages, projectID, replace) {
68
67
  case 3: return [4 /*yield*/, response.json()];
69
68
  case 4:
70
69
  result = _d.sent();
71
- return [2 /*return*/, result.languages];
70
+ return [2 /*return*/, result === null || result === void 0 ? void 0 : result.languages];
72
71
  }
73
72
  });
74
73
  });
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "2.0.67",
3
+ "version": "2.0.68",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "homepage": "https://github.com/General-Translation/generaltranslation#readme",
40
40
  "devDependencies": {
41
41
  "@types/node": "^20.14.9",
42
- "typescript": "^5.5.2"
42
+ "typescript": "^5.6.2"
43
43
  },
44
44
  "typescript": {
45
45
  "definition": "dist/index.d.ts"