【发布时间】:2019-12-23 05:07:34
【问题描述】:
我正在尝试将变量用作使用 i18next 进行本地化的键。虽然返回了正确的字符串,但插值不起作用。
我尝试使用变量和原始字符串来查看问题出在哪里。我确信它来自i18n.t() 中变量的使用。
return newChannel.guild.channels.get(config.defaultChannel).send(i18n.t(message.content, message.options));
message 值由函数返回。这是一个sn-p:
else if (newChannel.name !== oldChannel.name) {
return message = {
content: i18n.t('events:channel.update.name.text'),
options: { oldChannel: `**#${oldChannel.name}**`, newChannel: newChannel, interpolation: { escapeValue: false }}
};
}
即json中的字符串:
"update": {
"name": {
"text": "The text channel {{oldChannel}} is now called {{newChannel}}."
}
}
它输出:The text channel is now called .
【问题讨论】:
-
你能告诉我们
message.content和message.options的内容吗?我假设一个是update.name.text,另一个应该包含oldChannel和newChannel。通常,插值是通过匹配键名来进行的,所以我会在不知道内容的情况下猜测您的内容不匹配。 -
感谢阅读!我更新了我的问题:)。
-
没有人可以帮助我吗? :(
标签: javascript node.js i18next