Class Dictionary

Hierarchy

Index

Constructors

constructor

Properties

language

language: string

Optional runURL

runURL: string

Methods

applyToString

  • Apply the dictionary over a string, parsing the expressions in the string and replacing them with the values found for the respective keys inside the dictionary for a language.

    Always returns a string. Return the translated string if there are dictionary expressions, the raw string with no changes if there are no expressions, and an empty string if rawString is undefined.

    example
    const dictionary = new Dictionary({ language: "en-US", token: "my-token" });
    const result = dictionary.applyToString("Words are ignored #TEST.DICT_KEY#");

    Parameters

    • rawString: string

      String with words and/or expressions.

    • Optional options: IApplyToStringOptions

      Object containing options for the dictionary, including the language.

    Returns Promise<string>

getExpressionsFromString

  • Get all (and only) the expressions in a string and their parameters if applicable, ignoring normal words and phrases.

    example
    const dictionary = new Dictionary({ language: "en-US", token: "my-token" });
    const expressions = dictionary.getExpressionsFromString("Words are ignored #TEST.DICT_KEY#");

    Parameters

    • rawString: string

      String with words and/or expressions.

    Returns Promise<IParsedExpression[]>

getLanguagesData

  • getLanguagesData(dictionary: string, language?: string): Promise<LanguageData>

getValueFromKey

  • getValueFromKey(language: string, dictionary: string, key: string): Promise<string>
  • Get value from a key in a specific dictionary for a language.

    example
    const dictionary = new Dictionary({ language: "en-US", token: "my-token" });
    const value = dictionary.getValueFromKey("en-US", "TEST", "OK_BUTTON_LABEL");

    Parameters

    • language: string

      Name of the language (locale code).

    • dictionary: string

      Name of the dictionary.

    • key: string

      Name of the key.

    Returns Promise<string>

parseExpression

  • Parse an expression and extract the names of the dictionary, the key, and any arguments that are passed in the expression.

    example
    const dictionary = new Dictionary({ language: "en-US", token: "my-token" });
    const value = dictionary.parseExpression("#TAGORUN.WELCOME_TEXT,Hello");

    Parameters

    • expression: string

      String expression.

    Returns IParsedExpression

resolveExpression

  • Resolve an expression in a language, replacing the parameters in the dictionary value with the arguments passed in the expression.

    example
    const dictionary = new Dictionary({ language: "en-US", token: "my-token" });
    const value = dictionary.resolveExpression({
      language: "en-US",
      expression: {
        dictionary: "TEST",
        key: "SOME_KEY",
        params: [
          "first parameter",
        ],
      },
    });

    Parameters

    Returns Promise<string>