home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gettext-0.10.24-bin.lha / info / gettext.info-2 (.txt) < prev    next >
GNU Info File  |  1996-10-12  |  49KB  |  877 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: Entry Positioning,  Next: Normalizing,  Prev: Main PO Commands,  Up: Basics
  24. Entry Positioning
  25. =================
  26.    The cursor in a PO file window is almost always part of an entry.
  27. The only exceptions are the special case when the cursor is after the
  28. last entry in the file, or when the PO file is empty.  The entry where
  29. the cursor is found to be is said to be the current entry.  Many PO
  30. mode commands operate on the current entry, so moving the cursor does
  31. more than allowing the translator to browse the PO file, this also
  32. selects on which entry commands operate.
  33.    Some PO mode commands alter the position of the cursor in a
  34. specialized way.  A few of those special purpose positioning are
  35. described here, the others are described in following sections.
  36.      Redisplay the current entry.
  37.      Select the entry after the current one.
  38.      Select the entry before the current one.
  39.      Select the first entry in the PO file.
  40.      Select the last entry in the PO file.
  41.      Record the location of the current entry for later use.
  42.      Return to a previously saved entry location.
  43.      Exchange the current entry location with the previously saved one.
  44.    Any GNU Emacs command able to reposition the cursor may be used to
  45. select the current entry in PO mode, including commands which move by
  46. characters, lines, paragraphs, screens or pages, and search commands.
  47. However, there is a kind of standard way to display the current entry
  48. in PO mode, which usual GNU Emacs commands moving the cursor do not
  49. especially try to enforce.  The command `.' (`po-current-entry') has
  50. the sole purpose of redisplaying the current entry properly, after the
  51. current entry has been changed by means external to PO mode, or the
  52. Emacs screen otherwise altered.
  53.    It is yet to be decided if PO mode helps the translator, or otherwise
  54. irritates her, by forcing a rigid window disposition while she is doing
  55. her work.  We originally had quite precise ideas about how windows
  56. should behave, but on the other hand, anyone used to GNU Emacs is often
  57. happy to keep full control.  Maybe a fixed window disposition might be
  58. offered as a PO mode option that the translator might activate or
  59. deactivate at will, so it could be offered on an experimental basis.
  60. If nobody feels a real need for using it, or a compulsion for writing
  61. it, we should drop this whole idea.  The incentive for doing it should
  62. come from translators rather than programmers, as opinions from an
  63. experienced translator are surely more worth to me than opinions from
  64. programmers *thinking* about how *others* should do translation.
  65.    The commands `n' (`po-next-entry') and `p' (`po-previous-entry')
  66. move the cursor the entry following, or preceding, the current one.  If
  67. `n' is given while the cursor is on the last entry of the PO file, or
  68. if `p' is given while the cursor is on the first entry, no move is done.
  69.    The commands `<' (`po-first-entry') and `>' (`po-last-entry') move
  70. the cursor to the first entry, or last entry, of the PO file.  When the
  71. cursor is located past the last entry in a PO file, most PO mode
  72. commands will return an error saying `After last entry'.  Moreover, the
  73. commands `<' and `>' have the special property of being able to work
  74. even when the cursor is not into some PO file entry, and one may use
  75. them for nicely correcting this situation.  But even these commands
  76. will fail on a truly empty PO file.  There are development plans for
  77. the PO mode for it to interactively fill an empty PO file from sources.
  78. *Note Marking::.
  79.    The translator may decide, before working at the translation of a
  80. particular entry, that she needs to browse the remainder of the PO
  81. file, maybe for finding the terminology or phraseology used in related
  82. entries.  She can of course use the standard Emacs idioms for saving
  83. the current cursor location in some register, and use that register for
  84. getting back, or else, use the location ring.
  85.    PO mode offers another approach, by which cursor locations may be
  86. saved onto a special stack.  The command `m' (`po-push-location')
  87. merely adds the location of current entry to the stack, pushing the
  88. already saved locations under the new one.  The command `r'
  89. (`po-pop-location') consumes the top stack element and reposition the
  90. cursor to the entry associated with that top element.  This position is
  91. then lost, for the next `r' will move the cursor to the previously
  92. saved location, and so on until no locations remain on the stack.
  93.    If the translator wants the position to be kept on the location
  94. stack, maybe for taking a look at the entry associated with the top
  95. element, then go elsewhere with the intent of getting back later, she
  96. ought to use `m' immediately after `r'.
  97.    The command `x' (`po-exchange-location') simultaneously reposition
  98. the cursor to the entry associated with the top element of the stack of
  99. saved locations, and replace that top element with the location of the
  100. current entry before the move.  Consequently, repeating the `x' command
  101. toggles alternatively between two entries.  For achieving this, the
  102. translator will position the cursor on the first entry, use `m', then
  103. position to the second entry, and merely use `x' for making the switch.
  104. File: gettext.info,  Node: Normalizing,  Prev: Entry Positioning,  Up: Basics
  105. Normalizing Strings in Entries
  106. ==============================
  107.    There are many different ways for encoding a particular string into a
  108. PO file entry, because there are so many different ways to split and
  109. quote multi-line strings, and even, to represent special characters by
  110. backslahsed escaped sequences.  Some features of PO mode rely on the
  111. ability for PO mode to scan an already existing PO file for a
  112. particular string encoded into the `msgid' field of some entry.  Even
  113. if PO mode has internally all the built-in machinery for implementing
  114. this recognition easily, doing it fast is technically difficult.  To
  115. facilitate a solution to this efficiency problem, we decided on a
  116. canonical representation for strings.
  117.    A conventional representation of strings in a PO file is currently
  118. under discussion, and PO mode experiments with a canonical
  119. representation.  Having both `xgettext' and PO mode converging towards
  120. a uniform way of representing equivalent strings would be useful, as
  121. the internal normalization needed by PO mode could be automatically
  122. satisfied when using `xgettext' from GNU `gettext'.  An explicit PO
  123. mode normalization should then be only necessary for PO files imported
  124. from elsewhere, or for when the convention itself evolves.
  125.    So, for achieving normalization of at least the strings of a given
  126. PO file needing a canonical representation, the following PO mode
  127. command is available:
  128. `M-x po-normalize'
  129.      Tidy the whole PO file by making entries more uniform.
  130.    The special command `M-x po-normalize', which has no associate keys,
  131. revises all entries, ensuring that strings of both original and
  132. translated entries use uniform internal quoting in the PO file.  It
  133. also removes any crumb after the last entry.  This command may be
  134. useful for PO files freshly imported from elsewhere, or if we ever
  135. improve on the canonical quoting format we use.  This canonical format
  136. is not only meant for getting cleaner PO files, but also for greatly
  137. speeding up `msgid' string lookup for some other PO mode commands.
  138.    `M-x po-normalize' presently makes three passes over the entries.
  139. The first implements heuristics for converting PO files for GNU
  140. `gettext' 0.6 and earlier, in which `msgid' and `msgstr' fields were
  141. using K&R style C string syntax for multi-line strings.  These
  142. heuristics may fail for comments not related to obsolete entries and
  143. ending with a backslash; they also depend on subsequent passes for
  144. finalizing the proper commenting of continued lines for obsolete
  145. entries.  This first pass might disappear once all oldish PO files
  146. would have been adjusted.  The second and third pass normalize all
  147. `msgid' and `msgstr' strings respectively.  They also clean out those
  148. trailing backslashes used by XView's `msgfmt' for continued lines.
  149.    Having such an explicit normalizing command allows for importing PO
  150. files from other sources, but also eases the evolution of the current
  151. convention, evolution driven mostly by aesthetic concerns, as of now.
  152. It is easy to make suggested adjustments at a later time, as the
  153. normalizing command and eventually, other GNU `gettext' tools should
  154. greatly automate conformance.  A description of the canonical string
  155. format is given below, for the particular benefit of those not having
  156. GNU Emacs handy, and who would nevertheless want to handcraft their PO
  157. files in nice ways.
  158.    Right now, in PO mode, strings are single line or multi-line.  A
  159. string goes multi-line if and only if it has *embedded* newlines, that
  160. is, if it matches `[^\n]\n+[^\n]'.  So, we would have:
  161.      msgstr "\n\nHello, world!\n\n\n"
  162.    but, replacing the space by a newline, this becomes:
  163.      msgstr ""
  164.      "\n"
  165.      "\n"
  166.      "Hello,\n"
  167.      "world!\n"
  168.      "\n"
  169.      "\n"
  170.    We are deliberately using a caricatural example, here, to make the
  171. point clearer.  Usually, multi-lines are not that bad looking.  It is
  172. probable that we will implement the following suggestion.  We might
  173. lump together all initial newlines into the empty string, and also all
  174. newlines introducing empty lines (that is, for N > 1, the N-1'th last
  175. newlines would go together on a separate string), so making the
  176. previous example appear:
  177.      msgstr "\n\n"
  178.      "Hello,\n"
  179.      "world!\n"
  180.      "\n\n"
  181.    There are a few yet undecided little points about string
  182. normalization, to be documented in this manual, once these questions
  183. settle.
  184. File: gettext.info,  Node: Sources,  Next: Initial,  Prev: Basics,  Up: Top
  185. Preparing Program Sources
  186. *************************
  187.    For the programmer, changes to the C source code fall into three
  188. categories.  First, you have to make the localization functions known
  189. to all modules needing message translation.  Second, you should
  190. properly trigger the operation of GNU `gettext' when the program
  191. initializes, usually from the `main' function.  Last, you should
  192. identify and especially mark all constant strings in your program
  193. needing translation.
  194.    Presuming that your set of programs, or package, has been adjusted
  195. so all needed GNU `gettext' files are available, and your `Makefile'
  196. files are adjusted (*note Maintainers::.), each C module having
  197. translated C strings should contain the line:
  198.      #include <libintl.h>
  199.    The remaining changes to your C sources are discussed in the further
  200. sections of this chapter.
  201. * Menu:
  202. * Triggering::                  Triggering `gettext' Operations
  203. * Mark Keywords::               How Marks Appears in Sources
  204. * Marking::                     Marking Translatable Strings
  205. * c-format::                    Telling something about the following string
  206. * Special cases::               Special Cases of Translatable Strings
  207. File: gettext.info,  Node: Triggering,  Next: Mark Keywords,  Prev: Sources,  Up: Sources
  208. Triggering `gettext' Operations
  209. ===============================
  210.    The initialization of locale data should be done with more or less
  211. the same code in every program, as demonstrated below:
  212.      int
  213.      main (argc, argv)
  214.           int argc;
  215.           char argv;
  216.      {
  217.        ...
  218.        setlocale (LC_ALL, "");
  219.        bindtextdomain (PACKAGE, LOCALEDIR);
  220.        textdomain (PACKAGE);
  221.        ...
  222.      }
  223.    PACKAGE and LOCALEDIR should be provided either by `config.h' or by
  224. the Makefile.  For now consult the `gettext' sources for more
  225. information.
  226.    The use of `LC_ALL' might not be appropriate for you.  `LC_ALL'
  227. includes all locale categories and especially `LC_CTYPE'.  This later
  228. category is responsible for determining character classes with the
  229. `isalnum' etc. functions from `ctype.h' which could especially for
  230. programs, which process some kind of input language, be wrong.  For
  231. example this would mean that a source code using the c, (cedille
  232. character) is runnable in France but not in the U.S.
  233.    So it is sometimes necessary to replace the `LC_ALL' line in the
  234. code above by a sequence of `setlocale' lines
  235.      {
  236.        ...
  237.        setlocale (LC_TIME, "");
  238.        setlocale (LC_MESSAGES, "");
  239.        ...
  240.      }
  241. or to switch for and back to the character class in question.
  242. File: gettext.info,  Node: Mark Keywords,  Next: Marking,  Prev: Triggering,  Up: Sources
  243. How Marks Appears in Sources
  244. ============================
  245.    All strings requiring translation should be marked in the C sources.
  246. Marking is done in such a way that each translatable string appears to
  247. be the sole argument of some function or preprocessor macro.  There are
  248. only a few such possible functions or macros meant for translation, and
  249. their names are said to be marking keywords.  The marking is attached
  250. to strings themselves, rather than to what we do with them.  This
  251. approach has more uses.  A blatant example is an error message produced
  252. by formatting.  The format string needs translation, as well as some
  253. strings inserted through some `%s' specification in the format, while
  254. the result from `sprintf' may have so many different instances that it
  255. is impractical to list them all in some `error_string_out()' routine,
  256.    This marking operation has two goals.  The first goal of marking is
  257. for triggering the retrieval of the translation, at run time.  The
  258. keyword are possibly resolved into a routine able to dynamically return
  259. the proper translation, as far as possible or wanted, for the argument
  260. string.  Most localizable strings are found in executable positions,
  261. that is, attached to variables or given as parameters to functions.
  262. But this is not universal usage, and some translatable strings appear
  263. in structured initializations.  *Note Special cases::.
  264.    The second goal of the marking operation is to help `xgettext' at
  265. properly extracting all translatable strings when it scans a set of
  266. program sources and produces PO file templates.
  267.    The canonical keyword for marking translatable strings is `gettext',
  268. it gave its name to the whole GNU `gettext' package.  For packages
  269. making only light use of the `gettext' keyword, macro or function, it
  270. is easily used *as is*.  However, for packages using the `gettext'
  271. interface more heavily, it is usually more convenient to give the main
  272. keyword a shorter, less obtrusive name.  Indeed, the keyword might
  273. appear on a lot of strings all over the package, and programmers
  274. usually do not want nor need their program sources to remind them
  275. forcefully, all the time, that they are internationalized.  Further, a
  276. long keyword has the disadvantage of using more horizontal space,
  277. forcing more indentation work on sources for those trying to keep them
  278. within 79 or 80 columns.
  279.    Many GNU packages use `_' (a simple underline) as a keyword, and
  280. write `_("Translatable string")' instead of `gettext ("Translatable
  281. string")'.  Further, the usual GNU coding rule wanting that there is a
  282. space between the keyword and the opening parenthesis is relaxed, in
  283. practice, for this particular usage.  So, the textual overhead per
  284. translatable string is reduced to only three characters: the underline
  285. and the two parentheses.  However, even if GNU `gettext' uses this
  286. convention internally, it does not offer it officially.  The real,
  287. genuine keyword is truly `gettext' indeed.  It is fairly easy for those
  288. wanting to use `_' instead of `gettext' to declare:
  289.      #include <libintl.h>
  290.      #define _(String) gettext (String)
  291. instead of merely using `#include <libintl.h>'.
  292.    Later on, the maintenance is relatively easy.  If, as a programmer,
  293. you add or modify a string, you will have to ask yourself if the new or
  294. altered string requires translation, and include it within `_()' if you
  295. think it should be translated.  `"%s: %d"' is an example of string
  296. *not* requiring translation!
  297. File: gettext.info,  Node: Marking,  Next: c-format,  Prev: Mark Keywords,  Up: Sources
  298. Marking Translatable Strings
  299. ============================
  300.    In PO mode, one set of features is meant more for the programmer than
  301. for the translator, and allows him to interactively mark which strings,
  302. in a set of program sources, are translatable, and which are not.  Even
  303. if it is a fairly easy job for a programmer to find and mark such
  304. strings by other means, using any editor of his choice, PO mode makes
  305. this work more comfortable.  Further, this gives translators who feel a
  306. little like programmers, or programmers who feel a little like
  307. translators, a tool letting them work at marking translatable strings
  308. in the program sources, while simultaneously producing a set of
  309. translation in some language, for the package being internationalized.
  310.    The set of program sources, targetted by the PO mode commands
  311. describe here, should have an Emacs tags table constructed for your
  312. project, prior to using these PO file commands.  This is easy to do.
  313. In any shell window, change the directory to the root of your project,
  314. then execute a command resembling:
  315.      etags src/*.[hc] lib/*.[hc]
  316. presuming here you want to process all `.h' and `.c' files from the
  317. `src/' and `lib/' directories.  This command will explore all said
  318. files and create a `TAGS' file in your root directory, somewhat
  319. summarizing the contents using a special file format Emacs can
  320. understand.
  321.    For official GNU packages which follow the GNU coding standard there
  322. is a make goal `tags' or `TAGS' which construct the tag files in all
  323. directories and for all files containing source code.
  324.    Once your `TAGS' file is ready, the following commands assist the
  325. programmer at marking translatable strings in his set of sources.  But
  326. these commands are necessarily driven from within a PO file window, and
  327. it is likely that you do not even have such a PO file yet.  This is not
  328. a problem at all, as you may safely open a new, empty PO file, mainly
  329. for using these commands.  This empty PO file will slowly fill in while
  330. you mark strings as translatable in your program sources.
  331.      Search through program sources for a string which looks like a
  332.      candidate for translation.
  333. `M-,'
  334.      Mark the last string found with `_()'.
  335. `M-.'
  336.      Mark the last string found with a keyword taken from a set of
  337.      possible keywords.  This command with a prefix allows some
  338.      management of these keywords.
  339.    The `,' (`po-tags-search') command search for the next occurrence of
  340. a string which looks like a possible candidate for translation, and
  341. displays the program source in another Emacs window, positioned in such
  342. a way that the string is near the top of this other window.  If the
  343. string is too big to fit whole in this window, it is positioned so only
  344. its end is shown.  In any case, the cursor is left in the PO file
  345. window.  If the shown string would be better presented differently in
  346. different native languages, you may mark it using `M-,' or `M-.'.
  347. Otherwise, you might rather ignore it and skip to the next string by
  348. merely repeating the `,' command.
  349.    A string is a good candidate for translation if it contains a
  350. sequence of three or more letters.  A string containing at most two
  351. letters in a row will be considered as a candidate if it has more
  352. letters than non-letters.  The command disregards strings containing no
  353. letters, or isolated letters only.  It also disregards strings within
  354. comments, or strings already marked with some keyword PO mode knows
  355. (see below).
  356.    If you have never told Emacs about some `TAGS' file to use, the
  357. command will request that you specify one from the minibuffer, the
  358. first time you use the command.  You may later change your `TAGS' file
  359. by using the regular Emacs command `M-x visit-tags-table', which will
  360. ask you to name the precise `TAGS' file you want to use.  *Note Tag
  361. Tables: (emacs)Tags.
  362.    Each time you use the `,' command, the search resumes from where it
  363. was left by the previous search, and goes through all program sources,
  364. obeying the `TAGS' file, until all sources have been processed.
  365. However, by giving a prefix argument to the command (`C-u ,'), you may
  366. request that the search be restarted all over again from the first
  367. program source; but in this case, strings that you recently marked as
  368. translatable will be automatically skipped.
  369.    Using this `,' command does not prevent using of other regular Emacs
  370. tags commands.  For example, regular `tags-search' or
  371. `tags-query-replace' commands may be used without disrupting the
  372. independent `,' search sequence.  However, as implemented, the
  373. *initial* `,' command (or the `,' command is used with a prefix) might
  374. also reinitialize the regular Emacs tags searching to the first tags
  375. file, this reinitialization might be considered spurious.
  376.    The `M-,' (`po-mark-translatable') command will mark the recently
  377. found string with the `_' keyword.  The `M-.'
  378. (`po-select-mark-and-mark') command will request that you type one
  379. keyword from the minibuffer and use that keyword for marking the
  380. string.  Both commands will automatically create a new PO file
  381. untranslated entry for the string being marked, and make it the current
  382. entry (making it easy for you to immediately proceed to its
  383. translation, if you feel like doing it right away).  It is possible
  384. that the modifications made to the program source by `M-,' or `M-.'
  385. render some source line longer than 80 columns, forcing you to break
  386. and re-indent this line differently.  You may use the `O' command from
  387. PO mode, or any other window changing command from GNU Emacs, to break
  388. out into the program source window, and do any needed adjustments.  You
  389. will have to use some regular Emacs command to return the cursor to the
  390. PO file window, if you want command `,' for the next string, say.
  391.    The `M-.' command has a few built-in speedups, so you do not have to
  392. explicitly type all keywords all the time.  The first such speedup is
  393. that you are presented with a *preferred* keyword, which you may accept
  394. by merely typing `RET' at the prompt.  The second speedup is that you
  395. may type any non-ambiguous prefix of the keyword you really mean, and
  396. the command will complete it automatically for you.  This also means
  397. that PO mode has to *know* all your possible keywords, and that it will
  398. not accept mistyped keywords.
  399.    If you reply `?' to the keyword request, the command gives a list of
  400. all known keywords, from which you may choose.  When the command is
  401. prefixed by an argument (`C-u M-.'), it inhibits updating any program
  402. source or PO file buffer, and does some simple keyword management
  403. instead.  In this case, the command asks for a keyword, written in
  404. full, which becomes a new allowed keyword for later `M-.' commands.
  405. Moreover, this new keyword automatically becomes the *preferred*
  406. keyword for later commands.  By typing an already known keyword in
  407. response to `C-u M-.', one merely changes the *preferred* keyword and
  408. does nothing more.
  409.    All keywords known for `M-.' are recognized by the `,' command when
  410. scanning for strings, and strings already marked by any of those known
  411. keywords are automatically skipped.  If many PO files are opened
  412. simultaneously, each one has its own independent set of known keywords.
  413. There is no provision in PO mode, currently, for deleting a known
  414. keyword, you have to quit the file (maybe using `Q') and reopen it
  415. afresh.  When a PO file is newly brought up in an Emacs window, only
  416. `gettext' and `_' are known as keywords, and `gettext' is preferred for
  417. the `M-.' command.  In fact, this is not useful to prefer `_', as this
  418. one is already built in the `M-,' command.
  419. File: gettext.info,  Node: c-format,  Next: Special cases,  Prev: Marking,  Up: Sources
  420. Special Comments preceding Keywords
  421. ===================================
  422.    In C programs strings are often used within calls of functions from
  423. the `printf' family.  The special thing about these format strings is
  424. that they can contain format specifiers introduced with `%'.  Assume we
  425. have the code
  426.      printf (gettext ("String `%s' has %d characters\n"), s, strlen (s));
  427. A possible German translation for the above string might be:
  428.      "%d Zeichen lang ist die Zeichenkette `%s'"
  429.    A C programmer, even if he cannot speak German, will recognize that
  430. there is something wrong here.  The order of the two format specifiers
  431. is changed but of course the arguments in the `printf' don't have.
  432. This will most probably lead to problems because now the length of the
  433. string is regarded as the address.
  434.    To prevent errors at runtime caused by translations the `msgfmt'
  435. tool can check statically whether the arguments in the original and the
  436. translation string match in type and number.  If this is not the case a
  437. warning will be given and the error cannot causes problems at runtime.
  438. If the word order in the above German translation would be correct one
  439. would have to write
  440.      "%2$d Zeichen lang ist die Zeichenkette `%1$s'"
  441. The routines in `msgfmt' know about this special notation.
  442.    Because not all strings in a program must be format strings it is not
  443. useful for `msgfmt' to test all the strings in the `.po' file.  This
  444. might cause problems because the string might contain what looks like a
  445. format specifier, but the string is not used in `printf'.
  446.    Therefore the `xgettext' adds a special tag to those messages it
  447. thinks might be a format string.  There is no absolute rule for this,
  448. only a heuristic.  In the `.po' file the entry is marked using the
  449. `c-format' flag in the `#,' comment line (*note PO Files::.).
  450.    The careful reader now might say that this again can cause problems.
  451. The heuristic might guess it wrong.  This is true and therefore
  452. `xgettext' knows about special kind of comment which lets the
  453. programmer take over the decision.  If in the same line or the
  454. immediately preceding line of the `gettext' keyword the `xgettext'
  455. program find a comment containing the words `xgettext:c-format' it will
  456. mark the string in any case with the `c-format' flag.  This kind of
  457. comment should be used when `xgettext' does not recognize the string as
  458. a format string but is really is one and it should be tested.
  459.    This situation happens quite often.  The `printf' function is often
  460. called with strings which do not contain a format specifier.  Of course
  461. one would normally use `fputs' but it does happen.  In this case
  462. `xgettext' does not recognize this as a format string but what happens
  463. if the translation introduces a valid format specifier?  The `printf'
  464. function will try to access one of the parameter but none exists
  465. because the original code does not refer to any parameter.
  466.    `xgettext' of course could make a wrong decision the other way
  467. round.  A string marked as a format string is not really a format
  468. string.  In this case the `msgfmt' might give too many warnings and
  469. would prevent translating the `.po' file.  The method to prevent this
  470. wrong decision is similar to the one used above, only the comment to
  471. use must contain the string `xgettext:no-c-format'.
  472.    If a string is marked with `c-format' and this is not correct the
  473. user can find out who is responsible for the decision.  *Note xgettext
  474. Invocation:: to see how the `--debug' option can be used for solving
  475. this problem.
  476. File: gettext.info,  Node: Special cases,  Prev: c-format,  Up: Sources
  477. Special Cases of Translatable Strings
  478. =====================================
  479.    The attentive reader might now point out that it is not always
  480. possible to mark translatable string with `gettext' or something like
  481. this.  Consider the following case:
  482.      {
  483.        static const char *messages[] = {
  484.          "some very meaningful message",
  485.          "and another one"
  486.        };
  487.        const char *string;
  488.        ...
  489.        string
  490.          = index > 1 ? "a default message" : messages[index];
  491.      
  492.        fputs (string);
  493.        ...
  494.      }
  495.    While it is no problem to mark the string `"a default message"' it
  496. is not possible to mark the string initializers for `messages'.  What
  497. is to be done?  We have to fulfill two tasks.  First we have to mark the
  498. strings so that the `xgettext' program (*note xgettext Invocation::.)
  499. can find them, and second we have to translate the string at runtime
  500. before printing them.
  501.    The first task can be fulfilled by creating a new keyword, which
  502. names a no-op.  For the second we have to mark all access points to a
  503. string from the array.  So one solution can look like this:
  504.      #define gettext_noop(String) (String)
  505.      
  506.      {
  507.        static const char *messages[] = {
  508.          gettext_noop ("some very meaningful message"),
  509.          gettext_noop ("and another one")
  510.        };
  511.        const char *string;
  512.        ...
  513.        string
  514.          = index > 1 ? gettext ("a default message") : gettext (messages[index]);
  515.      
  516.        fputs (string);
  517.        ...
  518.      }
  519.    Please convince yourself that the string which is written by `fputs'
  520. is translated in any case.  How to get `xgettext' know the additional
  521. keyword `gettext_noop' is explained in *Note xgettext Invocation::.
  522.    The above is of course not the only solution.  You could also come
  523. along with the following one:
  524.      #define gettext_noop(String) (String)
  525.      
  526.      {
  527.        static const char *messages[] = {
  528.          gettext_noop ("some very meaningful message",
  529.          gettext_noop ("and another one")
  530.        };
  531.        const char *string;
  532.        ...
  533.        string
  534.          = index > 1 ? gettext_noop ("a default message") : messages[index];
  535.      
  536.        fputs (gettext (string));
  537.        ...
  538.      }
  539.    But this has some drawbacks.  First the programmer has to take care
  540. that he uses `gettext_noop' for the string `"a default message"'.  A
  541. use of `gettext' could have in rare cases unpredictable results.  The
  542. second reason is found in the internals of the GNU `gettext' Library
  543. which will make this solution less efficient.
  544.    One advantage is that you need not make control flow analysis to make
  545. sure the output is really translated in any case.  But this analysis is
  546. generally not very difficult.  If it should be in any situation you can
  547. use this second method in this situation.
  548. File: gettext.info,  Node: Initial,  Next: Updating,  Prev: Sources,  Up: Top
  549. Making the Initial PO File
  550. **************************
  551. * Menu:
  552. * xgettext Invocation::         Invoking the `xgettext' Program
  553. * C Sources Context::           C Sources Context
  554. * Compendium::                  Using Translation Compendiums
  555. File: gettext.info,  Node: xgettext Invocation,  Next: C Sources Context,  Prev: Initial,  Up: Initial
  556. Invoking the `xgettext' Program
  557. ===============================
  558.      xgettext [OPTION] INPUTFILE ...
  559. `--extract-all'
  560.      Extract all strings.
  561. `-c [TAG]'
  562. `--add-comments[=TAG]'
  563.      Place comment block with TAG (or those preceding keyword lines) in
  564.      output file.
  565. `--c++'
  566.      Recognize C++ style comments.
  567. `--debug'
  568.      Use the flags `c-format' and `possible-c-format' to show who was
  569.      responsible for marking a message as a format string.  The later
  570.      form is used if the `xgettext' program decided, the format form is
  571.      used if the programmer prescribed it.
  572.      By default only the `c-format' form is used.  The translator should
  573.      not have to care about these details.
  574. `-d NAME'
  575. `--default-domain=NAME'
  576.      Use `NAME.po' for output (instead of `messages.po').
  577.      The special domain name `-' or `/dev/stdout' means to write the
  578.      output to `stdout'.
  579. `-D DIRECTORY'
  580. `--directory=DIRECTORY'
  581.      Change to DIRECTORY before beginning to search and scan source
  582.      files.  The resulting `.po' file will be written relative to the
  583.      original directory, though.
  584. `-f FILE'
  585. `--files-from=FILE'
  586.      Read the names of the input files from FILE instead of getting
  587.      them from the command line.
  588. `--force'
  589.      Always write output file even if no message is defined.
  590. `--help'
  591.      Display this help and exit.
  592. `-I LIST'
  593. `--input-path=LIST'
  594.      List of directories searched for input files.
  595. `--join-existing'
  596.      Join messages with existing file.
  597. `-k WORD'
  598. `--keyword[=WORD]'
  599.      Additonal keyword to be looked for (without WORD means not to use
  600.      default keywords).
  601.      The default keywords, which are always looked for if not explicitly
  602.      disabled, are `gettext', `dgettext', `dcgettext' and
  603.      `gettext_noop'.
  604. `-m [STRING]'
  605. `--msgstr-prefix[=STRING]'
  606.      Use STRING or "" as prefix for msgstr entries.
  607. `-M [STRING]'
  608. `--msgstr-suffix[=STRING]'
  609.      Use STRING or "" as suffix for msgstr entries.
  610. `--no-location'
  611.      Do not write `#: FILENAME:LINE' lines.
  612. `--add-location'
  613.      Generate `#: FILENAME:LINE' lines (default).
  614. `--omit-header'
  615.      Don't write header with `msgid ""' entry.
  616.      This is useful for testing purposes because it eliminates a source
  617.      of variance for generated `.gmo' files.  We can ship some of these
  618.      files in the GNU `gettext' package, and the result of regenerating
  619.      them through `msgfmt' should yield the same values.
  620. `-p DIR'
  621. `--output-dir=DIR'
  622.      Output files will be placed in directory DIR.
  623. `--sort-output'
  624.      Generate sorted output and remove duplicates.
  625. `--strict'
  626.      Write out strict Uniforum conforming PO file.
  627. `--version'
  628.      Output version information and exit.
  629. `-x FILE'
  630. `--exclude-file=FILE'
  631.      Entries from FILE are not extracted.
  632.    Search path for supplementary PO files is:
  633. `/usr/local/share/nls/src/'.
  634.    If INPUTFILE is `-', standard input is read.
  635.    This implementation of `xgettext' is able to process a few awkward
  636. cases, like strings in preprocessor macros, ANSI concatenation of
  637. adjacent strings, and escaped end of lines for continued strings.
  638. File: gettext.info,  Node: C Sources Context,  Next: Compendium,  Prev: xgettext Invocation,  Up: Initial
  639. C Sources Context
  640. =================
  641.    PO mode is particularily powerful when used with PO files created
  642. through GNU `gettext' utilities, as those utilities insert special
  643. comments in the PO files they generate.  Some of these special comments
  644. relate the PO file entry to exactly where the untranslated string
  645. appears in the program sources.
  646.    When the translator gets to an untranslated entry, she is fairly
  647. often faced with an original string which is not as informative as it
  648. normally should be, being succinct, cryptic, or otherwise ambiguous.
  649. Before chosing how to translate the string, she needs to understand
  650. better what the string really means and how tight the translation has
  651. to be.  Most of times, when problems arise, the only way left to make
  652. her judgment is looking at the true program sources from where this
  653. string originated, searching for surrounding comments the programmer
  654. might have put in there, and looking around for helping clues of *any*
  655. kind.
  656.    Surely, when looking at program sources, the translator will receive
  657. more help if she is a fluent programmer.  However, even if she is not
  658. versed in programming and feels a little lost in C code, the translator
  659. should not be shy at taking a look, once in a while.  It is most
  660. probable that she will still be able to find some of the hints she
  661. needs.  She will learn quickly to not feel uncomfortable in program
  662. code, paying more attention to programmer's comments, variable and
  663. function names (if he dared chosing them well), and overall
  664. organization, than to programmation itself.
  665.    The following commands are meant to help the translator at getting
  666. program source context for a PO file entry.
  667.      Resume the display of a program source context, or cycle through
  668.      them.
  669. `M-s'
  670.      Display of a program source context selected by menu.
  671.      Add a directory to the search path for source files.
  672. `M-S'
  673.      Delete a directory from the search path for source files.
  674.    The commands `s' (`po-cycle-reference') and `M-s'
  675. (`po-select-source-reference') both open another window displaying some
  676. source program file, and already positioned in such a way that it shows
  677. an actual use of the string to be translated.  By doing so, the command
  678. gives source program context for the string.  But if the entry has no
  679. source context references, or if all references are unresolved along
  680. the search path for program sources, then the command diagnoses this as
  681. an error.
  682.    Even if `s' (or `M-s') opens a new window, the cursor stays in the
  683. PO file window.  If the translator really wants to get into the program
  684. source window, she ought to do it explicitly, maybe by using command
  685.    When `s' is typed for the first time, or for a PO file entry which
  686. is different of the last one used for getting source context, then the
  687. command reacts by giving the first context available for this entry, if
  688. any.  If some context has already been recently displayed for the
  689. current PO file entry, and the translator wandered off to do other
  690. things, typing `s' again will merely resume, in another window, the
  691. context last displayed.  In particular, if the translator moved the
  692. cursor away from the context in the source file, the command will bring
  693. the cursor back to the context.  By using `s' many times in a row, with
  694. no other commands intervening, PO mode will cycle to the next available
  695. contexts for this particular entry, getting back to the first context
  696. once the last has been shown.
  697.    The command `M-s' behaves differently.  Instead of cycling through
  698. references, it lets the translator choose of particular reference among
  699. many, and displays that reference.  It is best used with completion, if
  700. the translator types `TAB' immediately after `M-s', in response to the
  701. question, she will be offered a menu of all possible references, as a
  702. reminder of which are the acceptable answers.  This command is useful
  703. only where there are really many contexts available for a single string
  704. to translate.
  705.    Program source files are usually found relative to where the PO file
  706. stands.  As a special provision, when this fails, the file is also
  707. looked for, but relative to the directory immediately above it.  Those
  708. two cases take proper care of most PO files.  However, it might happen
  709. that a PO file has been moved, or is edited in a different place than
  710. its normal location.  When this happens, the translator should tell PO
  711. mode in which directory normally sits the genuine PO file.  Many such
  712. directories may be specified, and all together, they constitute what is
  713. called the "search path" for program sources.  The command `S'
  714. (`po-consider-source-path') is used to interactively enter a new
  715. directory at the front of the search path, and the command `M-S'
  716. (`po-ignore-source-path') is used to select, with completion, one of
  717. the directories she does not want anymore on the search path.
  718. File: gettext.info,  Node: Compendium,  Prev: C Sources Context,  Up: Initial
  719. Using Translation Compendiums
  720. =============================
  721.    Compendiums are yet to be implemented.
  722.    An incoming PO mode feature will let the translator maintain a
  723. compendium of already achieved translations.  A "compendium" is a
  724. special PO file containing a set of translations recurring in many
  725. different packages.  The translator will be given commands for adding
  726. entries to her compendium, and later initializing untranslated entries,
  727. or updating already translated entries, from translations kept in the
  728. compendium.  For this to work, however, the compendium would have to be
  729. normalized.  *Note Normalizing::.
  730. File: gettext.info,  Node: Updating,  Next: Binaries,  Prev: Initial,  Up: Top
  731. Updating Existing PO Files
  732. **************************
  733. * Menu:
  734. * msgmerge Invocation::         Invoking the `msgmerge' Program
  735. * Fuzzy Entries::
  736. * Untranslated Entries::        Untranslated Entries
  737. * Obsolete Entries::            Obsolete Entries
  738. * Modifying Translations::      Modifying Translations
  739. * Modifying Comments::          Modifying Comments
  740. * Auxiliary::                   Consulting Auxiliary PO Files
  741. File: gettext.info,  Node: msgmerge Invocation,  Next: Fuzzy Entries,  Prev: Updating,  Up: Updating
  742. Invoking the `msgmerge' Program
  743. ===============================
  744. File: gettext.info,  Node: Fuzzy Entries,  Next: Untranslated Entries,  Prev: msgmerge Invocation,  Up: Updating
  745. Fuzzy Entries
  746. =============
  747.    Each PO file entry may have a set of "attributes", which are
  748. qualities given an name and explicitely associated with the entry
  749. translation, using a special system comment.  One of these attributes
  750. has the name `fuzzy', and entries having this attribute are said to
  751. have a fuzzy translation.  They are called fuzzy entries, for short.
  752.    Fuzzy entries, even if they account for translated entries for most
  753. other purposes, usually call for revision by the translator.  Those may
  754. be produced by applying the program `msgmerge' to update an older
  755. translated PO files according to a new PO template file, when this tool
  756. hypothesises that some new `msgid' has been modified only slightly out
  757. of an older one, and chooses to pair what it thinks to be the old
  758. translation for the new modified entry.  The slight alteration in the
  759. original string (the `msgid' string) should often be reflected in the
  760. translated string, and this requires the intervention of the
  761. translator.  For this reason, `msgmerge' might mark some entries as
  762. being fuzzy.
  763.    Also, the translator may decide herself to mark an entry as fuzzy
  764. for her own convenience, when she wants to remember that the entry has
  765. to be later revisited.  So, some commands are more specifically related
  766. to fuzzy entry processing.
  767.      Find the next fuzzy entry.
  768. `M-f'
  769.      Find the previous fuzzy entry.
  770. `TAB'
  771.      Remove the fuzzy attribute of the current entry.
  772.    The commands `f' (`po-next-fuzzy') and `M-f' (`po-previous-fuzzy')
  773. move forwards or backwards, chasing for a fuzzy entry.  If none is
  774. found, the search is extended and wraps around in the PO file buffer.
  775.    The command `TAB' (`po-unfuzzy') removes the fuzzy attribute
  776. associated with an entry, usually leaving it translated.  Further, if
  777. the variable `po-auto-select-on-unfuzzy' has not the `nil' value, the
  778. `TAB' command will automatically chase for another interesting entry to
  779. work on.  The initial value of `po-auto-select-on-unfuzzy' is `t'.
  780.    Unless the variable `po-auto-fuzzy-on-edit' has been reset to `nil',
  781. any entry edited through the `RET' command is marked fuzzy, asking for
  782. later confirmation.  The usual paradigm is that an entry becomes fuzzy
  783. (if not already) whenever the translator modifies it.  If she is
  784. satisfied with the translation, she then uses `TAB' to pick another
  785. entry to work on, clearing the fuzzy attribute on the same blow.  If
  786. she is not satisfied yet, she merely uses `SPC' to chase another entry,
  787. leaving the entry fuzzy.  The initial value of `po-auto-fuzzy-on-edit'
  788. is `t'.
  789.    The translator may also use the `DEL' command (`po-fade-out-entry')
  790. over any translated entry to mark it as being fuzzy, when she wants to
  791. easily leave a trace she wants to later return working at this entry.
  792.    Also, when time comes to quit working on a PO file buffer with the
  793. `Q' command, the translator is asked for confirmation, if some fuzzy
  794. string still exists.
  795. File: gettext.info,  Node: Untranslated Entries,  Next: Obsolete Entries,  Prev: Fuzzy Entries,  Up: Updating
  796. Untranslated Entries
  797. ====================
  798.    When `xgettext' originally creates a PO file, unless told otherwise,
  799. it initializes the `msgid' field with the untranslated string, and
  800. leaves the `msgstr' string to be empty.  Such entries, having an empty
  801. translation, are said to be "untranslated" entries.  Later, when the
  802. programmer slightly modifies some string right in the program, this
  803. change is later reflected in the PO file by the appearance of a new
  804. untranslated entry for the modified string.
  805.    The usual commands moving from entry to entry consider untranslated
  806. entries on the same level as active entries.  Untranslated entries are
  807. easily recognizable by the fact they end with `msgstr ""'.
  808.    The work of the translator might be (quite naively) seen as the
  809. process of seeking after an untranslated entry, editing a translation
  810. for it, and repeating these actions until no untranslated entries
  811. remain.  Some commands are more specifically related to untranslated
  812. entry processing.
  813.      Find the next untranslated entry.
  814. `M-u'
  815.      Find the previous untranslated entry.
  816.      Turn the current entry into an untranslated one.
  817.    The commands `u' (`po-next-untranslated-entry') and `M-u'
  818. (`po-previous-untransted-entry') move forwards or backwards, chasing
  819. for an untranslated entry.  If none is found, the search is extended
  820. and wraps around in the PO file buffer.
  821.    An entry can be turned back into an untranslated entry by merely
  822. emptying its translation, using the command `k' (`po-kill-msgstr').
  823. *Note Modifying Translations::.
  824.    Also, when time comes to quit working on a PO file buffer with the
  825. `Q' command, the translator is asked for confirmation, if some
  826. untranslated string still exists.
  827. File: gettext.info,  Node: Obsolete Entries,  Next: Modifying Translations,  Prev: Untranslated Entries,  Up: Updating
  828. Obsolete Entries
  829. ================
  830.    By "obsolete" PO file entries, we mean those entries which are
  831. commented out, usually by `msgmerge' when it found that the translation
  832. is not needed anymore by the package being localized.
  833.    The usual commands moving from entry to entry consider obsolete
  834. entries on the same level as active entries.  Obsolete entries are
  835. easily recognizable by the fact that all their lines start with `#',
  836. even those lines containing `msgid' or `msgstr'.
  837.    Commands exist for emptying the translation or reinitializing it to
  838. the original untranslated string.  Commands interfacing with the kill
  839. ring may force some previously saved text into the translation.  The
  840. user may interactively edit the translation.  All these commands may
  841. apply to obsolete entries, carefully leaving the entry obsolete after
  842. the fact.
  843.    Moreover, some commands are more specifically related to obsolete
  844. entry processing.
  845.      Find the next obsolete entry.
  846. `M-o'
  847.      Find the previous obsolete entry.
  848.      Make an active entry obsolete, or zap out an obsolete entry.
  849.    The commands `o' (`po-next-obsolete-entry') and `M-o'
  850. (`po-previous-obsolete-entry') move forwards or backwards, chasing for
  851. an obsolete entry.  If none is found, the search is extended and wraps
  852. around in the PO file buffer.
  853.    PO mode does not provide ways for un-commenting an obsolete entry
  854. and making it active, because this would reintroduce an original
  855. untranslated string which does not correspond to any marked string in
  856. the program sources.  This goes with the philosophy of never
  857. introducing useless `msgid' values.
  858.    However, it is possible to comment out an active entry, so making it
  859. obsolete.  GNU `gettext' utilities will later react to the
  860. disappearance of a translation by using the untranslated string.  The
  861. command `z' (`po-fade-out-entry') pushes the current entry a little
  862. further towards annihilation.  If the entry is active, then the entry
  863. is merely commented out.  If the entry is already obsolete, then it is
  864. completely deleted from the PO file.  It is easy to recycle the
  865. translation so deleted into some other PO file entry, usually one which
  866. is untranslated.  *Note Modifying Translations::.
  867.    Here is a quite interesting problem to solve for later development of
  868. PO mode, for those nights you are not sleepy.  The idea would be that
  869. PO mode might become bright enough, one of these days, to make good
  870. guesses at retrieving the most probable candidate, among all obsolete
  871. entries, for initializing the translation of a newly appeared string.
  872. I think it might be a quite hard problem to do this algorithmically, as
  873. we have to develop good and efficient measures of string similarity.
  874. Right now, PO mode completely lets the decision to the translator, when
  875. the time comes to find the adequate obsolete translation, it merely
  876. tries to provide handy tools for helping her to do so.
  877.