home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / info / gettext.info-3 < prev    next >
Encoding:
GNU Info File  |  1996-10-12  |  45.3 KB  |  968 lines

  1. This is Info file gettext.info, produced by Makeinfo-1.64 from the
  2. input file /ade-src/fsf/gettext/doc/gettext.texi.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Gettext Utilities: (gettext).        GNU gettext utilities.
  6. * gettextize: (gettext)gettextize Invocation.    Prepare a package for gettext.
  7. * msgfmt: (gettext)msgfmt Invocation.        Make MO files out of PO files.
  8. * msgmerge: (gettext)msgmerge Invocation.    Update two PO files into one.
  9. * xgettext: (gettext)xgettext Invocation.    Extract strings into a PO file.
  10. END-INFO-DIR-ENTRY
  11.  
  12.    This file provides documentation for GNU `gettext' utilities.
  13.  
  14.    Copyright (C) 1995 Free Software Foundation, Inc.
  15.  
  16.    Permission is granted to make and distribute verbatim copies of this
  17. manual provided the copyright notice and this permission notice are
  18. preserved on all copies.
  19.  
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided that
  22. the entire resulting derived work is distributed under the terms of a
  23. permission notice identical to this one.
  24.  
  25.    Permission is granted to copy and distribute translations of this
  26. manual into another language, under the above conditions for modified
  27. versions, except that this permission notice may be stated in a
  28. translation approved by the Foundation.
  29.  
  30. 
  31. File: gettext.info,  Node: Modifying Translations,  Next: Modifying Comments,  Prev: Obsolete Entries,  Up: Updating
  32.  
  33. Modifying Translations
  34. ======================
  35.  
  36.    PO mode prevents direct edition of the PO file, by the usual means
  37. Emacs give for altering a buffer's contents.  By doing so, it pretends
  38. helping the translator to avoid little clerical errors about the
  39. overall file format, or the proper quoting of strings, as those errors
  40. would be easily made.  Other kinds of errors are still possible, but
  41. some may be caught and diagnosed by the batch validation process, which
  42. the translator may always trigger by the `V' command.  For all other
  43. errors, the translator has to rely on her own judgment, and also on the
  44. linguistic reports submitted to her by the users of the translated
  45. package, having the same mother tongue.
  46.  
  47.    When the time comes to create a translation, correct an error
  48. diagnosed mechanically or reported by a user, the translators have to
  49. resort to using the following commands for modifying the translations.
  50.  
  51. `RET'
  52.      Interactively edit the translation.
  53.  
  54. `LFD'
  55.      Reinitialize the translation with the original, untranslated
  56.      string.
  57.  
  58. `k'
  59.      Save the translation on the kill ring, and delete it.
  60.  
  61. `w'
  62.      Save the translation on the kill ring, without deleting it.
  63.  
  64. `y'
  65.      Replace the translation, taking the new from the kill ring.
  66.  
  67.    The command `RET' (`po-edit-msgstr') opens a new Emacs window
  68. containing a copy of the translation taken from the current PO file
  69. entry, all ready for edition, fully modifiable and with the complete
  70. extent of GNU Emacs modifying commands.  The string is presented to the
  71. translator expunged of all quoting marks, and she will modify the
  72. *unquoted* string in this window to heart's content.  Once done, the
  73. regular Emacs command `M-C-c' (`exit-recursive-edit') may be used to
  74. return the edited translation into the PO file, replacing the original
  75. translation.  The keys `C-c C-c' are bound so they have the same effect
  76. as `M-C-c'.
  77.  
  78.    If the translator becomes unsatisfied with her translation to the
  79. extent she prefers keeping the translation which was existent prior to
  80. the `RET' command, she may use the regular Emacs command `C-]'
  81. (`abort-recursive-edit') to merely get rid of edition, while preserving
  82. the original translation.  Another way would be for her to exit
  83. normally with `C-c C-c', then type `U' once for undoing the whole
  84. effect of last edition.
  85.  
  86.    While editing her translation, the translator should pay attention to
  87. not inserting unwanted `RET' (carriage returns) characters at the end
  88. of the translated string if those are not meant to be there, or to
  89. removing such characters when they are required.  Since these
  90. characters are not visible in the editing buffer, they are easily
  91. introduced by mistake.  To help her, `RET' automatically puts the
  92. character `<' at the end of the string being edited, but this `<' is
  93. not really part of the string.  On exiting the editing window with
  94. `C-c C-c', PO mode automatically removes such `<' and all whitespace
  95. added after it.  If the translator adds characters after the
  96. terminating `<', it looses its delimiting property and integrally
  97. becomes part of the string.  If she removes the delimiting `<', then
  98. the edited string is taken *as is*, with all trailing newlines, even if
  99. invisible.  Also, if the translated string ought to end itself with a
  100. genuine `<', then the delimiting `<' may not be removed; so the string
  101. should appear, in the editing window, as ending with two `<' in a row.
  102.  
  103.    When a translation (or a comment) is being edited, the translator
  104. may move the cursor back into the PO file buffer and freely move to
  105. other entries, browsing at will.  The edited entry will be recovered as
  106. soon as the edit ceases, because it is this entry only which is being
  107. modified.  If, with an edition still opened, the translator wanders in
  108. the PO file buffer, she cannot modify any other entry.  If she tries
  109. to, PO mode will react by suggesting that she abort the current edit,
  110. or else, by inviting her to finish the current edit prior to any other
  111. modification.
  112.  
  113.    The command `LFD' (`po-msgid-to-msgstr') initializes, or
  114. reinitializes the translation with the original string.  This command
  115. is normally used when the translator wants to redo a fresh translation
  116. of the original string, disregarding any previous work.
  117.  
  118.    In fact, whether it is best to start a translation with an empty
  119. string, or rather with a copy of the original string, is a matter of
  120. taste or habit.  Sometimes, the source language and the target language
  121. are so different that is simply best to start writing on an empty page.
  122. At other times, the source and target languages are so close that it
  123. would be a waste to retype a number of words already being written in
  124. the original string.  A translator may also like having the original
  125. string right under her eyes, as she will progressively overwrite the
  126. original text with the translation, even if this requires some extra
  127. editing work to get rid of the original.
  128.  
  129.    The command `k' (`po-kill-msgstr') merely empties the translation
  130. string, so turning the entry into an untranslated one.  But while doing
  131. so, its previous contents is put apart in a special place, known as the
  132. kill ring.  The command `w' (`po-kill-ring-save-msgstr') has also the
  133. effect of taking a copy of the translation onto the kill ring, but it
  134. otherwise leaves the entry alone, and does *not* remove the translation
  135. from the entry.  Both commands use exactly the Emacs kill ring, which
  136. is shared between buffers, and which is well known already to GNU Emacs
  137. lovers.
  138.  
  139.    The translator may use `k' or `w' many times in the course of her
  140. work, as the kill ring may hold several saved translations.  From the
  141. kill ring, strings may later be reinserted in various Emacs buffers.
  142. In particular, the kill ring may be used for moving translation strings
  143. between different entries of a single PO file buffer, or if the
  144. translator is handling many such buffers at once, even between PO files.
  145.  
  146.    To facilitate exchanges with buffers which are not in PO mode, the
  147. translation string put on the kill ring by the `k' command is fully
  148. unquoted before being saved: external quotes are removed, multi-lines
  149. strings are concatenated, and backslashed escaped sequences are turned
  150. into their corresponding characters.  In the special case of obsolete
  151. entries, the translation is also uncommented prior to saving.
  152.  
  153.    The command `y' (`po-yank-msgstr') completely replaces the
  154. translation of the current entry by a string taken from the kill ring.
  155. Following GNU Emacs terminology, we then say that the replacement
  156. string is "yanked" into the PO file buffer.  *Note Yanking:
  157. (emacs)Yanking.  The first time `y' is used, the translation receives
  158. the value of the most recent addition to the kill ring.  If `y' is
  159. typed once again, immediately, without intervening keystrokes, the
  160. translation just inserted is taken away and replaced by the second most
  161. recent addition to the kill ring.  By repeating `y' many times in a row,
  162. the translator may travel along the kill ring for saved strings, until
  163. she finds the string she really wanted.
  164.  
  165.    When a string is yanked into a PO file entry, it is fully and
  166. automatically requoted for complying with the format PO files should
  167. have.  Further, if the entry is obsolete, PO mode then appropriately
  168. push the inserted string inside comments.  Once again, translators
  169. should not burden themselves with quoting considerations besides, of
  170. course, the necessity of the translated string itself respective to the
  171. program using it.
  172.  
  173.    Note that `k' or `w' are not the only commands pushing strings on
  174. the kill ring, as almost any PO mode command replacing translation
  175. strings (or the translator comments) automatically save the old string
  176. on the kill ring.  The main exceptions to this general rule are the
  177. yanking commands themselves.
  178.  
  179.    To better illustrate the operation of killing and yanking, let's use
  180. an actual example, taken from a common situation.  When the programmer
  181. slightly modifies some string right in the program, his change is later
  182. reflected in the PO file by the appearance of a new untranslated entry
  183. for the modified string, and the fact that the entry translating the
  184. original or unmodified string becomes obsolete.  In many cases, the
  185. translator might spare herself some work by retrieving the unmodified
  186. translation from the obsolete entry, then initializing the untranslated
  187. entry `msgstr' field with this retrieved translation.  Once this done,
  188. the obsolete entry is not wanted anymore, and may be safely deleted.
  189.  
  190.    When the translator finds an untranslated entry and suspects that a
  191. slight variant of the translation exists, she immediately uses `m' to
  192. mark the current entry location, then starts chasing obsolete entries
  193. with `o', hoping to find some translation corresponding to the
  194. unmodified string.  Once found, she uses the `z' command for deleting
  195. the obsolete entry, knowing that `z' also *kills* the translation, that
  196. is, pushes the translation on the kill ring.  Then, `r' returns to the
  197. initial untranslated entry, `y' then *yanks* the saved translation
  198. right into the `msgstr' field.  The translator is then free to use
  199. `RET' for fine tuning the translation contents, and maybe to later use
  200. `u', then `m' again, for going on with the next untranslated string.
  201.  
  202.    When some sequence of keys has to be typed over and over again, the
  203. translator may find it useful to become better acquainted with the GNU
  204. Emacs capability of learning these sequences and playing them back under
  205. request.  *Note Keyboard Macros: (emacs)Keyboard Macros.
  206.  
  207. 
  208. File: gettext.info,  Node: Modifying Comments,  Next: Auxiliary,  Prev: Modifying Translations,  Up: Updating
  209.  
  210. Modifying Comments
  211. ==================
  212.  
  213.    Any translation work done seriously will raise many linguistic
  214. difficulties, for which decisions have to be made, and the choices
  215. further documented.  These documents may be saved within the PO file in
  216. form of translator comments, which the translator is free to create,
  217. delete, or modify at will.  These comments may be useful to herself
  218. when she returns to this PO file after a while.
  219.  
  220.    The following commands are somewhat similar to those modifying
  221. translations, so the general indications given for those apply here.
  222. *Note Modifying Translations::.
  223.  
  224. `#'
  225.      Interactively edit the translator comments.
  226.  
  227. `K'
  228.      Save the translator comments on the kill ring, and delete it.
  229.  
  230. `W'
  231.      Save the translator comments on the kill ring, without deleting it.
  232.  
  233. `Y'
  234.      Replace the translator comments, taking the new from the kill ring.
  235.  
  236.    These commands parallel PO mode commands for modifying the
  237. translation strings, and behave much the same way as they do, except
  238. that they handle this part of PO file comments meant for translator
  239. usage, rather than the translation strings.  So, if the descriptions
  240. given below are slightly succinct, it is because the full details have
  241. already been given.  *Note Modifying Translations::.
  242.  
  243.    The command `#' (`po-edit-comment') opens a new Emacs window
  244. containing a copy of the translator comments on the current PO file
  245. entry.  If there are no such comments, PO mode understands that the
  246. translator wants to add a comment to the entry, and she is presented
  247. with an empty screen.  Comment marks (`#') and the space following them
  248. are automatically removed before edition, and reinstated after.  For
  249. translator comments pertaining to obsolete entries, the uncommenting
  250. and recommenting operations are done twice.  Once in the editing
  251. window, the keys `C-c C-c' allow the translator to tell she is finished
  252. with editing the comment.
  253.  
  254.    The command `K' (`po-kill-comment') get rid of all translator
  255. comments, while saving those comments on the kill ring.  The command
  256. `W' (`po-kill-ring-save-comment') takes a copy of the translator
  257. comments on the kill ring, but leaves them undisturbed in the current
  258. entry.  The command `Y' (`po-yank-comment') completely replaces the
  259. translator comments by a string taken at the front of the kill ring.
  260. When this command is immediately repeated, the comments just inserted
  261. are withdrawn, and replaced by other strings taken along the kill ring.
  262.  
  263.    On the kill ring, all strings have the same nature.  There is no
  264. distinction between *translation* strings and *translator comments*
  265. strings.  So, for example, let's presume the translator has just
  266. finished editing a translation, and wants to create a new translator
  267. comment to document why the previous translation was not good, just to
  268. remember what was the problem.  Foreseeing that she will do that in her
  269. documentation, the translator may want to quote the previous
  270. translation in her translator comments.  To do so, she may initialize
  271. the translator comments with the previous translation, still at the
  272. head of the kill ring.  Because editing already pushed the previous
  273. translation on the kill ring, she merely has to type `M-w' prior to
  274. `#', and the previous translation will be right there, all ready for
  275. being introduced by some explanatory text.
  276.  
  277.    On the other hand, presume there are some translator comments already
  278. and that the translator wants to add to those comments, instead of
  279. wholly replacing them.  Then, she should edit the comment right away
  280. with `#'.  Once inside the editing window, she can use the regular GNU
  281. Emacs commands `C-y' (`yank') and `M-y' (`yank-pop') to get the
  282. previous translation where she likes.
  283.  
  284. 
  285. File: gettext.info,  Node: Auxiliary,  Prev: Modifying Comments,  Up: Updating
  286.  
  287. Consulting Auxiliary PO Files
  288. =============================
  289.  
  290.    An incoming feature of PO mode should help the knowledgeable
  291. translator to take advantage of translations already achieved in other
  292. languages she just happens to know, by providing these other language
  293. translation as additional context for her own work.  Each PO file
  294. existing for the same package the translator is working on, but
  295. targeted to a different mother tongue language, is called an
  296. "auxiliary" PO file.  Commands will exist for declaring and handling
  297. auxiliary PO files, and also for showing contexts for the entry under
  298. work.  For this to work fully, all auxiliary PO files will have to be
  299. normalized.
  300.  
  301. 
  302. File: gettext.info,  Node: Binaries,  Next: Users,  Prev: Updating,  Up: Top
  303.  
  304. Producing Binary MO Files
  305. *************************
  306.  
  307. * Menu:
  308.  
  309. * msgfmt Invocation::           Invoking the `msgfmt' Program
  310. * MO Files::                    The Format of GNU MO Files
  311.  
  312. 
  313. File: gettext.info,  Node: msgfmt Invocation,  Next: MO Files,  Prev: Binaries,  Up: Binaries
  314.  
  315. Invoking the `msgfmt' Program
  316. =============================
  317.  
  318.      Usage: msgfmt [OPTION] FILENAME.po ...
  319.  
  320. `-a NUMBER'
  321. `--alignment=NUMBER'
  322.      Align strings to NUMBER bytes (default: 1).
  323.  
  324. `-h'
  325. `--help'
  326.      Display this help and exit.
  327.  
  328. `--no-hash'
  329.      Binary file will not include the hash table.
  330.  
  331. `-o FILE'
  332. `--output-file=FILE'
  333.      Specify output file name as FILE.
  334.  
  335. `--strict'
  336.      Direct the program to work strictly following the Uniforum/Sun
  337.      implementation.  Currently this only affects the naming of the
  338.      output file.  If this option is not given the name of the output
  339.      file is the same as the domain name.  If the strict Uniforum mode
  340.      is enable the suffix `.mo' is added to the file name if it is not
  341.      already present.
  342.  
  343.      We find this behaviour of Sun's implementation rather silly and so
  344.      by default this mode is *not* selected.
  345.  
  346. `-v'
  347. `--verbose'
  348.      Detect and diagnose input file anomalies which might represent
  349.      translation errors.  The `msgid' and `msgstr' strings are studied
  350.      and compared.  It is considered abnormal that one string starts or
  351.      ends with a newline while the other does not.
  352.  
  353.      Also, if the string represents a format sring used in a
  354.      `printf'-like function both strings should have the same number of
  355.      `%' format specifiers, with matching types.  If the flag
  356.      `c-format' or `possible-c-format' appears in the special comment
  357.      #, for this entry a check is performed.  For example, the check
  358.      will diagnose using `%.*s' against `%s', or `%d' against `%s', or
  359.      `%d' against `%x'.  It can even handle positional parameters.
  360.  
  361.      Normally the `xgettext' program automatically decides whether a
  362.      string is a format string or not.  This algorithm is not perfect,
  363.      though.  It might regard a string as a format string though it is
  364.      not used in a `printf'-like function and so `msgfmt' might report
  365.      errors where there are none.  Or the other way round: a string is
  366.      not regarded as a format string but it is used in a `printf'-like
  367.      function.
  368.  
  369.      So solve this problem the programmer can dictate the decision to
  370.      the `xgettext' program (*note c-format::.).  The translator should
  371.      not consider removing the flag from the #, line.  This "fix" would
  372.      be reversed again as soon as `msgmerge' is called the next time.
  373.  
  374. `-V'
  375. `--version'
  376.      Output version information and exit.
  377.  
  378.    If input file is `-', standard input is read.  If output file is
  379. `-', output is written to standard output.
  380.  
  381. 
  382. File: gettext.info,  Node: MO Files,  Prev: msgfmt Invocation,  Up: Binaries
  383.  
  384. The Format of GNU MO Files
  385. ==========================
  386.  
  387.    The format of the generated MO files is best described by a picture,
  388. which appears below.
  389.  
  390.    The first two words serve the identification of the file.  The magic
  391. number will always signal GNU MO files.  The number is stored in the
  392. byte order of the generating machine, so the magic number really is two
  393. numbers: `0x950412de' and `0xde120495'.  The second word describes the
  394. current revision of the file format.  For now the revision is 0.  This
  395. might change in future versions, and ensures that the readers of MO
  396. files can distinguish new formats from old ones, so that both can be
  397. handled correctly.  The version is kept separate from the magic number,
  398. instead of using different magic numbers for different formats, mainly
  399. because `/etc/magic' is not updated often.  It might be better to have
  400. magic separated from internal format version identification.
  401.  
  402.    Follow a number of pointers to later tables in the file, allowing
  403. for the extension of the prefix part of MO files without having to
  404. recompile programs reading them.  This might become useful for later
  405. inserting a few flag bits, indication about the charset used, new
  406. tables, or other things.
  407.  
  408.    Then, at offset O and offset T in the picture, two tables of string
  409. descriptors can be found.  In both tables, each string descriptor uses
  410. two 32 bits integers, one for the string length, another for the offset
  411. of the string in the MO file, counting in bytes from the start of the
  412. file.  The first table contains descriptors for the original strings,
  413. and is sorted so the original strings are in increasing lexicographical
  414. order.  The second table contains descriptors for the translated
  415. strings, and is parallel to the first table: to find the corresponding
  416. translation one has to access the array slot in the second array with
  417. the same index.
  418.  
  419.    Having the original strings sorted enables the use of simple binary
  420. search, for when the MO file does not contain an hashing table, or for
  421. when it is not practical to use the hashing table provided in the MO
  422. file.  This also has another advantage, as the empty string in a PO
  423. file GNU `gettext' is usually *translated* into some system information
  424. attached to that particular MO file, and the empty string necessarily
  425. becomes the first in both the original and translated tables, making
  426. the system information very easy to find.
  427.  
  428.    The size S of the hash table can be zero.  In this case, the hash
  429. table itself is not contained in the MO file.  Some people might prefer
  430. this because a precomputed hashing table takes disk space, and does not
  431. win *that* much speed.  The hash table contains indices to the sorted
  432. array of strings in the MO file.  Conflict resolution is done by double
  433. hashing.  The precise hashing algorithm used is fairly dependent of GNU
  434. `gettext' code, and is not documented here.
  435.  
  436.    As for the strings themselves, they follow the hash file, and each
  437. is terminated with a NUL, and this NUL is not counted in the length
  438. which appears in the string descriptor.  The `msgfmt' program has an
  439. option selecting the alignment for MO file strings.  With this option,
  440. each string is separately aligned so it starts at an offset which is a
  441. multiple of the alignment value.  On some RISC machines, a correct
  442. alignment will speed things up.
  443.  
  444.    Nothing prevents a MO file from having embedded NULs in strings.
  445. However, the program interface currently used already presumes that
  446. strings are NUL terminated, so embedded NULs are somewhat useless.  But
  447. MO file format is general enough so other interfaces would be later
  448. possible, if for example, we ever want to implement wide characters
  449. right in MO files, where NUL bytes may accidently appear.
  450.  
  451.    This particular issue has been strongly debated in the GNU `gettext'
  452. development forum, and it is expectable that MO file format will evolve
  453. or change over time.  It is even possible that many formats may later
  454. be supported concurrently.  But surely, we have to start somewhere, and
  455. the MO file format described here is a good start.  Nothing is cast in
  456. concrete, and the format may later evolve fairly easily, so we should
  457. feel comfortable with the current approach.
  458.  
  459.              byte
  460.                   +------------------------------------------+
  461.                0  | magic number = 0x950412de                |
  462.                   |                                          |
  463.                4  | file format revision = 0                 |
  464.                   |                                          |
  465.                8  | number of strings                        |  == N
  466.                   |                                          |
  467.               12  | offset of table with original strings    |  == O
  468.                   |                                          |
  469.               16  | offset of table with translation strings |  == T
  470.                   |                                          |
  471.               20  | size of hashing table                    |  == S
  472.                   |                                          |
  473.               24  | offset of hashing table                  |  == H
  474.                   |                                          |
  475.                   .                                          .
  476.                   .    (possibly more entries later)         .
  477.                   .                                          .
  478.                   |                                          |
  479.                O  | length & offset 0th string  ----------------.
  480.            O + 8  | length & offset 1st string  ------------------.
  481.                    ...                                    ...   | |
  482.      O + ((N-1)*8)| length & offset (N-1)th string           |  | |
  483.                   |                                          |  | |
  484.                T  | length & offset 0th translation  ---------------.
  485.            T + 8  | length & offset 1st translation  -----------------.
  486.                    ...                                    ...   | | | |
  487.      T + ((N-1)*8)| length & offset (N-1)th translation      |  | | | |
  488.                   |                                          |  | | | |
  489.                H  | start hash table                         |  | | | |
  490.                    ...                                    ...   | | | |
  491.        H + S * 4  | end hash table                           |  | | | |
  492.                   |                                          |  | | | |
  493.                   | NUL terminated 0th string  <----------------' | | |
  494.                   |                                          |    | | |
  495.                   | NUL terminated 1st string  <------------------' | |
  496.                   |                                          |      | |
  497.                    ...                                    ...       | |
  498.                   |                                          |      | |
  499.                   | NUL terminated 0th translation  <---------------' |
  500.                   |                                          |        |
  501.                   | NUL terminated 1st translation  <-----------------'
  502.                   |                                          |
  503.                    ...                                    ...
  504.                   |                                          |
  505.                   +------------------------------------------+
  506.  
  507. 
  508. File: gettext.info,  Node: Users,  Next: Programmers,  Prev: Binaries,  Up: Top
  509.  
  510. The User's View
  511. ***************
  512.  
  513.    When GNU `gettext' will truly have reached is goal, average users
  514. should feel some kind of astonished pleasure, seeing the effect of that
  515. strange kind of magic that just makes their own native language appear
  516. everywhere on their screens.  As for naive users, they would ideally
  517. have no special pleasure about it, merely taking their own language for
  518. *granted*, and becoming rather unhappy otherwise.
  519.  
  520.    So, let's try to describe here how we would like the magic to
  521. operate, as we want the users' view to be the simplest, among all ways
  522. one could look at GNU `gettext'.  All other software engineers:
  523. programmers, translators, maintainers, should work together in such a
  524. way that the magic becomes possible.  This is a long and progressive
  525. undertaking, and information is available about the progress of the GNU
  526. Translation Project.
  527.  
  528.    When a package is distributed, there are two kind of users:
  529. "installers" who fetch the distribution, unpack it, configure it,
  530. compile it and install it for themselves or others to use; and "end
  531. users" that call programs of the package, once these have been
  532. installed at their site.  GNU `gettext' is offering magic for both
  533. installers and end users.
  534.  
  535. * Menu:
  536.  
  537. * Matrix::                      The Current `NLS' Matrix for GNU
  538. * Installers::                  Magic for Installers
  539. * End Users::                   Magic for End Users
  540.  
  541. 
  542. File: gettext.info,  Node: Matrix,  Next: Installers,  Prev: Users,  Up: Users
  543.  
  544. The Current `NLS' Matrix for GNU
  545. ================================
  546.  
  547.    Languages are not equally supported in all GNU packages.  To know if
  548. some GNU package uses GNU `gettext', one may check the distribution for
  549. the `NLS' information file, for some `LL.po' files, often kept together
  550. into some `po/' directory, or for an `intl/' directory.
  551. Internationalized packages have usually many `LL.po' files, where LL
  552. represents the language.  *Note End Users:: for a complete description
  553. of the format for LL.
  554.  
  555.    More generally, a matrix is available for showing the current state
  556. of GNU internationalization, listing which packages are prepared for
  557. multi-lingual messages, and which languages is supported by each.
  558. Because this information changes often, this matrix is not kept within
  559. this GNU `gettext' manual.  This information is often found in file
  560. `NLS' from various GNU distributions, but is also as old as the
  561. distribution itself.  A recent copy of this `NLS' file, containing
  562. up-to-date information, should generally be found on most GNU archive
  563. sites.
  564.  
  565. 
  566. File: gettext.info,  Node: Installers,  Next: End Users,  Prev: Matrix,  Up: Users
  567.  
  568. Magic for Installers
  569. ====================
  570.  
  571.    By default, packages fully using GNU `gettext', internally, are
  572. installed in such a way that they to allow translation of messages.  At
  573. *configuration* time, those packages should automatically detect
  574. whether the underlying host system provides usable `catgets' or
  575. `gettext' functions.  If neither is present, the GNU `gettext' library
  576. should be automatically prepared and used.  Installers may use special
  577. options at configuration time for changing this behavior.  The command
  578. `./configure --with-included-gettext' bypasses system `catgets' or
  579. `gettext' to use GNU `gettext' instead, while `./configure
  580. --disable-nls' produces program totally unable to translate messages.
  581.  
  582.    Internationalized packages have usually many `LL.po' files.  Unless
  583. translations are disabled, all those available are installed together
  584. with the package.  However, the environment variable `LINGUAS' may be
  585. set, prior to configuration, to limit the installed set.  `LINGUAS'
  586. should then contain a space separated list of two-letter codes, stating
  587. which languages are allowed.
  588.  
  589. 
  590. File: gettext.info,  Node: End Users,  Prev: Installers,  Up: Users
  591.  
  592. Magic for End Users
  593. ===================
  594.  
  595.    We consider here those packages using GNU `gettext' internally, and
  596. for which the installers did not disable translation at *configure*
  597. time.  Then, users only have to set the `LANG' environment variable to
  598. the appropriate `LL' prior to using the programs in the package.  *Note
  599. Matrix::.  For example, let's presume a German site.  At the shell
  600. prompt, users merely have to execute `setenv LANG de' (in `csh') or
  601. `export LANG; LANG=de' (in `sh').  They could even do this from their
  602. `.login' or `.profile' file.
  603.  
  604. 
  605. File: gettext.info,  Node: Programmers,  Next: Translators,  Prev: Users,  Up: Top
  606.  
  607. The Programmer's View
  608. *********************
  609.  
  610.    One aim of the current message catalog implementation provided by
  611. GNU `gettext' was to use the systems message catalog handling, if the
  612. installer wishes to do so.  So we perhaps should first take a look at
  613. the solutions we know about.  The people in the POSIX committee does not
  614. manage to agree on one of the semi-official standards which we'll
  615. describe below.  In fact they couldn't agree on anything, so nothing
  616. decide only to include an example of an interface.  The major Unix
  617. vendors are split in the usage of the two most important
  618. specifications: X/Opens catgets vs. Uniforums gettext interface.  We'll
  619. describe them both and later explain our solution of this dilemma.
  620.  
  621. * Menu:
  622.  
  623. * catgets::                     About `catgets'
  624. * gettext::                     About `gettext'
  625. * Comparison::                  Comparing the two interfaces
  626. * Using libintl.a::             Using libintl.a in own programs
  627. * gettext grok::                Being a `gettext' grok
  628. * Temp Programmers::            Temporary Notes for the Programmers Chapter
  629.  
  630. 
  631. File: gettext.info,  Node: catgets,  Next: gettext,  Prev: Programmers,  Up: Programmers
  632.  
  633. About `catgets'
  634. ===============
  635.  
  636.    The `catgets' implementation is defined in the X/Open Portability
  637. Guide, Volume 3, XSI Supplementary Definitions, Chapter 5.  But the
  638. process of creating this standard seemed to be too slow for some of the
  639. Unix vendors so they created their implementations on preliminary
  640. versions of the standard.  Of course this leads again to problems while
  641. writing platform independent programs: even the usage of `catgets' does
  642. not guarantee a unique interface.
  643.  
  644.    Another, personal comment on this that only a bunch of committee
  645. members could have made this interface.  They never really tried to
  646. program using this interface.  It is a fast, memory-saving
  647. implementation, an user can happily live with it.  But programmers hate
  648. it (at least me and some others do...)
  649.  
  650.    But we must not forget one point: after all the trouble with
  651. transfering the rights on Unix(tm) they at last came to X/Open, the
  652. very same who published this specifications.  This leads me to making
  653. the prediction that this interface will be in future Unix standards
  654. (e.g. Spec1170) and therefore part of all Unix implementation
  655. (implementations, which are *allowed* to wear this name).
  656.  
  657. * Menu:
  658.  
  659. * Interface to catgets::        The interface
  660. * Problems with catgets::       Problems with the `catgets' interface?!
  661.  
  662. 
  663. File: gettext.info,  Node: Interface to catgets,  Next: Problems with catgets,  Prev: catgets,  Up: catgets
  664.  
  665. The Interface
  666. -------------
  667.  
  668.    The interface to the `catgets' implementation consists of three
  669. functions which correspond to those used in file access: `catopen' to
  670. open the catalog for using, `catgets' for accessing the message tables,
  671. and `catclose' for closing after work is done.  Prototypes for the
  672. functions and the needed definitions are in the `<nl_types.h>' header
  673. file.
  674.  
  675.    `catopen' is used like in this:
  676.  
  677.      nl_catd catd = catopen ("catalog_name", 0);
  678.  
  679.    The function takes as the argument the name of the catalog.  This
  680. usual refers to the name of the program or the package.  The second
  681. parameter is not further specified in the standard.  I don't even know
  682. whether it is implemented consistently among various systems.  So the
  683. common advice is to use `0' as the value.  The return value is a handle
  684. to the message catalog, equivalent to handles to file returned by
  685. `open'.
  686.  
  687.    This handle is of course used in the `catgets' function which can be
  688. used like this:
  689.  
  690.      char *translation = catgets (catd, set_no, msg_id, "original string");
  691.  
  692.    The first parameter is this catalog descriptor.  The second parameter
  693. specifies the set of messages in this catalog, in which the message
  694. described by `msg_id' is obtained.  `catgets' therefore uses a
  695. three-stage addressing:
  696.  
  697.      catalog name => set number => message ID => translation
  698.  
  699.    The fourth argument is not used to address the translation.  It is
  700. given as a default value in case when one of the addressing stages
  701. fail.  One important thing to remember is that although the return type
  702. of catgets is `char *' the resulting string *must not* be changed.  It
  703. should better `const char *', but the standard is published in 1988,
  704. one year before ANSI C.
  705.  
  706. The last of these function functions is used and behaves as expected:
  707.  
  708.      catclose (catd);
  709.  
  710.    After this no `catgets' call using the descriptor is legal anymore.
  711.  
  712. 
  713. File: gettext.info,  Node: Problems with catgets,  Prev: Interface to catgets,  Up: catgets
  714.  
  715. Problems with the `catgets' Interface?!
  716. ---------------------------------------
  717.  
  718.    Now that this descriptions seemed to be really easy where are the
  719. problem we speak of.  In fact the interface could be used in a
  720. reasonable way, but constructing the message catalogs is a pain.  The
  721. reason for this lies in the third argument of `catgets': the unique
  722. message ID.  This has to be a numeric value for all messages in a single
  723. set.  Perhaps you could imagine the problems keeping such list while
  724. changing the source code.  Add a new message here, remove one there.  Of
  725. course there have been developed a lot of tools helping to organize this
  726. chaos but one as the other fails in one aspect or the other.  We don't
  727. want to say that the other approach has no problems but they are far
  728. more easily to manage.
  729.  
  730. 
  731. File: gettext.info,  Node: gettext,  Next: Comparison,  Prev: catgets,  Up: Programmers
  732.  
  733. About `gettext'
  734. ===============
  735.  
  736.    The definition of the `gettext' interface comes from a Uniforum
  737. proposal and it is followed by at least one major Unix vendor (Sun) in
  738. its last developments.  It is not specified in any official standard,
  739. though.
  740.  
  741.    The main points about this solution is that it does not follow the
  742. method of normal file handling (open-use-close) and that it does not
  743. burden the programmer so many task, especially the unique key handling.
  744. Of course here is also a unique key needed, but this key is the message
  745. itself (how long or short it is).  *Note Comparison:: for a more
  746. detailed comparison of the two methods.
  747.  
  748.    The following section contains a rather detailed description of the
  749. interface.  We make it that detailed because this is the interface we
  750. chose for the GNU `gettext' Library.  Programmers interested in using
  751. this library will be interested in this description.
  752.  
  753. * Menu:
  754.  
  755. * Interface to gettext::        The interface
  756. * Ambiguities::                 Solving ambiguities
  757. * Locating Catalogs::           Locating message catalog files
  758. * Optimized gettext::           Optimization of the *gettext functions
  759.  
  760. 
  761. File: gettext.info,  Node: Interface to gettext,  Next: Ambiguities,  Prev: gettext,  Up: gettext
  762.  
  763. The Interface
  764. -------------
  765.  
  766.    The minimal functionality an interface must have is a) to select a
  767. domain the strings are coming from (a single domain for all programs is
  768. not reasonable because its construction and maintenance is difficult,
  769. perhaps impossible) and b) to access a string in a selected domain.
  770.  
  771.    This is principally the description of the `gettext' interface.  It
  772. has an global domain which unqualified usages reference.  Of course this
  773. domain is selectable by the user.
  774.  
  775.      char *textdomain (const char *domain_name);
  776.  
  777.    This provides the possibility to change or query the current status
  778. of the current global domain of the `LC_MESSAGE' category.  The
  779. argument is a null-terminated string, whose characters must be legal in
  780. the use in filenames.  If the DOMAIN_NAME argument is `NULL', the
  781. function return the current value.  If no value has been set before,
  782. the name of the default domain is returned: *messages*.  Please note
  783. that although the return value of `textdomain' is of type `char *' no
  784. changing is allowed.  It is also important to know that no checks of
  785. the availability are made.  If the name is not available you will see
  786. this by the fact that no translations are provided.
  787.  
  788. To use a domain set by `textdomain' the function
  789.  
  790.      char *gettext (const char *msgid);
  791.  
  792.    is to be used.  This is the simplest reasonable form one can imagine.
  793. The translation of the string MSGID is returned if it is available in
  794. the current domain.  If not available the argument itself is returned.
  795. If the argument is `NULL' the result is undefined.
  796.  
  797.    One things which should come into mind is that no explicit
  798. dependency to the used domain is given.  The current value of the
  799. domain for the `LC_MESSAGES' locale is used.  If this changes between
  800. two executions of the same `gettext' call in the program, both calls
  801. reference a different message catalog.
  802.  
  803.    For the easiest case, which is normally used in internationalized GNU
  804. packages, once at the beginning of execution a call to `textdomain' is
  805. issued, setting the domain to a unique name, normally the package name.
  806. In the following code all strings which have to be translated are
  807. filtered through the gettext function.  That's all, the package speaks
  808. your language.
  809.  
  810. 
  811. File: gettext.info,  Node: Ambiguities,  Next: Locating Catalogs,  Prev: Interface to gettext,  Up: gettext
  812.  
  813. Solving Ambiguities
  814. -------------------
  815.  
  816.    While this single name domain work good for most applications there
  817. might be the need to get translations from more than one domain.  Of
  818. course one could switch between different domains with calls to
  819. `textdomain', but this is really not convenient nor is it fast.  A
  820. possible situation could be one case discussing while this writing:  all
  821. error messages of functions in the set of common used functions should
  822. go into a separate domain `error'.  By this mean we would only need to
  823. translate them once.
  824.  
  825. For this reasons there are two more functions to retrieve strings:
  826.  
  827.      char *dgettext (const char *domain_name, const char *msgid);
  828.      char *dcgettext (const char *domain_name, const char *msgid,
  829.                       int category);
  830.  
  831.    Both take an additional argument at the first place, which
  832. corresponds to the argument of `textdomain'.  The third argument of
  833. `dcgettext' allows to use another locale but `LC_MESSAGES'.  But I
  834. really don't know where this can be useful.  If the DOMAIN_NAME is
  835. `NULL' or CATEGORY has an value beside the known ones, the result is
  836. undefined.  It should also be noted that this function is not part of
  837. the second known implementation of this function family, the one found
  838. in Solaris.
  839.  
  840.    A second ambiguity can arise by the fact, that perhaps more than one
  841. domain has the same name.  This can be solved by specifying where the
  842. needed message catalog files can be found.
  843.  
  844.      char *bindtextdomain (const char *domain_name,
  845.                            const char *dir_name);
  846.  
  847.    Calling this function binds the given domain to a file in the
  848. specified directory (how this file is determined follows below).  Esp a
  849. file in the systems default place is not favored against the specified
  850. file anymore (as it would be by solely using `textdomain').  A `NULL'
  851. pointer for the DIR_NAME parameter returns the binding associated with
  852. DOMAIN_NAME.  If DOMAIN_NAME itself is `NULL' nothing happens and a
  853. `NULL' pointer is returned.  Here again as for all the other functions
  854. is true that none of the return value must be changed!
  855.  
  856. 
  857. File: gettext.info,  Node: Locating Catalogs,  Next: Optimized gettext,  Prev: Ambiguities,  Up: gettext
  858.  
  859. Locating Message Catalog Files
  860. ------------------------------
  861.  
  862.    Because many different languages for many different packages have to
  863. be stored we need some way to add these information to file message
  864. catalog files.  The way usually used in Unix environments is have this
  865. encoding in the file name.  This is also done here.  The directory name
  866. given in `bindtextdomain's second argument (or the default directory),
  867. followed by the value and name of the locale and the domain name are
  868. concatenated:
  869.  
  870.      DIR_NAME/LOCALE/LC_CATEGORY/DOMAIN_NAME.mo
  871.  
  872.    The default value for DIR_NAME is system specific.  For the GNU
  873. library it's:
  874.      /usr/local/share/locale
  875.  
  876. LOCALE is the value of the locale whose name is this `LC_CATEGORY'.
  877. For `gettext' and `dgettext' this locale is always `LC_MESSAGES'.
  878. `dcgettext' specifies the locale by the third argument.(1) (2)
  879.  
  880.    ---------- Footnotes ----------
  881.  
  882.    (1)  Some system, eg Ultrix, don't have `LC_MESSAGES'.  Here we use
  883. a more or less arbitrary value for it.
  884.  
  885.    (2)  When the system does not support `setlocale' its behavior in
  886. setting the locale values is simulated by looking at the environment
  887. variables.
  888.  
  889. 
  890. File: gettext.info,  Node: Optimized gettext,  Prev: Locating Catalogs,  Up: gettext
  891.  
  892. Optimization of the *gettext functions
  893. --------------------------------------
  894.  
  895.    At this point of the discussion we should talk about an advantage of
  896. the GNU `gettext' implementation.  Some readers might have pointed out
  897. that an internationalized program might have a poor performance if some
  898. string has to be translated in an inner loop.  While this is unavoidable
  899. when the string varies from one run of the loop to the other it is
  900. simply a waste of time when the string is always the same.  Take the
  901. following example:
  902.  
  903.      {
  904.        while (...)
  905.          {
  906.            puts (gettext ("Hello world"));
  907.          }
  908.      }
  909.  
  910. When the locale selection does not change between two runs the resulting
  911. string is always the same.  One way to use this is:
  912.  
  913.      {
  914.        str = gettext ("Hello world");
  915.        while (...)
  916.          {
  917.            puts (str);
  918.          }
  919.      }
  920.  
  921. But this solution is not usable in all situation (e.g. when the locale
  922. selection changes) nor is it good readable.
  923.  
  924.    The GNU C compiler, version 2.7 and above, provide another solution
  925. for this.  To describe this we show here some lines of the
  926. `intl/libgettext.h' file.  For an explanation of the expression command
  927. block see *Note Statements and Declarations in Expressions:
  928. (gcc)Statement Exprs.
  929.  
  930.      #  if defined __GNUC__ && __GNUC__ == 2 && __GNUC_MINOR__ >= 7
  931.      #   define    dcgettext(domainname, msgid, category)           \
  932.        (__extension__                                                 \
  933.         ({                                                            \
  934.           char *result;                                               \
  935.           if (__builtin_constant_p (msgid))                           \
  936.             {                                                         \
  937.               extern int _nl_msg_cat_cntr;                            \
  938.               static char *__translation__;                           \
  939.               static int __catalog_counter__;                         \
  940.               if (! __translation__                                   \
  941.                   || __catalog_counter__ != _nl_msg_cat_cntr)         \
  942.                 {                                                     \
  943.                   __translation__ =                                   \
  944.                     dcgettext__ ((domainname), (msgid), (category));  \
  945.                   __catalog_counter__ = _nl_msg_cat_cntr;             \
  946.                 }                                                     \
  947.               result = __translation__;                               \
  948.             }                                                         \
  949.           else                                                        \
  950.             result = dcgettext__ ((domainname), (msgid), (category)); \
  951.           result;                                                     \
  952.          }))
  953.      #  endif
  954.  
  955.    The interesting thing here is the `__builtin_constant_p' predicate.
  956. This is evaluated at compile time and so optimization can take place
  957. immediately.  Here two cases are distinguished: the argument to
  958. `gettext' is not a constant value in which case simply the function
  959. `dcgettext__' is called, the real implementation of the `dcgettext'
  960. function.
  961.  
  962.    If the string argument *is* constant we can reuse the once gained
  963. translation when the locale selection has not changed.  This is exactly
  964. what is done here.  The `_nl_msg_cat_cntr' variable is defined in the
  965. `loadmsgcat.c' which is available in `libintl.a' and is changed
  966. whenever a new message catalog is loaded.
  967.  
  968.