Interface SolutionLocalizationApi

This API is used for solution content localization.

Accessed from the window at window.sas.vi.localization.solution.

window.sas.vi.metadata.getLocalizationBundle();
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 undefined | SolutionLocalizationBundle

    The SolutionLocalizationBundle used to lookup translations if solution localization is enabled, else undefined.

  • Parameters

    • resourceKey: string

      {string} A resource key used to lookup the localized value.

    Returns undefined | string

    The localized value for the given resource key, else undefined.

    getLocalizedResource("colors.red.txt") === "rouge"
    
  • Returns boolean

    True if solution localization is enabled, else false.

    Check that solution localization is enabled. Localization methods will return unmodified inputs if isEnabled returns false. Solution localization is not available in the administration application.

  • Parameters

    • str: string

      {string} The string to localize.

    • OptionalresourceKey: string

      {string} A resource key used to lookup the localized value.

    Returns string

    The localized string.

    Localize a string using a resourceKey. Fallback to lookup by value if the resourceKey is not found or not supplied.

    localize("red", "colors.red.txt") === "rouge"
    
  • Type Parameters

    • T extends object

    Parameters

    • list: T[]

      {T[]} The objects to translate.

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

      {function(T): Record<string, string | undefined>} A 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.

    Localize a list of objects.

    localizeList(
    [{ id: "red", label: "Red" }, { id: "blue", label: "Blue"} ],
    (item) => ({ "label": `colors.${item.id}.title` })
    ) === [{ id: "red", label: "Rouge" }, { id: "blue", label: "Bleu"} ]
  • Type Parameters

    • T extends object

    Parameters

    • obj: T

      {T} The source object to localize.

    • props: Record<string, undefined | string>

      {Record<string, string | undefined>} The properties to localize and their resource keys.

    Returns T

    The localized object.

    Localize string properties of an object. Properties are provided as a map of property keys to resource keys, deep property keys are accepted.

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