gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
15KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>54.1. For the Translator</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="nls.html" title="Chapter 54. Native Language Support" /><link rel="next" href="nls-programmer.html" title="54.2. For the Programmer" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">54.1. For the Translator</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="nls.html" title="Chapter 54. Native Language Support">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="nls.html" title="Chapter 54. Native Language Support">Up</a></td><th width="60%" align="center">Chapter 54. Native Language Support</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="nls-programmer.html" title="54.2. For the Programmer">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="NLS-TRANSLATOR"><div class="titlepage"><div><div><h2 class="title" style="clear: both">54.1. For the Translator</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="nls-translator.html#id-1.10.7.2.3">54.1.1. Requirements</a></span></dt><dt><span class="sect2"><a href="nls-translator.html#id-1.10.7.2.4">54.1.2. Concepts</a></span></dt><dt><span class="sect2"><a href="nls-translator.html#id-1.10.7.2.5">54.1.3. Creating and Maintaining Message Catalogs</a></span></dt><dt><span class="sect2"><a href="nls-translator.html#id-1.10.7.2.6">54.1.4. Editing the PO Files</a></span></dt></dl></div><p>
  3. <span class="productname">PostgreSQL</span>
  4. programs (server and client) can issue their messages in
  5. your favorite language — if the messages have been translated.
  6. Creating and maintaining translated message sets needs the help of
  7. people who speak their own language well and want to contribute to
  8. the <span class="productname">PostgreSQL</span> effort. You do not have to be a
  9. programmer at all
  10. to do this. This section explains how to help.
  11. </p><div class="sect2" id="id-1.10.7.2.3"><div class="titlepage"><div><div><h3 class="title">54.1.1. Requirements</h3></div></div></div><p>
  12. We won't judge your language skills — this section is about
  13. software tools. Theoretically, you only need a text editor. But
  14. this is only in the unlikely event that you do not want to try out
  15. your translated messages. When you configure your source tree, be
  16. sure to use the <code class="option">--enable-nls</code> option. This will
  17. also check for the <span class="application">libintl</span> library and the
  18. <code class="filename">msgfmt</code> program, which all end users will need
  19. anyway. To try out your work, follow the applicable portions of
  20. the installation instructions.
  21. </p><p>
  22. If you want to start a new translation effort or want to do a
  23. message catalog merge (described later), you will need the
  24. programs <code class="filename">xgettext</code> and
  25. <code class="filename">msgmerge</code>, respectively, in a GNU-compatible
  26. implementation. Later, we will try to arrange it so that if you
  27. use a packaged source distribution, you won't need
  28. <code class="filename">xgettext</code>. (If working from Git, you will still need
  29. it.) <span class="application">GNU Gettext 0.10.36</span> or later is currently recommended.
  30. </p><p>
  31. Your local gettext implementation should come with its own
  32. documentation. Some of that is probably duplicated in what
  33. follows, but for additional details you should look there.
  34. </p></div><div class="sect2" id="id-1.10.7.2.4"><div class="titlepage"><div><div><h3 class="title">54.1.2. Concepts</h3></div></div></div><p>
  35. The pairs of original (English) messages and their (possibly)
  36. translated equivalents are kept in <em class="firstterm">message
  37. catalogs</em>, one for each program (although related
  38. programs can share a message catalog) and for each target
  39. language. There are two file formats for message catalogs: The
  40. first is the <span class="quote">“<span class="quote">PO</span>”</span> file (for Portable Object), which
  41. is a plain text file with special syntax that translators edit.
  42. The second is the <span class="quote">“<span class="quote">MO</span>”</span> file (for Machine Object),
  43. which is a binary file generated from the respective PO file and
  44. is used while the internationalized program is run. Translators
  45. do not deal with MO files; in fact hardly anyone does.
  46. </p><p>
  47. The extension of the message catalog file is to no surprise either
  48. <code class="filename">.po</code> or <code class="filename">.mo</code>. The base
  49. name is either the name of the program it accompanies, or the
  50. language the file is for, depending on the situation. This is a
  51. bit confusing. Examples are <code class="filename">psql.po</code> (PO file
  52. for psql) or <code class="filename">fr.mo</code> (MO file in French).
  53. </p><p>
  54. The file format of the PO files is illustrated here:
  55. </p><pre class="programlisting">
  56. # comment
  57. msgid "original string"
  58. msgstr "translated string"
  59. msgid "more original"
  60. msgstr "another translated"
  61. "string can be broken up like this"
  62. ...
  63. </pre><p>
  64. The msgid's are extracted from the program source. (They need not
  65. be, but this is the most common way.) The msgstr lines are
  66. initially empty and are filled in with useful strings by the
  67. translator. The strings can contain C-style escape characters and
  68. can be continued across lines as illustrated. (The next line must
  69. start at the beginning of the line.)
  70. </p><p>
  71. The # character introduces a comment. If whitespace immediately
  72. follows the # character, then this is a comment maintained by the
  73. translator. There can also be automatic comments, which have a
  74. non-whitespace character immediately following the #. These are
  75. maintained by the various tools that operate on the PO files and
  76. are intended to aid the translator.
  77. </p><pre class="programlisting">
  78. #. automatic comment
  79. #: filename.c:1023
  80. #, flags, flags
  81. </pre><p>
  82. The #. style comments are extracted from the source file where the
  83. message is used. Possibly the programmer has inserted information
  84. for the translator, such as about expected alignment. The #:
  85. comment indicates the exact location(s) where the message is used
  86. in the source. The translator need not look at the program
  87. source, but can if there is doubt about the correct
  88. translation. The #, comments contain flags that describe the
  89. message in some way. There are currently two flags:
  90. <code class="literal">fuzzy</code> is set if the message has possibly been
  91. outdated because of changes in the program source. The translator
  92. can then verify this and possibly remove the fuzzy flag. Note
  93. that fuzzy messages are not made available to the end user. The
  94. other flag is <code class="literal">c-format</code>, which indicates that
  95. the message is a <code class="function">printf</code>-style format
  96. template. This means that the translation should also be a format
  97. string with the same number and type of placeholders. There are
  98. tools that can verify this, which key off the c-format flag.
  99. </p></div><div class="sect2" id="id-1.10.7.2.5"><div class="titlepage"><div><div><h3 class="title">54.1.3. Creating and Maintaining Message Catalogs</h3></div></div></div><p>
  100. OK, so how does one create a <span class="quote">“<span class="quote">blank</span>”</span> message
  101. catalog? First, go into the directory that contains the program
  102. whose messages you want to translate. If there is a file
  103. <code class="filename">nls.mk</code>, then this program has been prepared
  104. for translation.
  105. </p><p>
  106. If there are already some <code class="filename">.po</code> files, then
  107. someone has already done some translation work. The files are
  108. named <code class="filename"><em class="replaceable"><code>language</code></em>.po</code>,
  109. where <em class="replaceable"><code>language</code></em> is the
  110. <a class="ulink" href="https://www.loc.gov/standards/iso639-2/php/English_list.php" target="_top">
  111. ISO 639-1 two-letter language code (in lower case)</a>, e.g.,
  112. <code class="filename">fr.po</code> for French. If there is really a need
  113. for more than one translation effort per language then the files
  114. can also be named
  115. <code class="filename"><em class="replaceable"><code>language</code></em>_<em class="replaceable"><code>region</code></em>.po</code>
  116. where <em class="replaceable"><code>region</code></em> is the
  117. <a class="ulink" href="https://www.iso.org/iso-3166-country-codes.html" target="_top">
  118. ISO 3166-1 two-letter country code (in upper case)</a>,
  119. e.g.,
  120. <code class="filename">pt_BR.po</code> for Portuguese in Brazil. If you
  121. find the language you wanted you can just start working on that
  122. file.
  123. </p><p>
  124. If you need to start a new translation effort, then first run the
  125. command:
  126. </p><pre class="programlisting">
  127. make init-po
  128. </pre><p>
  129. This will create a file
  130. <code class="filename"><em class="replaceable"><code>progname</code></em>.pot</code>.
  131. (<code class="filename">.pot</code> to distinguish it from PO files that
  132. are <span class="quote">“<span class="quote">in production</span>”</span>. The <code class="literal">T</code> stands for
  133. <span class="quote">“<span class="quote">template</span>”</span>.)
  134. Copy this file to
  135. <code class="filename"><em class="replaceable"><code>language</code></em>.po</code> and
  136. edit it. To make it known that the new language is available,
  137. also edit the file <code class="filename">nls.mk</code> and add the
  138. language (or language and country) code to the line that looks like:
  139. </p><pre class="programlisting">
  140. AVAIL_LANGUAGES := de fr
  141. </pre><p>
  142. (Other languages can appear, of course.)
  143. </p><p>
  144. As the underlying program or library changes, messages might be
  145. changed or added by the programmers. In this case you do not need
  146. to start from scratch. Instead, run the command:
  147. </p><pre class="programlisting">
  148. make update-po
  149. </pre><p>
  150. which will create a new blank message catalog file (the pot file
  151. you started with) and will merge it with the existing PO files.
  152. If the merge algorithm is not sure about a particular message it
  153. marks it <span class="quote">“<span class="quote">fuzzy</span>”</span> as explained above. The new PO file
  154. is saved with a <code class="filename">.po.new</code> extension.
  155. </p></div><div class="sect2" id="id-1.10.7.2.6"><div class="titlepage"><div><div><h3 class="title">54.1.4. Editing the PO Files</h3></div></div></div><p>
  156. The PO files can be edited with a regular text editor. The
  157. translator should only change the area between the quotes after
  158. the msgstr directive, add comments, and alter the fuzzy flag.
  159. There is (unsurprisingly) a PO mode for Emacs, which I find quite
  160. useful.
  161. </p><p>
  162. The PO files need not be completely filled in. The software will
  163. automatically fall back to the original string if no translation
  164. (or an empty translation) is available. It is no problem to
  165. submit incomplete translations for inclusions in the source tree;
  166. that gives room for other people to pick up your work. However,
  167. you are encouraged to give priority to removing fuzzy entries
  168. after doing a merge. Remember that fuzzy entries will not be
  169. installed; they only serve as reference for what might be the right
  170. translation.
  171. </p><p>
  172. Here are some things to keep in mind while editing the
  173. translations:
  174. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  175. Make sure that if the original ends with a newline, the
  176. translation does, too. Similarly for tabs, etc.
  177. </p></li><li class="listitem"><p>
  178. If the original is a <code class="function">printf</code> format string, the translation
  179. also needs to be. The translation also needs to have the same
  180. format specifiers in the same order. Sometimes the natural
  181. rules of the language make this impossible or at least awkward.
  182. In that case you can modify the format specifiers like this:
  183. </p><pre class="programlisting">
  184. msgstr "Die Datei %2$s hat %1$u Zeichen."
  185. </pre><p>
  186. Then the first placeholder will actually use the second
  187. argument from the list. The
  188. <code class="literal"><em class="replaceable"><code>digits</code></em>$</code> needs to
  189. follow the % immediately, before any other format manipulators.
  190. (This feature really exists in the <code class="function">printf</code>
  191. family of functions. You might not have heard of it before because
  192. there is little use for it outside of message
  193. internationalization.)
  194. </p></li><li class="listitem"><p>
  195. If the original string contains a linguistic mistake, report
  196. that (or fix it yourself in the program source) and translate
  197. normally. The corrected string can be merged in when the
  198. program sources have been updated. If the original string
  199. contains a factual mistake, report that (or fix it yourself)
  200. and do not translate it. Instead, you can mark the string with
  201. a comment in the PO file.
  202. </p></li><li class="listitem"><p>
  203. Maintain the style and tone of the original string.
  204. Specifically, messages that are not sentences (<code class="literal">cannot
  205. open file %s</code>) should probably not start with a
  206. capital letter (if your language distinguishes letter case) or
  207. end with a period (if your language uses punctuation marks).
  208. It might help to read <a class="xref" href="error-style-guide.html" title="53.3. Error Message Style Guide">Section 53.3</a>.
  209. </p></li><li class="listitem"><p>
  210. If you don't know what a message means, or if it is ambiguous,
  211. ask on the developers' mailing list. Chances are that English
  212. speaking end users might also not understand it or find it
  213. ambiguous, so it's best to improve the message.
  214. </p></li></ul></div><p>
  215. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="nls.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="nls.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="nls-programmer.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 54. Native Language Support </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 54.2. For the Programmer</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1