generaltranslation 8.0.6 → 8.1.0

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