如何在.net (C#/ASP.Net) 开发中使用 xliff 或 po l10n 文件格式

发布于 2024-12-20 08:41:59 字数 476 浏览 4 评论 0原文

我一直在研究 xliffpo i18n 文件格式,看来它们被广泛使用和支持。有很多免费工具可以管理 xliff/po 文件中的翻译。

但是,到目前为止,我找不到如何在 .net (C#/ASP.Net) 项目中使用 xliff 或 po 文件的良好解决方案。我希望有某种 xliff/po =>; resx 转换器,但到目前为止还没有找到。

但同时许多工具确实支持将 xliff/po 文件转换为 java .properties 格式。

如果您有通过 .Net 项目中的 xliff 或 po 文件实现 l10n 的经验 - 请提供建议并分享其工作原理的最佳实践。

PS:我更喜欢使用 xliff 格式,因为我发现它更干净且功能更丰富,但 po 也是一种选择。

I've been researching about xliff and po i18n files formats and it seems they are widely used and supported. There are plenty of free tools to manage the translations in xliff/po files.

However, so far I could not find a good solution of how to use the xliff or po files in .net (C#/ASP.Net) projects. I would expect some sort of xliff/po => resx converter, but so far haven't found one yet.

However at the same time many tools do support the conversion of xliff/po files into java .properties format.

If you have an experience implementing l10n via xliff or po files in .Net projects - please provide advice and share the best practices on how it works.

PS: I would prefer using xliff format, since I find it cleaner and more feature-reach, but po is also an option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

彡翼 2024-12-27 08:41:59

您还可以考虑 i18n 包 by Daniel Crenna可从 nuGet 获取。它使用 PO 文件作为本地化文本的默认存储。

You could also consider the i18n package by Daniel Crenna, available from nuGet. It uses PO files as its default store for localized text.

够运 2024-12-27 08:41:59

PO 和 XLIFF 文件的工作方式通常不同:

  • PO 文件是编译为二进制格式然后使用 gettext() 库访问的资源文件。有时 PO 被用作像 XLIFF 这样的提取格式,但这不是它的最初目的。

  • XLIFF 是通过将资源文件(例如 resx)提取到 XLIFF 中创建的提取文件,然后合并回原始格式。

因此,对于 XLIFF,您应该寻找一个执行 resx -> 的工具。 xliff-> resx 而不是 xlif -> .resx.

提取/合并 XLIFF 文件的工具通常称为过滤器。有相当多的商业翻译工具可以接受 XLIFF,有些也可以创建 XLIFF(Swordfish、Trados Studio 等)。

还有一些开源工具可以提取/合并XLIFF:例如File2XLIFF4j(但我认为它不支持resx)。

来自 Okapi 项目的 Rainbow 确实支持 resx。 “旧”.net 版本(Rainbow 5:SourceForge 上的 Okapi)有一个专用于 resx 文件的过滤器,可以很好地处理它们;即使是二进制数据。不过,它可能会遇到第三方控件的问题(请参阅 http://okapi.sourceforge .net/Release/Filters/Help/netres.htm 了解详细信息)。

新的 Java 版本(Rainbow 6:http://code.google.com/p/okapi/) 通过其 XML 过滤器支持 resx,并且可以很好地处理简单的 resx,但如果其中包含二进制数据,则不会提取这些条目中的文本。

-ys

PO and XLIFF files usually work differently:

  • PO files are resource files that get complied into a binary format and then accessed using gettext() libraries. Sometimes PO is used as an extraction format like XLIFF, but that is not its original purpose.

  • XLIFF are extraction files that get created by extracting your resource file (e.g. resx) into XLIFF, and then merged back into the original format.

so for XLIFF you should be looking for a tools doing resx -> xliff -> resx rather than xlif -> resx.

The tools that extract/merge XLIFF files are usually called filters. There are quite a few commercial translation tools that will accept XLIFF, and some that can also create XLIFF (Swordfish, Trados Studio, etc.).

There are also a few open-source tools that can extract/merge XLIFF: File2XLIFF4j for example (but I don't think it supports resx).

Rainbow, from the Okapi project, does support resx. The "old" .net version (Rainbow 5: Okapi on SourceForge) has a filter dedicated to resx file and can handle them very well; even with binary data. It may run into problem with third party controls though (See http://okapi.sourceforge.net/Release/Filters/Help/netres.htm for details).

The new java version (Rainbow 6: http://code.google.com/p/okapi/) support resx through its XML filter and works fine with simple resx, but if you have binary data in them the text in those entries will not be extracted.

-ys

猫九 2024-12-27 08:41:59

在 .resx 文件开始失控后,我使用 PO 来管理 .Net 项目。我将其用作“像 XLIFF 一样的提取格式”(参见 Yves 评论)。我们现有的 .resx 文件被导出/合并为每种语言的一个 .po 文件,然后该文件成为我们的权威语言文件,所有 resx 文件将自动生成。

我正在进行的项目不是 ASP,所以我不知道 mcw0933 提到的包,但是 Mono 的 resgen.exe 实现有一些简单的 po <=>; resx转换能力。然而,为了保留现有的注释并自动添加原始文本作为额外注释,我扩展了 mono 的转换工具,以至于我使用的工具基本上被重写了。

我把扩展的 .po <=> github 上的 .resx 转换器

至于选择 .po 来管理 C# 项目的翻译,.po 简单且友好,但使用方式与 gettext 中的原始用法略有不同,存在一些不便,而且我没有经验说它是否是比 xliff 更好的选择,但能够管理翻译和自动化任务比处理 resx 文件要好得多,就像我们过去那样。

使用 PO 带来的小不便与它的意图略有不同:

  • 因为 gettext 使用 msgid 兼作存储原始未翻译字符串的字段,所以我必须使 resgenEx 将原始翻译字符串存档到附加注释中,而不是为此设计的字段目的。
  • 某些工具假设 msgid 将包含原始英文翻译(而不仅仅是 ID 字符串),这可能意味着该工具的自动错误检查选项不是很有用,或者可能意味着让您选择不同的工具,等等。但大多数工具不做任何假设。
  • 一些 .po 工具,如 \n 而不是 \r\n

我最初编写 resgenEx 的项目对于每种受支持的语言都有两个 .resx 文件和一个 .isl 文件,但很快我就需要管理 .Net 的所有翻译项目中的每个类都有多个 resx 文件。当这种情况发生时,我将决定是否应该继续使用 .po 还是应该使用 xliff 或其他东西。如果我继续使用 .po,那么我将清理 resgenEx,并且可能需要添加更多功能,例如自动将程序集名称和类名前缀添加到 msgids 的功能。

I've used PO to manage a .Net project after .resx files started getting out of hand. I used it "as an extraction format like XLIFF" (see Yves comment). Our existing .resx files were exported/merged once into one .po file per language, which then became our authoritative language files from which all the resx files would be automatically generated.

The projects I'm on aren't ASP so I don't know about the package mentioned by mcw0933, but Mono's implementation of resgen.exe has some simple po <=> resx conversion ability. However, in order to preserve existing comments and automatically add the original text as extra comments, I extended mono's conversion tool to the point where the one I use is basically rewritten.

I put the extended .po <=> .resx converter on github.

As for choosing .po to manage the translations of a C# project, .po is simple and friendly but there are some inconveniences from using it in a way that slightly differs from its original use in gettext, and I don't have the experience to say whether it was a better choice than xliff, but being able to manage translations and automate tasks was much better than dealing with the resx files, like we had been in the past.

Minor inconveniences from using PO a little differently to its intent:

  • Because gettext uses msgid to double as the field to store the original untranslated string in, I had to make resgenEx archive the original translation string into an attached comment instead of a field designed for that purpose.
  • Some tools assume the msgid will contain the original english translation (instead of just an ID string), which could mean the automatic error checking option of that tool isn't very useful, or it might mean something that makes you choose a different tool, etc. Most tools make no assumption though.
  • Some .po tools like \n instead of \r\n

The project I originally wrote resgenEx for had two .resx files and one .isl file for every supported language, but soon I'll need to manage all the translations for a .Net project that has multiple resx files for every class in the code. When this happens I'll decide whether I should keep using .po or whether I should use xliff or something else. If I keep using .po then I'll clean up resgenEx and probably need to add more features, like the ability to automatically add assembly name and class name prefixes to the msgids.

酷到爆炸 2024-12-27 08:41:59

查看 xliff-tasks。该工具从 resx 生成 xliff,并从 xliff 生成卫星程序集。

Check out xliff-tasks. The tool generates xliff from resx and satellite assemblies from xliff.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文