javascript - I18n-js - 有没有办法检查翻译是否存在?

标签 javascript internationalization translation i18n-js

有没有办法用 I18n-js 库检查翻译是否存在?

最佳答案

您可以使用方法lookup()

当翻译不存在时返回undefined,所以你可以把它放在你的条件中。

例如:

if(!I18n.lookup('translation_key')) {
  console.log('Translation does not exist');
}
else {
  console.log('Translation does exist. Congrats.');
}

关于javascript - I18n-js - 有没有办法检查翻译是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65665076/

相关文章:

php - Doctrine2 中是否有 i18n 解决方案

python - unicode python 3 等效项

android - 旋转 Canvas 后坐标计算问题

codeigniter - 如何翻译 CodeIgniter 上的上传错误

javascript - 使用不变性助手修改数组的每个值

javascript - 获取 contenteditable 中发生 keydown 的元素

javascript - 如何在 prime ui 或 jquery datatable "columns"选项的 headerText 中包含 HTML 代码?

ruby-on-rails - 设置本地化文件中文本的样式 - 粗体、斜体等

用于匹配逗号分隔列表中的元素的 Javascript 正则表达式

javascript - 手动调用jquery mouseover函数