Variable InternationalizationUtilsConst

InternationalizationUtils: {
    formatCurrency(amount, currency?, locale?, options?): string;
    formatDate(date, locale?, options?): string;
    formatDateWithPattern(date, format?, locale?): string;
    formatList(list, locale?, options?): string;
    formatNumber(number, locale?, options?): string;
    formatPlural(count, locale?, options?): string;
    formatRelativeTime(date, locale?, options?): string;
    getCalendarDisplayName(calendar, locale?, options?): string;
    getCurrencyDisplayName(currency, locale?, options?): string;
    getDateTimeFieldDisplayName(field, locale?, options?): string;
    getLanguageDisplayName(language, locale?, options?): string;
    getRegionDisplayName(region, locale?, options?): string;
    getScriptDisplayName(script, locale?, options?): string;
    getUnitDisplayName(unit, locale?, options?): string;
    getUserLocale(): string;
    getUserLanguage(): string;
    getUserLanguages(): readonly string[];
    getUserTimezone(): string;
} = ...

Type declaration

  • formatCurrency:function
    • Formats a currency amount according to the specified locale and currency code.

      Parameters

      • amount: number

        The numeric amount to format

      • currency: string = "USD"

        The currency code (e.g., 'USD', 'EUR', 'JPY')

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: NumberFormatOptions = {}

        Additional Intl.NumberFormat options for customization

      Returns string

      The formatted currency string

      Example

      InternationalizationUtils.formatCurrency(99.99, 'USD', 'en-US'); // "$99.99"
      InternationalizationUtils.formatCurrency(99.99, 'EUR', 'fr-FR'); // "99,99 €"
      InternationalizationUtils.formatCurrency(1234.56, 'JPY', 'ja-JP'); // "¥1,235"
  • formatDate:function
    • Formats a date according to the specified locale and formatting options.

      Parameters

      • date: string | number | Date

        The date to format (Date object, timestamp, or date string)

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: DateTimeFormatOptions = {}

        Intl.DateTimeFormat options for customization

      Returns string

      The formatted date string

      Example

      InternationalizationUtils.formatDate(new Date(), 'en-US'); // "1/1/2024"
      InternationalizationUtils.formatDate(new Date(), 'fr-FR', { dateStyle: 'full' }); // "lundi 1 janvier 2024"
      InternationalizationUtils.formatDate(Date.now(), 'de-DE', { year: 'numeric', month: 'long' }); // "Januar 2024"
  • formatDateWithPattern:function
    • Formats a date using a specific pattern string for custom date formats.

      Parameters

      • date: string | number | Date

        The date to format (Date object, timestamp, or date string)

      • format: string = "YYYY-MM-DD"

        The format pattern string (e.g., 'YYYY-MM-DD', 'DD/MM/YYYY')

      • locale: string = navigator.language

        The locale to use (default: user's locale)

      Returns string

      The formatted date string according to the pattern

      Example

      InternationalizationUtils.formatDateWithPattern(new Date(), 'YYYY-MM-DD'); // "2024-01-01"
      InternationalizationUtils.formatDateWithPattern(new Date(), 'DD/MM/YYYY'); // "01/01/2024"
      InternationalizationUtils.formatDateWithPattern(new Date(), 'YYYY-MM-DD HH:mm:ss'); // "2024-01-01 14:30:45"
  • formatList:function
    • Formats a list of items according to locale-specific list formatting rules.

      Parameters

      • list: string[]

        Array of strings to format into a list

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: {
            type?: "conjunction" | "disjunction" | "unit";
            style?: "short" | "long" | "narrow";
        } = {}

        ListFormat options for type and style

        • Optional type?: "conjunction" | "disjunction" | "unit"

          The type of list: 'conjunction' (and), 'disjunction' (or), or 'unit'

        • Optional style?: "short" | "long" | "narrow"

          The style: 'long', 'short', or 'narrow'

      Returns string

      The formatted list string

      Example

      InternationalizationUtils.formatList(['apple', 'banana', 'orange'], 'en-US'); // "apple, banana, and orange"
      InternationalizationUtils.formatList(['red', 'blue'], 'en-US', { type: 'disjunction' }); // "red or blue"
      InternationalizationUtils.formatList(['Jan', 'Feb', 'Mar'], 'fr-FR'); // "Jan, Feb et Mar"
  • formatNumber:function
    • Formats a number according to the specified locale and formatting options.

      Parameters

      • number: number

        The number to format

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: NumberFormatOptions = {}

        Intl.NumberFormat options for customization

      Returns string

      The formatted number string

      Example

      InternationalizationUtils.formatNumber(1234.56, 'en-US'); // "1,234.56"
      InternationalizationUtils.formatNumber(1234.56, 'fr-FR'); // "1 234,56"
      InternationalizationUtils.formatNumber(0.75, 'en-US', { style: 'percent' }); // "75%"
  • formatPlural:function
    • Determines the plural rule category for a given count according to locale rules.

      Parameters

      • count: number

        The number to determine plural category for

      • locale: string = ...

        The locale to use for plural rules (default: user's locale)

      • options: PluralRulesOptions = {}

        Intl.PluralRules options

      Returns string

      The plural category: 'zero', 'one', 'two', 'few', 'many', or 'other'

      Example

      InternationalizationUtils.formatPlural(0, 'en-US'); // "other"
      InternationalizationUtils.formatPlural(1, 'en-US'); // "one"
      InternationalizationUtils.formatPlural(2, 'en-US'); // "other"
      InternationalizationUtils.formatPlural(1, 'ru-RU'); // "one"
  • formatRelativeTime:function
    • Formats a relative time string (e.g., "2 hours ago", "in 3 days") for a given date.

      Parameters

      • date: string | number | Date

        The date to format relative to now (Date object, timestamp, or date string)

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: RelativeTimeFormatOptions = {}

        Intl.RelativeTimeFormat options

      Returns string

      The formatted relative time string

      Example

      const now = new Date();
      const anHourAgo = new Date(now.getTime() - 3600000);
      InternationalizationUtils.formatRelativeTime(anHourAgo, 'en-US'); // "1 hour ago"

      const tomorrow = new Date(now.getTime() + 86400000);
      InternationalizationUtils.formatRelativeTime(tomorrow, 'en-US'); // "in 1 day"
  • getCalendarDisplayName:function
    • Gets the localized display name for a calendar system.

      Parameters

      • calendar: string

        The calendar code (e.g., 'gregory', 'buddhist', 'islamic')

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: Omit<DisplayNamesOptions, "type"> = {}

        Additional DisplayNames options for customization

      Returns string

      The localized calendar display name

      Example

      InternationalizationUtils.getCalendarDisplayName('gregory', 'en-US'); // "Gregorian Calendar"
      InternationalizationUtils.getCalendarDisplayName('buddhist', 'th-TH'); // "ปฏิทินพุทธ"
      InternationalizationUtils.getCalendarDisplayName('islamic', 'ar-SA'); // "التقويم الهجري"
  • getCurrencyDisplayName:function
    • Gets the localized display name for a currency.

      Parameters

      • currency: string

        The currency code (e.g., 'USD', 'EUR', 'JPY')

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: Omit<DisplayNamesOptions, "type"> = {}

        Additional DisplayNames options for customization

      Returns string

      The localized currency display name

      Example

      InternationalizationUtils.getCurrencyDisplayName('USD', 'en-US'); // "US Dollar"
      InternationalizationUtils.getCurrencyDisplayName('EUR', 'fr-FR'); // "euro"
      InternationalizationUtils.getCurrencyDisplayName('JPY', 'ja-JP'); // "日本円"
  • getDateTimeFieldDisplayName:function
    • Gets the localized display name for a date/time field.

      Parameters

      • field: string

        The field code (e.g., 'year', 'month', 'day', 'hour', 'minute')

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: Omit<DisplayNamesOptions, "type"> = {}

        Additional DisplayNames options for customization

      Returns string

      The localized field display name

      Example

      InternationalizationUtils.getDateTimeFieldDisplayName('year', 'en-US'); // "year"
      InternationalizationUtils.getDateTimeFieldDisplayName('month', 'fr-FR'); // "mois"
      InternationalizationUtils.getDateTimeFieldDisplayName('day', 'es-ES'); // "día"
  • getLanguageDisplayName:function
    • Gets the localized display name for a language.

      Parameters

      • language: string

        The language code (e.g., 'en', 'fr', 'es', 'zh')

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: Omit<DisplayNamesOptions, "type"> = {}

        Additional DisplayNames options for customization

      Returns string

      The localized language display name

      Example

      InternationalizationUtils.getLanguageDisplayName('en', 'en-US'); // "English"
      InternationalizationUtils.getLanguageDisplayName('fr', 'fr-FR'); // "français"
      InternationalizationUtils.getLanguageDisplayName('es', 'es-ES'); // "español"
  • getRegionDisplayName:function
    • Gets the localized display name for a region/country.

      Parameters

      • region: string

        The region/country code (e.g., 'US', 'FR', 'JP', 'GB')

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: Omit<DisplayNamesOptions, "type"> = {}

        Additional DisplayNames options for customization

      Returns string

      The localized region display name

      Example

      InternationalizationUtils.getRegionDisplayName('US', 'en-US'); // "United States"
      InternationalizationUtils.getRegionDisplayName('FR', 'fr-FR'); // "France"
      InternationalizationUtils.getRegionDisplayName('JP', 'ja-JP'); // "日本"
  • getScriptDisplayName:function
    • Gets the localized display name for a writing script.

      Parameters

      • script: string

        The script code (e.g., 'Latn', 'Cyrl', 'Arab', 'Hans')

      • locale: string = ...

        The locale to use for formatting (default: user's locale)

      • options: Omit<DisplayNamesOptions, "type"> = {}

        Additional DisplayNames options for customization

      Returns string

      The localized script display name

      Example

      InternationalizationUtils.getScriptDisplayName('Latn', 'en-US'); // "Latin"
      InternationalizationUtils.getScriptDisplayName('Cyrl', 'ru-RU'); // "кириллица"
      InternationalizationUtils.getScriptDisplayName('Arab', 'ar-SA'); // "العربية"
  • getUnitDisplayName:function
    • Gets the display names of a unit

      Parameters

      • unit: string

        Unit code (e.g., 'meter', 'kilogram')

      • locale: string = ...

        Locale to use (e.g., 'en-US', 'fr-FR')

      • options: Omit<DisplayNamesOptions, "type"> = {}

        DisplayNames options

      Returns string

      Unit display name

      Example

      getUnitDisplayName('meter', 'en-US') // 'meter'
      getUnitDisplayName('kilogram', 'fr-FR') // 'kilogramme'
  • getUserLocale:function
    • Gets the user's locale

      Returns string

      User's locale (e.g., 'en-US', 'fr-FR')

      Example

      const locale = getUserLocale(); // 'en-US'
      
  • getUserLanguage:function
    • Gets the user's preferred language

      Returns string

      User's preferred language code (e.g., 'en-US', 'fr-FR')

      Example

      const language = getUserLanguage(); // 'en-US'
      
  • getUserLanguages:function
    • Gets the user's preferred languages

      Returns readonly string[]

      Array of user's preferred language codes

      Example

      const languages = getUserLanguages(); // ['en-US', 'en', 'fr']
      
  • getUserTimezone:function
    • Gets the user's timezone

      Returns string

      User's timezone (e.g., 'America/New_York', 'Europe/Paris')

      Example

      const timezone = getUserTimezone(); // 'America/New_York'