如何在 I18Next 中将嵌套键小写

How to lowercase a nested key in I18Next

假设我有一个翻译(在 JSON 文件中),例如:

{
    "first": "John",
    "last": "Doe",
    "welcome": "Welcome $t(first) $t(last)",
}

是否可以选择将引用的键小写? 所以它会输出 "Welcome john doe".

而不是 "Welcome John Doe"

您可以使用 get 语法。

The get syntax binds an object property to a function that will be called when that property is looked up.

var obj = {
    "first": "John",
    "last": "Doe",
    get welcome() {
      return `Welcome ${this.first.toLowerCase()} ${this.last.toLowerCase()}`;
    }
};
console.log(obj.welcome);