generaltranslation 8.0.6 → 8.1.1

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/dist/index.d.ts CHANGED
@@ -95,11 +95,13 @@ type ActionType = 'standard' | 'fast' | string;
95
95
  *
96
96
  * @param context - The context of the request.
97
97
  * @param id - The id of the request.
98
+ * @param maxChars - The maxChars of the request.
98
99
  * @param hash - The hash of the request.
99
100
  */
100
101
  type EntryMetadata = {
101
102
  context?: string;
102
103
  id?: string;
104
+ maxChars?: number;
103
105
  hash?: string;
104
106
  dataFormat?: DataFormat;
105
107
  sourceLocale?: string;
@@ -329,7 +331,7 @@ type SubmitUserEditDiff = {
329
331
  branchId: string;
330
332
  versionId: string;
331
333
  fileId: string;
332
- localContent?: string;
334
+ localContent: string;
333
335
  };
334
336
  type SubmitUserEditDiffsPayload = {
335
337
  diffs: SubmitUserEditDiff[];
@@ -409,6 +411,23 @@ type CreateBranchResult = {
409
411
  };
410
412
  };
411
413
 
414
+ /** Type of terminator */
415
+ type CutoffFormatStyle = 'none' | 'ellipsis';
416
+ /** Terminator options */
417
+ interface TerminatorOptions {
418
+ /** The terminator to use */
419
+ terminator?: string;
420
+ /** An optional separator between the terminator and the value */
421
+ separator?: string;
422
+ }
423
+ /** Input formatting options (for constructor) */
424
+ interface CutoffFormatOptions extends TerminatorOptions {
425
+ /** Cutoff length */
426
+ maxChars?: number;
427
+ /** Type of terminator */
428
+ style?: CutoffFormatStyle;
429
+ }
430
+
412
431
  /**
413
432
  * Type representing the constructor parameters for the GT class.
414
433
  * @typedef {Object} GTConstructorParams
@@ -761,6 +780,38 @@ declare class GT {
761
780
  source: FileUpload;
762
781
  translations: FileUpload[];
763
782
  }[], options: UploadFilesOptions): Promise<UploadFilesResponse>;
783
+ /**
784
+ * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
785
+ *
786
+ * This method uses the GT instance's rendering locales by default for locale-specific terminator selection,
787
+ * but can be overridden with custom locales in the options.
788
+ *
789
+ * @param {string} value - The string value to format with cutoff behavior.
790
+ * @param {Object} [options] - Configuration options for cutoff formatting.
791
+ * @param {string | string[]} [options.locales] - The locales to use for terminator selection. Defaults to instance's rendering locales.
792
+ * @param {number} [options.maxChars] - The maximum number of characters to display.
793
+ * - Undefined values are treated as no cutoff.
794
+ * - Negative values follow .slice() behavior and terminator will be added before the value.
795
+ * - 0 will result in an empty string.
796
+ * - If cutoff results in an empty string, no terminator is added.
797
+ * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
798
+ * @param {string} [options.terminator] - Optional override the terminator to use.
799
+ * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
800
+ * - If no terminator is provided, then separator is ignored.
801
+ * @returns {string} The formatted string with terminator applied if cutoff occurs.
802
+ *
803
+ * @example
804
+ * const gt = new GT({ targetLocale: 'en-US' });
805
+ * gt.formatCutoff('Hello, world!', { maxChars: 8 });
806
+ * // Returns: 'Hello, w...'
807
+ *
808
+ * @example
809
+ * gt.formatCutoff('Hello, world!', { maxChars: -3 });
810
+ * // Returns: '...ld!'
811
+ */
812
+ formatCutoff(value: string, options?: {
813
+ locales?: string | string[];
814
+ } & CutoffFormatOptions): string;
764
815
  /**
765
816
  * Formats a message according to the specified locales and options.
766
817
  *
@@ -1096,6 +1147,46 @@ declare class GT {
1096
1147
  */
1097
1148
  isSupersetLocale(superLocale: string, subLocale: string): boolean;
1098
1149
  }
1150
+ /**
1151
+ * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
1152
+ *
1153
+ * This standalone function provides cutoff formatting functionality without requiring a GT instance.
1154
+ * The locales parameter is required for proper terminator selection based on the target language.
1155
+ *
1156
+ * @param {string} value - The string value to format with cutoff behavior.
1157
+ * @param {Object} [options] - Configuration options for cutoff formatting.
1158
+ * @param {string | string[]} [options.locales] - The locales to use for terminator selection.
1159
+ * @param {number} [options.maxChars] - The maximum number of characters to display.
1160
+ * - Undefined values are treated as no cutoff.
1161
+ * - Negative values follow .slice() behavior and terminator will be added before the value.
1162
+ * - 0 will result in an empty string.
1163
+ * - If cutoff results in an empty string, no terminator is added.
1164
+ * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
1165
+ * @param {string} [options.terminator] - Optional override the terminator to use.
1166
+ * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
1167
+ * - If no terminator is provided, then separator is ignored.
1168
+ * @returns {string} The formatted string with terminator applied if cutoff occurs.
1169
+ *
1170
+ * @example
1171
+ * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
1172
+ * // Returns: 'Hello, w...'
1173
+ *
1174
+ * @example
1175
+ * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
1176
+ * // Returns: '...ld!'
1177
+ *
1178
+ * @example
1179
+ * formatCutoff('Very long text that needs cutting', {
1180
+ * locales: 'en-US',
1181
+ * maxChars: 15,
1182
+ * style: 'ellipsis',
1183
+ * separator: ' '
1184
+ * });
1185
+ * // Returns: 'Very long text ...'
1186
+ */
1187
+ declare function formatCutoff(value: string, options?: {
1188
+ locales?: string | string[];
1189
+ } & CutoffFormatOptions): string;
1099
1190
  /**
1100
1191
  * Formats a message according to the specified locales and options.
1101
1192
  *
@@ -1347,4 +1438,4 @@ declare function isSameLanguage(...locales: (string | string[])[]): boolean;
1347
1438
  */
1348
1439
  declare function isSupersetLocale(superLocale: string, subLocale: string): boolean;
1349
1440
 
1350
- export { GT, determineLocale, formatCurrency, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, standardizeLocale };
1441
+ export { GT, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, standardizeLocale };