Postgresql 中文操作指南
57.1. For the Translator #
PostgreSQL 程序(服务器和客户端)可以使用你喜欢的语言发出消息 - 如果消息已翻译。创建和维护翻译的信息集需要精通自己的语言并希望为 PostgreSQL 工作做出贡献的人员的帮助。为此,你根本不必成为程序员。本部分解释了如何提供帮助。
PostgreSQL programs (server and client) can issue their messages in your favorite language — if the messages have been translated. Creating and maintaining translated message sets needs the help of people who speak their own language well and want to contribute to the PostgreSQL effort. You do not have to be a programmer at all to do this. This section explains how to help.
57.1.1. Requirements #
我们不会判断你的语言技能 - 本部分讨论的是软件工具。理论上,你只需要一个文本编辑器。但这只适用于你不想尝试你翻译的消息的不大可能的情况。配置你的源代码树时,请务必使用 —enable-nls 选项。这还将检查 libintl 库和 msgfmt 程序,所有最终用户都需要这些库和程序。若要尝试你的工作,请按照安装说明中适用的部分进行操作。
We won’t judge your language skills — this section is about software tools. Theoretically, you only need a text editor. But this is only in the unlikely event that you do not want to try out your translated messages. When you configure your source tree, be sure to use the —enable-nls option. This will also check for the libintl library and the msgfmt program, which all end users will need anyway. To try out your work, follow the applicable portions of the installation instructions.
如果要启动新的翻译工作或要执行消息目录合并(稍后描述),你将分别需要 GNU 兼容实现中的 xgettext 和 msgmerge 程序。稍后,我们会安排好一切,以便在使用打包的源代码发行版时,你不需要 xgettext。(如果从 Git 运行,你仍需要此程序。)目前建议使用 GNU Gettext 0.10.36 或更高版本。
If you want to start a new translation effort or want to do a message catalog merge (described later), you will need the programs xgettext and msgmerge, respectively, in a GNU-compatible implementation. Later, we will try to arrange it so that if you use a packaged source distribution, you won’t need xgettext. (If working from Git, you will still need it.) GNU Gettext 0.10.36 or later is currently recommended.
你的本地 gettext 实现应附带自己的文档。其中一些可能在以下内容中重复了,但对于其他详细信息,你应查看此处。
Your local gettext implementation should come with its own documentation. Some of that is probably duplicated in what follows, but for additional details you should look there.
57.1.2. Concepts #
原始(英语)信息和其(可能)翻译等效内容的对保留在 message catalogs 中,每个程序一个(虽然相关程序可能共享一个消息目录)以及每目标语言一个。有两种消息目录文件格式:第一个是“PO”文件(用于可移植对象),它是具有特殊语法的纯文本文件,由翻译员编辑。第二个是“MO”文件(用于机器对象),它是从相应的 PO 文件生成的二进制文件并在运行国际化程序时使用。翻译员无需处理 MO 文件;实际上,几乎没人处理它们。
The pairs of original (English) messages and their (possibly) translated equivalents are kept in message catalogs, one for each program (although related programs can share a message catalog) and for each target language. There are two file formats for message catalogs: The first is the “PO” file (for Portable Object), which is a plain text file with special syntax that translators edit. The second is the “MO” file (for Machine Object), which is a binary file generated from the respective PO file and is used while the internationalized program is run. Translators do not deal with MO files; in fact hardly anyone does.
毫无疑问,消息目录文件扩展名为 .po 或 .mo。基本名称可能是其随附的程序的名称,或文件涉及的语言(取决于具体情况)。这有点令人困惑。示例是 psql.po(用于 psql 的 PO 文件)或 fr.mo(法语 MO 文件)。
The extension of the message catalog file is to no surprise either .po or .mo. The base name is either the name of the program it accompanies, or the language the file is for, depending on the situation. This is a bit confusing. Examples are psql.po (PO file for psql) or fr.mo (MO file in French).
这里对 PO 文件的文件格式做了说明:
The file format of the PO files is illustrated here:
# comment
msgid "original string"
msgstr "translated string"
msgid "more original"
msgstr "another translated"
"string can be broken up like this"
...
msgid 行从程序源中提取。(无需提取,但这最常见的方式。)msgstr 行最初为空,并由翻译员用有用的字符串填充。这些字符串可包含 C 风格的转义字符,并可以像图中那样续行。(下一行必须从行首开始。)
The msgid lines are extracted from the program source. (They need not be, but this is the most common way.) The msgstr lines are initially empty and are filled in with useful strings by the translator. The strings can contain C-style escape characters and can be continued across lines as illustrated. (The next line must start at the beginning of the line.)
字符用于引入注释。如果空格紧随 # 字符,则这是翻译员维护的注释。还可以有自动注释,其在 # 之后立即具有一个非空格字符。这些注释由对 PO 文件进行操作的各种工具来维护,其目的是帮助翻译员。
The # character introduces a comment. If whitespace immediately follows the # character, then this is a comment maintained by the translator. There can also be automatic comments, which have a non-whitespace character immediately following the #. These are maintained by the various tools that operate on the PO files and are intended to aid the translator.
#. automatic comment
#: filename.c:1023
#, flags, flags
. 样式注释从使用消息的源文件中提取。可能是程序员为翻译员插入了信息,例如关于预期对齐方式。: 注释指出消息在源中使用的确切位置。翻译员无需查看程序源,但如果有疑问,可以查看是否翻译正确。#, 注释包含以某种方式描述消息的标记。当前有两个标记:如果由于程序源中的更改,消息可能已过时,则设置 fuzzy。然后翻译员可以验证此消息,并可能删除模糊标记。请注意,模棱两可的消息不会提供给最终用户。另一个标记是 c-format,它指示消息是 printf 风格的格式模板。这意味着翻译也应是具有相同数量和类型占位符的格式字符串。有一些工具可以验证这一点,其通过 c-format 标记来区分。
The #. style comments are extracted from the source file where the message is used. Possibly the programmer has inserted information for the translator, such as about expected alignment. The #: comments indicate the exact locations where the message is used in the source. The translator need not look at the program source, but can if there is doubt about the correct translation. The #, comments contain flags that describe the message in some way. There are currently two flags: fuzzy is set if the message has possibly been outdated because of changes in the program source. The translator can then verify this and possibly remove the fuzzy flag. Note that fuzzy messages are not made available to the end user. The other flag is c-format, which indicates that the message is a printf-style format template. This means that the translation should also be a format string with the same number and type of placeholders. There are tools that can verify this, which key off the c-format flag.
57.1.3. Creating and Maintaining Message Catalogs #
那么,如何创建一个“空白”消息目录?首先,进入包含你想要翻译其消息的程序的目录。如果存在文件 nls.mk,则此程序已做好翻译准备。
OK, so how does one create a “blank” message catalog? First, go into the directory that contains the program whose messages you want to translate. If there is a file nls.mk, then this program has been prepared for translation.
如果已有一些 .po 文件,则表明有人已经做过一些翻译工作。这些文件被命名为 language.po_, where language is the ISO 639-1 two-letter language code (in lower case), e.g., fr.po for French. If there is really a need for more than one translation effort per language then the files can also be named _ language___region_.po_,其中 region 是 ISO 3166-1 two-letter country code (in upper case) ,例如 pt_BR.po 用于巴西的葡萄牙语。如果您找到了您想要使用的语言,您可以直接开始处理该文件。
If there are already some .po files, then someone has already done some translation work. The files are named language_.po_, where language is the ISO 639-1 two-letter language code (in lower case), e.g., fr.po for French. If there is really a need for more than one translation effort per language then the files can also be named language___region_.po_ where region is the ISO 3166-1 two-letter country code (in upper case), e.g., pt_BR.po for Portuguese in Brazil. If you find the language you wanted you can just start working on that file.
如果你需要开始一项新的翻译工作,那么首先运行命令:
If you need to start a new translation effort, then first run the command:
make init-po
这将创建一个文件 progname.pot_. (.pot to distinguish it from PO files that are “in production”. The T stands for “template”.) Copy this file to _ language_.po_ 并对其进行编辑。为了让大家知道新语言已经可用,也请编辑文件 po/LINGUAS ,并添加语言(或语言和国家/地区)代码,放在已列出的语言旁边,如下所示:
This will create a file progname_.pot_. (.pot to distinguish it from PO files that are “in production”. The T stands for “template”.) Copy this file to language_.po_ and edit it. To make it known that the new language is available, also edit the file po/LINGUAS and add the language (or language and country) code next to languages already listed, like:
de fr
(当然会出现其他语言。)
(Other languages can appear, of course.)
随着基础程序或库的更改,消息可能会被程序员更改或添加。在这种情况下,你无需从头开始。相反,运行命令:
As the underlying program or library changes, messages might be changed or added by the programmers. In this case you do not need to start from scratch. Instead, run the command:
make update-po
它将创建一个新的空白消息目录文件(即你最初使用的 pot 文件),并将其与现有的 PO 文件合并。如果合并算法不确定特定消息,则会将其标记为“模棱两可”,如上所述。新的 PO 文件将以 .po.new 扩展名保存。
which will create a new blank message catalog file (the pot file you started with) and will merge it with the existing PO files. If the merge algorithm is not sure about a particular message it marks it “fuzzy” as explained above. The new PO file is saved with a .po.new extension.
57.1.4. Editing the PO Files #
PO 文件可以使用常规文本编辑器进行编辑。还有多个专门用于 PO 文件的编辑器,它可以通过特定于翻译的功能帮助翻译过程。(毫不奇怪)Emacs 有一个 PO 模式,这可能相当有用。
The PO files can be edited with a regular text editor. There are also several specialized editors for PO files which can help the process with translation-specific features. There is (unsurprisingly) a PO mode for Emacs, which can be quite useful.
翻译员应仅更改 msgstr 指令后引号中的区域,添加注释并更改模糊标记。
The translator should only change the area between the quotes after the msgstr directive, add comments, and alter the fuzzy flag.
PO 文件无需完全填写。如果没有翻译(或空翻译),该软件将自动恢复到原始字符串。将未完成的翻译提交以包含在源树中不成问题;这让其他人有机会继续你的工作。但是,鼓励你在进行合并后优先级移除模糊条目。请记住,模糊条目将不会被安装;它们仅用作可能是正确翻译的参考。
The PO files need not be completely filled in. The software will automatically fall back to the original string if no translation (or an empty translation) is available. It is no problem to submit incomplete translations for inclusions in the source tree; that gives room for other people to pick up your work. However, you are encouraged to give priority to removing fuzzy entries after doing a merge. Remember that fuzzy entries will not be installed; they only serve as reference for what might be the right translation.
在编辑翻译时,需要注意以下事项:
Here are some things to keep in mind while editing the translations: