将po文件编译为Mo的好处 [英] Benefits of compiling po files to mo

查看:70
本文介绍了将po文件编译为Mo的好处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将GNU gettext .po (便携式对象)文件编译为 .mo (机器对象)的好处和主要原因是什么?

What's the benefit and primary reason for compiling GNU gettext .po (Portable Object) files to .mo (Machine Object) ?

我看到许多程序直接读取/解析 .po .

I saw many programs reading/parsing .po directly.

我没有使用wordpress,但在他们的文档中显示:

I'm not using wordpress but on their docs it says:

https://codex.wordpress.org/I18n_for_WordPress_Developers

PO文件被编译为二进制MO文件,从而可以在运行时更快地访问字符串

PO files are compiled to binary MO files, which give faster access to the strings at run-time

更快的访问是否正确?PO只能读取一次并缓存在某个哈希表中,MO可能也是如此

Is faster access true? PO can be read only once and cached in some hash table, the same probably goes for MO

推荐答案

有以下几个原因:

  1. 您应始终使用 msgfmt --check 编译PO文件,该文件对PO文件执行多项重要检查,而不仅仅是语法检查.例如,如果您使用的是printf格式的字符串,它将检查转换中的%扩展名是否与原始字符串匹配.否则,可能会导致运行时崩溃.还有很多检查,具体取决于(编程)语言.
  2. 读取二进制MO文件通常比解析文本PO文件更快,更简单.
  3. PO文件通常具有不应用于生产的翻译条目,例如模糊或过时的条目.
  4. 许多PO解析器有错误或不完整.
  5. 它是gettext API的一部分.翻译应位于/usr/share/locale/LOCALE/LC_MESSAGES/TEXTDOMAIN.mo 下,并且应采用MO格式,而不是PO格式.当然,这不适用于仅实现gettext API子集的无数库.
  1. You should always compile PO files with msgfmt --check which performs several important checks on the PO file, not only a syntax check. For example, if you you are using printf format strings, it will check that %-expansions in the translation match the original string. Failure to do so, may result in crashs at runtime. There are a lot more checks, depending on the (programming) language.
  2. Reading a binary MO file is usually faster and simpler than parsing a textual PO file.
  3. PO files often have translation entries that should not be used for production, for example fuzzy or obsolete entries.
  4. Many PO parsers are buggy or incomplete.
  5. It is part of the gettext API. Translations are expected to be located under /usr/share/locale/LOCALE/LC_MESSAGES/TEXTDOMAIN.mo and they are expected to be in MO format, not in PO format. That does, of course, not apply to the countless libraries that just implement a subset of the gettext API.

这篇关于将po文件编译为Mo的好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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