更新Angular中的i18n翻译文件 [英] Updates to i18n translation files in Angular

查看:254
本文介绍了更新Angular中的i18n翻译文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在向我们公司使用的Angular应用添加语言环境。经过一番思考,我们决定采用Angular 5+本机i18n支持。



不过,据我了解,每次翻译文件都是使用 ng xi18n --outputPath src / locale / --locale en 创建一个新文件。这意味着,每次添加新的i18n标记时,已经包含旧翻译的先前XLF文件都需要与新翻译合并。



这似乎很麻烦,因此我的问题是:有没有办法将新的反式单元仅附加到已经存在的XLF文件中?还是已经有一个可以将这两者合并在一起的工具?

解决方案

编辑后的答案



您可以使用 xliffmerge 工具。在html中添加新翻译后,它可以合并翻译文件



这是教程



基本在运行后您通常的提取命令会调用xliffmerge并传递您要为其生成翻译文件的语言

  ng xi18n- outputPath src / locale / --locale en&& xliffmerge --profile xliffmerge.json zh fr 

您可以为该工具指定json配置

  {
xliffmergeOptions:{
srcDir: src / locale,
genDir: src / locale
}
}

原始答案



尝试为您的翻译设置自定义ID



https://angular.io/guide/i18n#set-a-custom -id-for-persistence-and-maintenance

 < h1 i18n = @@ introductionHeader>您好i18n!< / h1> 

Nex在您运行extract命令时,它只会添加新的块,但不会现有的



顺便说一句,我认为采用原生选项是一个不错的选择,因为主要替代方案(ngx-translate)的维护者实际上正在与角度小组合作

I am currently in the process of adding en locale to an Angular App we are using at my company. After some thinking we decided to go with the Angular 5+ native i18n support.

From how I understand it however, everytime the translation file is generated with ng xi18n --outputPath src/locale/ --locale en a new file is created. This means, that every time a new i18n tag is added, the previous XLF file which already contains the old translations, needs to be merged with the new translations.

This seems highly bothersome, therefore my question: Is there a way such that the new trans-units are just appended to the already existing XLF file? Or is there already a tool which can merge these two together?

解决方案

Edited answer

You can use the xliffmerge tool. It can merge translation files after you've added new translations in your html

Here is a tutorial for angular

Basically after running your normal extract command you call xliffmerge and pass the language(s) for which you want to generate translation files

ng xi18n --outputPath src/locale/ --locale en && xliffmerge --profile xliffmerge.json en fr

You can specify a json config for the tool

{
  "xliffmergeOptions": {
  "srcDir": "src/locale",
  "genDir": "src/locale"
   }
}

Original answer

Try setting custom ids to your translations

https://angular.io/guide/i18n#set-a-custom-id-for-persistence-and-maintenance

<h1 i18n="@@introductionHeader">Hello i18n!</h1>

Nex time you run the extract command, it'll just add the new blocks but won't touch the existing ones

Btw I think going with the native option is a good choice, since the maintainer of the main alternative (ngx-translate) is actually working with the angular team on the native approach

这篇关于更新Angular中的i18n翻译文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆