Hierarchy

  • LocalizationPowers

Index

Methods

Static getEventLocale

  • getEventLocale(): string
  • Get the locale for the current event.

    example
    // Ensure you import the LocalizationPowers
    // import { LocalizationPowers } from "@andi/powers";
    
    const eventLocale = LocalizationPowers.getEventLocale();

    Returns string

    Event locale, such as "en-US", or null if no locale on event

Static getText

  • getText(key: string, locale?: string, formatOptions?: StringMap): string
  • Get translated text for a given key.

    throws

    {TypeError} When string key is not provided or is empty.

    throws

    {Error} When event locale is missing, and there is no valid locale argument.

    throws

    {RangeError} When locale provided is not canonical. GOOD: "en-US" BAD: "ene-xe".

    example

    This example gets the localized text for tag_description

    // Ensure you import the LocalizationPowers
    // import { LocalizationPowers } from "@andi/powers";
    
    // key: tag_description
    // translation text: Click to download report.
    const translation = LocalizationPowers.getText("tag_description");
    // Click to download report.
    example

    This example takes tokens defined in formatOptions and interpolates them into the localized text for email_subject

     // Ensure you import the LocalizationPowers
     // import { LocalizationPowers } from "@andi/powers";
    
     // key: email_subject
     // translation text:
     // {{report.name}} report has not been updated in {{days}} days
     const daysWithoutUpdate = 4;
     const report = {
         name: "TPS",
         description: "Weekly report for latest testing"
     };
     const formatOptions = {
         days: daysWithoutUpdate,
         report
     };
     const translation = LocalizationPowers
         .getText("email_subject", "en-US", formatOptions);
     // TPS report has not been updated in 4 days

    Parameters

    • key: string

      Key used to look up a translation.

    • Optional locale: string

      Optional. By default, the locale on the event is used. You can override with this parameter. You can also specify current event locale with LocalizationPowers.getEventLocale().

    • Optional formatOptions: StringMap

      Optional. Pass in values to be interpolated into your translations. Your translated text should refer to these values wrapped inside of double curly braces. Use the name of the variables that you pass in, in your translated text.

    Returns string

    Translated text or key if no translation is found.

Generated using TypeDoc