The ui18n-config.yaml file

The ui18n-config.yaml file is placed in the same directory as all other translations and contains metadata and settings for the library. It looks like this:

terms:
  - v1: 1
  - v2: 2
  - v3: 3

The terms key defines static string variables that will be used to do static interpolation into strings.

The translation format

The translation format is simple YAML. Example code showcasing all features:

translations:
  - id: normal-string
    text: "This is a normal string"
  - id: interpolated-string
    text: "This is an interpolated string. Text: {}"
  - id: statically-interpolated-with-terms
    text: "This uses a term. Text: {v1}"
  - id: dynamically-interpolated-with-variable
    text: "This uses a variable. Text: {var1}"
  - id: dynamic-interpolation-with-conditional
    text: "This uses a variable. Text: {var2}"
    switch:
      - var: var2
        default: "{var2} targets"
        cases:
          - case: "1"
            result: "1 target"

Notice how IDs are not actual strings. This is intentional to make translating easier.

Normal and interpolated string

Normal strings look like this:

- id: normal-string
  text: This is a normal string

As you can see, no special syntax is applied

Sometimes you might want to add interpolation to the string, to do this, use {} to mark the position that should be replaced by the interpolated value. Example:

- id: interpolated-string
  text: "This is an interpolated string. Values: {}, {}, {}"

Statically interpolated strings

Strings can also use static variable interpolation by interpolating terms. Example:

- id: static-interpolation
  text: "This is an interpolated string. Values: {term1}"

When the library is initialised, term1 will be substituted with its value and interpolation into this string will no longer be possible

Dynamically interpolated strings

You can also use dynamic interpolation using libraries pushed to the translation engine. Example:

- id: static-interpolation
  text: "This is an interpolated string. Values: {var1}"

Dynamically interpolated strings with conditions

When doing dynamic interpolation, you can also do conditional statements with the variable's value so that you can provide better support for cases, pluralisation and other grammatical features that require modification of parts of phrases. Example:

- id: dynamic-interpolation-with-conditional
  text: "This uses a variable. Text: {var2}"
  switch:
    - var: var2
      default: "{var2} targets"
      cases:
        - case: "1"
          result: "1 target"

As you can see, the syntax is similar to the concept of a switch case in most programming languages.