i18next和react-i18next)。不涉及本地化或服务器端。
当前设置:-默认和后备语言:en-其他语言:fr我想自动化一些与错误检查有关的东西:1.检查是否在每个定义的语言文件中翻译了所有键2.在dev env或lint中警告ci / cd。
我尝试使用以下选项进行1 .:
saveMissing: true,
saveMissingTo:"all",
missingKeyHandler: (ng, ns, key, fallbackValue) => {
console.log(ng, ns, key, fallbackValue)
},
// other options
resources: {
en: {
translations: enTranslation,
},
fr: {
translations: frTranslation,
},
},
fallbackLng: 'en',
ns: ['translations'],
defaultNS: 'translations',
interpolation: {
formatSeparator: ',',
},
react: {
wait: true,
}
我以为如果我从法语.json中删除了一个密钥(以测试它是否有效),它将被记录下来,但是只有当我删除两个密钥时,它才会被记录。[尝试其他解决方案:1. "eslint-plugin-i18n-json",但未检查我需要的内容,没有找到正确的选项/配置2.选项2.
您有任何帮助的链接或解决方案吗? (涉及saas的除外)
将此添加到您的eslintrc中:
module.exports = {
extends: ["plugin:i18n-json/recommended"],
rules: {
"i18n-json/identical-keys": [
2,
{
filePath: path.resolve("translations/en.json")
}
]
}
};
然后使用此选项运行eslint:
eslint --fix --ext .json --format node_modules/eslint-plugin-i18n-json/formatter.js translations/
这假设翻译后的文件夹称为translations
(您应该更改路径)。这里是一个代码框,表明它有效:https://codesandbox.io/s/friendly-minsky-9siu4
您可以使用终端运行
npm run lint
,并且可以使用translations/en.json
和translations/de.json
中的值进行播放以检查其工作方式。