跨平台本地化资源格式
我希望将替换字符串(德语、法语等)保留为标准且可在 Windows 和 Linux 平台上使用的文件格式。这样VC++资源文件就被排除了。
其他人更喜欢使用什么文件格式来保存这些本地资源?我希望格式支持的另外两个功能是:
- 用于索引 l10n 字符串的“键”本身是一个英文字符串,而不是一个枚举。
- 该格式可以携带消息摘要,因此我可以验证没有被篡改。
我的目的是使用一个函数(例如 wstring foo = GetString(L"I am %1% 岁");
)来提供 boost::format 或 boost::wformat 函数。请注意,提供给 GetString 的键是字符串,而不是枚举。
显然,我可以使用我想要的任何 XML 格式(或其他格式)。但我宁愿使用一些有点标准的东西。
I want to keep my replacement strings (German, French, etc) in a file format that is standard-ish and useable across Windows and Linux platforms. Thus VC++ resource files are ruled out right away.
What file format do others prefer to use for keeping these l10n resources? Two more features I'd like the format to support are:
- the "key" for indexing l10n strings is itself an English string, rather than an enum.
- the format can carry a message digest, so I could verify there has been no tampering.
My intent would be to use a function (e.g. wstring foo = GetString(L"I am %1% years old");
) that feeds the boost::format or boost::wformat functions. Notice that the key fed to GetString is a string, not an enum.
Obviously I can use whatever XML format (or otherwise) I'd like to dream up. But I'd rather use something that is somewhat standard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于标准格式,请使用 gettext 和 msgfmt 制作二进制 .mo 文件。该格式来自 Unix,但可以跨平台使用。 Audacity,即 Linux/Mac/Windows,都使用它。
1) 关键是英文字符串。
2) 标准格式没有防篡改方法,因此您需要自己编写。
还有一个编辑器 poEdit 和一个 emacs 模式,用于处理中间文本 .po 格式的翻译。
For a standard format, use gettext and msgfmt to make binary .mo files. The format comes from Unix, but is usable cross platform. Audacity, which is Linux/Mac/Windows, uses it.
1) The key is the English string.
2) The standard format doesn't come with an anti-tamper approach, so you will need to cook up your own.
There is also an editor, poEdit, and an emacs mode for working with the translations in the intermediate textual .po format.
我们使用了一个名为 I18N 的库(我确信有大量的实现都以相同的方式命名)。键和翻译存储在 .txt 文件中,并使用一些哈希来加快查找速度。我们对其进行了一些修改以改进上下文 - 它使用文件名上下文,因此您不能在同一文件中使用同一字符串文字的多个翻译。
用法类似于 Translated = String::Format(I18N("I am %d 岁"),years);
我们会定期针对源代码运行单独的可执行文件,以解析所有各种 I18N 条目,重新散列它们,并使用任何新添加的内容更新文件。
不幸的是,我在来源中找不到作者的任何属性。
We used a library called I18N (I'm sure there are a ton of implementations named the same way all over). The keys and translations were stored in a .txt file, and used some hash for faster lookups. We modified it some to improve the context - it used a context of filename, so you could not use multiple translations of the same string literal in the same file.
Usage was something like Translated = String::Format(I18N("I am %d years old"), years);
We would periodically run a separately executable against our sourcecode to parse out all the various I18N entries, rehash them, and update the file with any new additions.
Unfortunately I can't find any attributes to the author in the source.
不确定是否有,但如果有可能,在 lisa.org 的某处提到过:http ://www.lisa.org/Standards.30.0.html
Not sure if there is one, but if there is chances are it is mentioned somewhere at lisa.org: http://www.lisa.org/Standards.30.0.html