Skip to content

I18n

Navi support to define I18n strings.

Use @ and follow by a identifier to define a I18n string.

The following statement defines the I18n string hello, which supports two languages: zh-CN and en.

nvs
@hello {
    "en" = "Hello",
    "zh-CN" = "你好"
}

Yes, we can also use string interpolation to define I18n strings:

nvs
let n = 10;

@length {
    "en" = `Length {n}`,
    "zh-CN" = `长度 {n}`
}

You can use @<identifier> to reference I18n string with current locale.

For example, the following code assigns Hello or 你好 to the variable value when the closing price is greater than the opening price, otherwise it is an empty string.

nvs
@hello {
  "en" = "Hello",
  "zh-CN" = "你好",
}

let value = quote.close > quote.open ? @hello : "";

WARNING

The string interpolation in I18n string definition is relative to the statement where the definition is referenced.

For example, the following code assigns Length 10 or 长度 10 to the variable a, and Length 20 or 长度 20 to the variable b.

nvs
@length {
  "en" = `Length {n}`,
  "zh-CN" = `长度 {n}`,
}

let n = 10;
let a = @length;
// a = "Length 10"

n = 20;
let b = @length;
// b = "Length 20"

Result:

nvs
{
  "a": "Length 10",
  "b": "Length 20"
}