interface SolutionLocalizationApi {
    getLocalizationBundle(): undefined | SolutionLocalizationBundle;
    getLocalizedResource(resourceKey: string): undefined | string;
    isEnabled(): boolean;
    localize(str: string, resourceKey?: string): string;
    localizeList<T>(list: T[], getProps: ((obj: T) => Record<string, undefined | string>)): T[];
    localizeObject<T>(obj: T, props: Record<string, undefined | string>): T;
}

Methods

  • returns the localized value for the given resource key, else, undefined.

    Parameters

    • resourceKey: string

    Returns undefined | string

  • returns true if solution localization is enabled. methods will return unmodified inputs if not enabled. note that solution localization is disabled in the administration application.

    Returns boolean

  • localize a string using a resourceKey. fallback to lookup by value if the resourceKey is not supplied/found. mappings are defined by the contents of getLocalizationBundle

    Parameters

    • str: string

      string to localize

    • OptionalresourceKey: string

      a resource key used to lookup the localized value

    Returns string

    the localized string

    localize("red", "colours.red.txt") === "rouge"
    
  • localize a list of objects. localizeObject is applied to each element in the list.

    Type Parameters

    • T extends object

    Parameters

    • list: T[]

      objects to translate

    • getProps: ((obj: T) => Record<string, undefined | string>)

      callback to return a map of properties and resource keys for the given list element

        • (obj): Record<string, undefined | string>
        • Parameters

          • obj: T

          Returns Record<string, undefined | string>

    Returns T[]

    the localized list

    localizeList(
    [{ id: "red", label: "Red" }, { id: "blue", label: "Blue"} ],
    (item) => ({ "label": `colours.${item.id}.title` })
    ) === [{ id: "red", label: "Rouge" }, { id: "blue", label: "Bleu"} ]
  • localize string properties of an object, properties are provided as a map of <propertyKey, resourceKey>, deep property keys are accepted. localize is applied to each property with its given resourceKey.

    Type Parameters

    • T extends object

    Parameters

    • obj: T

      source object to localize

    • props: Record<string, undefined | string>

      properties to localize and their resource keys

    Returns T

    the localized object

    localizeObject({ label: "red" }, { "label": "colours.red.txt" }) === { label: "rouge" }