generaltranslation 7.1.6 โ†’ 7.2.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
@@ -3,6 +3,7 @@ import { LocaleProperties } from './locales/getLocaleProperties';
3
3
  import { JsxChildren } from './internal';
4
4
  import { FileTranslationQuery } from './types-dir/checkFileTranslations';
5
5
  import { CheckTranslationStatusOptions, TranslationStatusResult } from './types-dir/translationStatus';
6
+ import { CustomRegionMapping } from './locales/getRegionProperties';
6
7
  /**
7
8
  * Type representing the constructor parameters for the GT class.
8
9
  * @typedef {Object} GTConstructorParams
@@ -58,6 +59,8 @@ export declare class GT {
58
59
  _renderingLocales: string[];
59
60
  /** Custom mapping for locale codes to their names */
60
61
  customMapping?: CustomMapping;
62
+ /** Lazily derived custom mapping for regions */
63
+ customRegionMapping?: CustomRegionMapping;
61
64
  /**
62
65
  * Constructs an instance of the GT class.
63
66
  *
@@ -406,7 +409,7 @@ export declare class GT {
406
409
  locales?: string | string[];
407
410
  } & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
408
411
  /**
409
- * Retrieves the display name of a locale code using Intl.DisplayNames.
412
+ * Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found.
410
413
  *
411
414
  * @param {string} [locale=this.targetLocale] - A BCP-47 locale code
412
415
  * @returns {string} The display name corresponding to the code
@@ -463,6 +466,48 @@ export declare class GT {
463
466
  * @property {string} emoji - The emoji associated with the locale's region, if applicable.
464
467
  */
465
468
  getLocaleProperties(locale?: string | undefined): LocaleProperties;
469
+ /**
470
+ * Retrieves multiple properties for a given region code, including:
471
+ * - `code`: the original region code
472
+ * - `name`: the localized display name
473
+ * - `emoji`: the associated flag or symbol
474
+ *
475
+ * Behavior:
476
+ * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
477
+ * - Uses the instance's `targetLocale` to localize the region name for the user.
478
+ * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
479
+ * - Otherwise, uses `Intl.DisplayNames` to get the localized region name, falling back to `libraryDefaultLocale`.
480
+ * - Falls back to the region code as `name` if display name resolution fails.
481
+ * - Falls back to a default emoji if no emoji mapping is found in built-in data or `customMapping`.
482
+ *
483
+ * @param {string} [region=this.getLocaleProperties().regionCode] - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
484
+ * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
485
+ * @returns {{ code: string, name: string, emoji: string }} An object containing:
486
+ * - `code`: the input region code
487
+ * - `name`: the localized or custom region name
488
+ * - `emoji`: the matching emoji flag or symbol
489
+ *
490
+ * @throws {Error} If no target locale is available to determine region properties.
491
+ *
492
+ * @example
493
+ * const gt = new GT({ targetLocale: 'en-US' });
494
+ * gt.getRegionProperties('US');
495
+ * // => { code: 'US', name: 'United States', emoji: '๐Ÿ‡บ๐Ÿ‡ธ' }
496
+ *
497
+ * @example
498
+ * const gt = new GT({ targetLocale: 'fr-FR' });
499
+ * gt.getRegionProperties('US');
500
+ * // => { code: 'US', name: 'ร‰tats-Unis', emoji: '๐Ÿ‡บ๐Ÿ‡ธ' }
501
+ *
502
+ * @example
503
+ * gt.getRegionProperties('US', { US: { name: 'USA', emoji: '๐Ÿ—ฝ' } });
504
+ * // => { code: 'US', name: 'USA', emoji: '๐Ÿ—ฝ' }
505
+ */
506
+ getRegionProperties(region?: string, customMapping?: CustomRegionMapping): {
507
+ code: string;
508
+ name: string;
509
+ emoji: string;
510
+ };
466
511
  /**
467
512
  * Determines whether a translation is required based on the source and target locales.
468
513
  *