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