A utility class for localization and internationalization (i18n). Provides methods for locale-aware string comparison, sorting, formatting of durations, relative times, numbers, lists, and message templates.

Accessors

Methods

  • Locale-aware string comparison.

    Parameters

    • first: string

      The first string to compare.

    • second: string

      The second string to compare.

    • options: { ascii: boolean; caseInsensitive: boolean } = ...

      Normalization flags applied to both strings; both default to false.

      • ascii: boolean

        Fold accents and non-ASCII characters before comparing when true.

      • caseInsensitive: boolean

        Lowercase both strings before comparing when true.

    Returns number

    A negative number if first < second, 0 if equal, positive if first > second.

    If first or second is not a string.

  • Format an internationalized message string, optionally pluralized.

    Parameters

    • messageKey: string

      The base key to use for i18n.

    • values: PlainObject & { count?: number; ordinal?: boolean; useFallback?: boolean } = {}

      An object containing interpolation values.

      • count

        If present, plural form will be chosen.

      • ordinal

        If true, uses ordinal plural rules.

      • useFallback

        If true, uses fallback localization ("en" by default).

      • Optionalcount?: number

        If present, plural form will be chosen.

      • Optionalordinal?: boolean

        If true, uses ordinal plural rules.

      • OptionaluseFallback?: boolean

        If true, uses fallback localization ("en" by default).

    Returns string

    A formatted message string.

  • Format a duration object into a compact string (e.g., "2y 3m 5d"). Fallback to English formatting for unsupported languages.

    Parameters

    Returns string

    A formatted string.

  • Format a list with "+and" conjunction.

    Parameters

    • value: string[]

      Array of string items.

    Returns string

    A human-readable, localized list.

  • Format a list with "or" disjunction.

    Parameters

    • value: string[]

      Array of string items.

    Returns string

    A human-readable, localized list.

  • Format a number in the current locale.

    Parameters

    • value: number

      The number to format.

    Returns string

    A formatted string.

  • Format a value relative to now.

    Parameters

    • value: number

      Numeric value.

    • unit: RelativeTimeFormatUnit

      A time unit for Intl.RelativeTimeFormat.

    Returns string

    A formatted string.

  • Localizes a string based on the provided string ID using the game's internationalization system. If the string ID is not found or is invalid, it returns the string ID itself as a fallback.

    Parameters

    • stringId: string

      The ID of the string to localize. This should correspond to a key in the localization files.

    • defaultString: string = stringId

      The default string to return if the localization is not found.

    • useFallback: boolean = false

      If true, attempts to use a fallback localization if the string ID is not found. Defaults to false.

    Returns string

    The localized string if found, or the default string if not found or invalid.

  • Normalize a string for comparison or matching.

    With ascii enabled, strips combining diacritics (NFD decomposition) and collapses non-printable/non-ASCII characters to spaces; with caseInsensitive enabled, lowercases the result.

    Parameters

    • str: string

      The string to normalize.

    • options: { ascii: boolean; caseInsensitive: boolean } = ...

      Normalization flags; both default to true.

      • ascii: boolean

        Fold accents and non-ASCII characters when true.

      • caseInsensitive: boolean

        Lowercase the string when true.

    Returns string

    The normalized string, or "" for falsy input.

  • Sort an array of objects by a property using locale-aware string comparison.

    Parameters

    • objects: PlainObject[]

      The array of objects to sort.

    • key: string

      The key to sort by (dot-separated path).

    Returns PlainObject[]

    The sorted array.

  • Sort an array of strings using locale-aware string comparison.

    Parameters

    • ...ary: string[]

      The array of strings to sort.

    Returns string[]

    The sorted array.