XLIFF 的工作流程/最佳实践

Workflow / best practices for XLIFF

我正在使用命令行工具 (ng-xi18n) 从我编写的 angular 2 应用程序中提取 i18n 字符串。此命令的输出是一个 messages.xlf 文件。来自 .po 背景,并且不熟悉 .xlf,我假设这个文件等同于 .pot 文件(如果我错了请纠正我)。

然后我假设如果我想翻译我的应用程序,我必须 cp messages.xlf messages.de.xlf 获得模板文件 (messages.xlf) 的副本 (messages.de.xlf)将每条消息翻译成德语(因此 .de.xlf)。

在翻译了一些虚拟文本和 运行 应用程序后,我看到它按预期工作,所以我停止翻译并继续开发应用程序。一段时间后,我添加了更多 i18n 字符串,最终认为我必须更新我的模板。这就是事情变得难以维护的地方。我更新了模板 messages.xlf 文件,很快就想知道如何在不丢失进度的情况下将新字符串更新到我已经翻译的 messages.de.xlf 文件中。

当我使用 .po 文件进行开发时,由于有像 poEdit 这样的好工具,这没问题,但我没有找到与 .xlf 相媲美的东西。在尝试了一些工具之后,我认为最好的选择是 Lokalize,但我也没有找到将模板文件合并到已翻译(但已过时)文件的可能性。


到目前为止,这与其说是一个问题,不如说是一篇文章,所以这里有一个简短的总结:


旁注:


提前感谢您的帮助,非常感谢

官方 Angular 文档现已更新为国际化 (i18n) https://angular.io/docs/ts/latest/cookbook/i18n.html including a section specifically for creating a translation source file with the ng-xi18n tool

到目前为止,我所见过的最好的工作流自动化解决方案来自 Roland Oldengarm 的博客条目 "Angular 2: Automated i18n workflow using gulp". To summarize, in a few dozen lines of Gulp code he created the tooling to handle some of the challenges you faced. Specifically it runs ng-xi18n to extract the messages; creates an English translation with sources copied to targets; updates existing translations by adding new trans-units, keeping existing ones, and removing missing ones; and then exposes all xlf files as TypeScript string constants. These last strings can then be imported to supply the bootstrapModule with its translation provider 选项。

警告:我自己没有使用过这个确切的解决方案(和代码),但我能够将生成的 xlf 公开为 TypeScript 字符串,并以类似于他描述的方式在应用程序中使用它们。至于维护翻译,我已经利用 IntelliJ IDEA (WebStorm) file comparison features and Counterparts Lite(对于 Mac)。我自己的努力仍处于早期阶段,但正在为一个正在积极开发的应用程序端到端地工作。

我写了一个名为 xliffmerge 的小型 npm 命令行工具。 原则上它与 Roland Oldengarm 执行他的博客文章中描述的 gulp 任务相同。 它是免费的,您可以在 https://github.com/martinroob/ngx-i18nsupport#readme

查看它