简体   繁体   English

添加新翻译

[英]Adding new translations

I'm using FormatJS to localize my app.我正在使用 FormatJS 来本地化我的应用程序。 There's a handy CLI to extract all the translations from the code base.有一个方便的 CLI 可以从代码库中提取所有翻译。 I can generate the en.json file, and send it to the translator.我可以生成 en.json 文件,并将其发送给翻译器。 When I get the translation back I can save this as fr.json.当我得到翻译后,我可以将其保存为 fr.json。 So far so good.到现在为止还挺好。 What I don't understand is what to do when I'm adding new translations in my app.我不明白的是当我在我的应用程序中添加新翻译时该怎么做。 When I run formatjs extract again, I get a new en.js file, with all the keys.当我再次运行formatjs extract时,我得到一个新的 en.js 文件,其中包含所有键。 Obviously I don't want to send the whole thing again to the translator.显然,我不想再将整个内容发送给翻译人员。 I could diff the new en.json against the previous version but it's such a basic step that I feel like I must be missing something?我可以将新的 en.json 与以前的版本进行比较,但这是一个非常基本的步骤,我觉得我一定遗漏了什么? I didn't find anything about this in the docs.我在文档中没有找到任何关于此的信息。 How is this part of the workflow handled with FormatJS? FormatJS 是如何处理这部分工作流程的?

It seems like translation services typically take care of diffing the data.似乎翻译服务通常会负责比较数据。 You send them the whole template file and they send back translation files will all the translated strings (new ones + ones that have already been translated).您将整个模板文件发送给他们,他们将所有已翻译的字符串(新字符串 + 已翻译字符串)发回翻译文件。 At least that's how it works with the provider my company uses.至少这就是我公司使用的提供商的工作方式。 My workflow is as follow:我的工作流程如下:

  • add new translations in the source code with intl.formatMessage()使用 intl.formatMessage() 在源代码中添加新的翻译
  • formatjs extract to create the new en.json file (template file) formatjs extract以创建新的 en.json 文件(模板文件)
  • replace the translation files (eg es.json, fr.json etc.) with the new ones from the provider用来自提供者的新文件替换翻译文件(例如 es.json、fr.json 等)
  • formatjs compile to generate the machine files formatjs compile生成机器文件

I also created a test to ensure that each key in en.json has a corresponding key in each translation file.我还创建了一个测试,以确保 en.json 中的每个键在每个翻译文件中都有一个对应的键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM