简体   繁体   English

如何运行 formatjs 编译?

[英]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.

相关问题 如何使用FormatJs消息语法将数字格式化为带有两位小数的百分比? - How to format a number to percentage with two decimals using FormatJs Message Syntax? 如何使用 FormatJS CLI 从多个特定文件夹中提取消息? - How do I extract messages from multiple specific folders with FormatJS CLI? 如何编译和运行附件的react Web应用程序? - How can I compile and run the attached react web application? 运行 npm run dev 时出现 Failed to compile 错误如何解决? - How to solve Failed to compile error when running npm run dev? 如何修复 npm run build failed to compile react js? - how to fix npm run build failed to compile react js? React-如何在编译/构建时而不是运行时运行node_modules包? - React - How to run a node_modules package at compile/build time instead of run time? i18n for react,formatjs,react-intl - i18n for react, formatjs, react-intl 如何解决 npm run build 的 React 应用程序错误“无法编译。无法缩小包。”? - How do I resolve the React app error for npm run build "Failed to compile. Failed to minify the bundle."? npm run build 上的“编译失败”错误 - "Failed to compile" error on npm run build 在项目上运行 formatjs extract 时没有返回消息。 关于为什么的任何想法? - No messages returned when running formatjs extract on project. Any ideas of why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM