Benefits of compiling po files to mo

拜拜、爱过 提交于 2021-02-08 01:50:08

问题


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

I saw many programs reading/parsing .po directly.

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

https://codex.wordpress.org/I18n_for_WordPress_Developers

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

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


回答1:


There are several reasons:

  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.


来源:https://stackoverflow.com/questions/53743208/benefits-of-compiling-po-files-to-mo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!