[英]How to run formatjs compile?
How to run formatjs compile command without replacement of already translated messages?如何在不替换已翻译消息的情况下运行 formatjs 编译命令? Now I run it this way:
现在我这样运行它:
../../node_modules/.bin/formatjs compile lang/ru.json --out-file compiled-lang/ru.json
You need to have a custom formatter with your own compile function: https://formatjs.io/docs/tooling/cli/#custom-formatters你需要有一个自定义格式化程序,你自己编译 function: https://formatjs.io/docs/tooling/cli/#custom-formatters
This is what my formatter file looks like:这是我的格式化程序文件的样子:
const argv = require('yargs').argv;
const originTranslations = require(argv['out-file']);
module.exports = {
compile: function (msgs) {
const results = {};
for (const k in msgs) {
const defaultMessage = msgs[k].defaultMessage;
if (originTranslations[k]) {
results[k] = originTranslations[k];
} else if (defaultMessage) {
results[k] = defaultMessage;
} else {
results[k] = 'MISSING TRANSLATION';
}
}
return results;
},
};
You need to pass in this formatter with --format
option您需要使用
--format
选项传入此格式化程序
yarn formatjs compile lang/ru.json --out-file compiled-lang/ru.json --format <your formatter file>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.