Options
All
  • Public
  • Public/Protected
  • All
V1.7
  • V1.6
  • V1.7
Menu

Class LocaleHelper

Localization wrapper around ICU

Hierarchy

  • LocaleHelper

Index

Constructors

constructor

  • new LocaleHelper(locale?: string, path?: string, file?: string): LocaleHelper
  • Constructor

    Parameters

    • Optional locale: string

      default = "en"
      the locale code to initialize the helper with (E.g. "en", "en_US", "es" etc.)

    • Optional path: string

      default = "res"
      the path of the icu data file (e.g. "res")

    • Optional file: string

      default = "locale"
      the filename of the locale file (the .dat extension is not required)

    Returns LocaleHelper

Methods

formatUTF8String

  • formatUTF8String(input: string, arguments: Array<string>): string | null
  • formatUTF8String(input: string, arguments: {} | Map<string, string>): string | null
  • formatUTF8String(input: string, arguments: Array<Param>): string | null
  • formatUTF8String(input: string, arguments: {} | Map<string, Param>): string | null
  • Format a given string with the given string arguments (only string replacements are possible with this method)

    Parameters

    • input: string

      the string to format

    • arguments: Array<string>

      a vector of strings - argument names will be numbers (e.g. the first element will be named "0", the second will be "1" etc.)

    Returns string | null

    the formatted output string

  • Format a given string with the given string arguments (only string replacements are possible with this method)

    Parameters

    • input: string

      the string to format

    • arguments: {} | Map<string, string>

      a map of argument names to argument string values

    Returns string | null

    the formatted output string

  • Format a given string with the given Params

    Parameters

    • input: string

      the string to format

    • arguments: Array<Param>

      a vector of Params - argument names will be numbers (e.g. the first element will be named "0", the second will be "1" etc.)

    Returns string | null

    the formatted output string

  • Format a given string with the given Params

    Parameters

    • input: string

      the string to format

    • arguments: {} | Map<string, Param>

      a map of argument names to Params

    Returns string | null

    the formatted output string

getFormattedUTF8String

  • getFormattedUTF8String(key: string, arguments: Array<string>): string | null
  • getFormattedUTF8String(key: string, arguments: {} | Map<string, string>): string | null
  • getFormattedUTF8String(key: string, arguments: Array<Param>): string | null
  • getFormattedUTF8String(key: string, arguments: {} | Map<string, Param>): string | null
  • Locate a string in the locale data with the given key and format it with the given string arguments (only string replacements are possible with this method)

    Parameters

    • key: string

      the key of the requested localized string

    • arguments: Array<string>

      a vector of strings - argument names will be numbers (e.g. the first element will be named "0", the second will be "1" etc.)

    Returns string | null

    the formatted output string

  • Locate a string in the locale data with the given key and format it with the given string arguments (only string replacements are possible with this method)

    Parameters

    • key: string

      the key of the requested localized string

    • arguments: {} | Map<string, string>

      a map of argument names to argument string values

    Returns string | null

    the formatted output string

  • Locate a string in the locale data with the given key and format it with the given Params

    Parameters

    • key: string

      the key of the requested localized string

    • arguments: Array<Param>

      a vector of Params - argument names will be numbers (e.g. the first element will be named "0", the second will be "1" etc.)

    Returns string | null

    the formatted output string

  • Locate a string in the locale data with the given key and format it with the given Params

    Parameters

    • key: string

      the key of the requested localized string

    • arguments: {} | Map<string, Param>

      a map of argument names to Params

    Returns string | null

    the formatted output string

getLocale

  • getLocale(): string

getLocalizedPath

  • getLocalizedPath(path: string): string | null
  • Helper method to get the localized path of a resource using the LocaleHelper's current locale

    Parameters

    • path: string

      is the relative path to the resource

    Returns string | null

    the path to the resource if found

getUTF8String

  • getUTF8String(key: string): string | null
  • Retrieves a string from the locale data with the given key and performs no formatting

    Parameters

    • key: string

      the key of the requested localized string

    Returns string | null

    the requested string

init

  • init(): boolean
  • Initialize the locale helper. This or setLocale must be called before other methods are available.

    Returns boolean

    true if initialized successfully, false otherwise

setLocale

  • setLocale(locale: string): boolean
  • Change the locale of the locale helper

    Parameters

    • locale: string

      the new locale code

    Returns boolean

    true if locale data was found for the new locale, false otherwise

Generated using TypeDoc