~ubuntu-branches/ubuntu/breezy/gettext/breezy

« back to all changes in this revision

Viewing changes to doc/gettext_2.html

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2004-03-14 17:40:02 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040314174002-p1ad5ldve1hqzhye
Tags: 0.14.1-2
* Added libexpat1-dev to Build-Depends, for glade support.
* Added libc0.1-dev to Build-Depends, for GNU/kFreeBSD.
* Removed special-casing of knetbsd-gnu in debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML>
2
 
<HEAD>
3
 
<!-- This HTML file has been created by texi2html 1.51
4
 
     from gettext.texi on 15 September 2001 -->
5
 
 
6
 
<TITLE>GNU gettext utilities - 2  PO Files and PO Mode Basics</TITLE>
7
 
</HEAD>
8
 
<BODY>
9
 
Go to the <A HREF="gettext_1.html">first</A>, <A HREF="gettext_1.html">previous</A>, <A HREF="gettext_3.html">next</A>, <A HREF="gettext_14.html">last</A> section, <A HREF="gettext_toc.html">table of contents</A>.
10
 
<P><HR><P>
11
 
 
12
 
 
13
 
<H1><A NAME="SEC7" HREF="gettext_toc.html#TOC7">2  PO Files and PO Mode Basics</A></H1>
14
 
 
15
 
<P>
16
 
The GNU <CODE>gettext</CODE> toolset helps programmers and translators
17
 
at producing, updating and using translation files, mainly those
18
 
PO files which are textual, editable files.  This chapter stresses
19
 
the format of PO files, and contains a PO mode starter.  PO mode
20
 
description is spread throughout this manual instead of being concentrated
21
 
in one place.  Here we present only the basics of PO mode.
22
 
 
23
 
</P>
24
 
 
25
 
 
26
 
 
27
 
<H2><A NAME="SEC8" HREF="gettext_toc.html#TOC8">2.1  Completing GNU <CODE>gettext</CODE> Installation</A></H2>
28
 
 
29
 
<P>
30
 
Once you have received, unpacked, configured and compiled the GNU
31
 
<CODE>gettext</CODE> distribution, the <SAMP>`make install'</SAMP> command puts in
32
 
place the programs <CODE>xgettext</CODE>, <CODE>msgfmt</CODE>, <CODE>gettext</CODE>, and
33
 
<CODE>msgmerge</CODE>, as well as their available message catalogs.  To
34
 
top off a comfortable installation, you might also want to make the
35
 
PO mode available to your Emacs users.
36
 
 
37
 
</P>
38
 
<P>
39
 
During the installation of the PO mode, you might want to modify your
40
 
file <TT>`.emacs'</TT>, once and for all, so it contains a few lines looking
41
 
like:
42
 
 
43
 
</P>
44
 
 
45
 
<PRE>
46
 
(setq auto-mode-alist
47
 
      (cons '("\\.po[tx]?\\'\\|\\.po\\." . po-mode) auto-mode-alist))
48
 
(autoload 'po-mode "po-mode" "Major mode for translators to edit PO files" t)
49
 
</PRE>
50
 
 
51
 
<P>
52
 
Later, whenever you edit some <TT>`.po'</TT>, <TT>`.pot'</TT> or <TT>`.pox'</TT>
53
 
file, or any file having the string <SAMP>`.po.'</SAMP> within its name,
54
 
Emacs loads <TT>`po-mode.elc'</TT> (or <TT>`po-mode.el'</TT>) as needed, and
55
 
automatically activates PO mode commands for the associated buffer.
56
 
The string <EM>PO</EM> appears in the mode line for any buffer for
57
 
which PO mode is active.  Many PO files may be active at once in a
58
 
single Emacs session.
59
 
 
60
 
</P>
61
 
<P>
62
 
If you are using Emacs version 20 or newer, and have already installed
63
 
the appropriate international fonts on your system, you may also tell
64
 
Emacs how to determine automatically the coding system of every PO file.
65
 
This will often (but not always) cause the necessary fonts to be loaded
66
 
and used for displaying the translations on your Emacs screen.  For this
67
 
to happen, add the lines:
68
 
 
69
 
</P>
70
 
 
71
 
<PRE>
72
 
(modify-coding-system-alist 'file "\\.po[tx]?\\'\\|\\.po\\."
73
 
                            'po-find-file-coding-system)
74
 
(autoload 'po-find-file-coding-system "po-mode")
75
 
</PRE>
76
 
 
77
 
<P>
78
 
to your <TT>`.emacs'</TT> file.  If, with this, you still see boxes instead
79
 
of international characters, try a different font set (via Shift Mouse
80
 
button 1).
81
 
 
82
 
</P>
83
 
 
84
 
 
85
 
<H2><A NAME="SEC9" HREF="gettext_toc.html#TOC9">2.2  The Format of PO Files</A></H2>
86
 
 
87
 
<P>
88
 
A PO file is made up of many entries, each entry holding the relation
89
 
between an original untranslated string and its corresponding
90
 
translation.  All entries in a given PO file usually pertain
91
 
to a single project, and all translations are expressed in a single
92
 
target language.  One PO file <STRONG>entry</STRONG> has the following schematic
93
 
structure:
94
 
 
95
 
</P>
96
 
 
97
 
<PRE>
98
 
<VAR>white-space</VAR>
99
 
#  <VAR>translator-comments</VAR>
100
 
#. <VAR>automatic-comments</VAR>
101
 
#: <VAR>reference</VAR>...
102
 
#, <VAR>flag</VAR>...
103
 
msgid <VAR>untranslated-string</VAR>
104
 
msgstr <VAR>translated-string</VAR>
105
 
</PRE>
106
 
 
107
 
<P>
108
 
The general structure of a PO file should be well understood by
109
 
the translator.  When using PO mode, very little has to be known
110
 
about the format details, as PO mode takes care of them for her.
111
 
 
112
 
</P>
113
 
<P>
114
 
Entries begin with some optional white space.  Usually, when generated
115
 
through GNU <CODE>gettext</CODE> tools, there is exactly one blank line
116
 
between entries.  Then comments follow, on lines all starting with the
117
 
character <KBD>#</KBD>.  There are two kinds of comments: those which have
118
 
some white space immediately following the <KBD>#</KBD>, which comments are
119
 
created and maintained exclusively by the translator, and those which
120
 
have some non-white character just after the <KBD>#</KBD>, which comments
121
 
are created and maintained automatically by GNU <CODE>gettext</CODE> tools.
122
 
All comments, of either kind, are optional.
123
 
 
124
 
</P>
125
 
<P>
126
 
After white space and comments, entries show two strings, namely
127
 
first the untranslated string as it appears in the original program
128
 
sources, and then, the translation of this string.  The original
129
 
string is introduced by the keyword <CODE>msgid</CODE>, and the translation,
130
 
by <CODE>msgstr</CODE>.  The two strings, untranslated and translated,
131
 
are quoted in various ways in the PO file, using <KBD>"</KBD>
132
 
delimiters and <KBD>\</KBD> escapes, but the translator does not really
133
 
have to pay attention to the precise quoting format, as PO mode fully
134
 
takes care of quoting for her.
135
 
 
136
 
</P>
137
 
<P>
138
 
The <CODE>msgid</CODE> strings, as well as automatic comments, are produced
139
 
and managed by other GNU <CODE>gettext</CODE> tools, and PO mode does not
140
 
provide means for the translator to alter these.  The most she can
141
 
do is merely deleting them, and only by deleting the whole entry.
142
 
On the other hand, the <CODE>msgstr</CODE> string, as well as translator
143
 
comments, are really meant for the translator, and PO mode gives her
144
 
the full control she needs.
145
 
 
146
 
</P>
147
 
<P>
148
 
The comment lines beginning with <KBD>#,</KBD> are special because they are
149
 
not completely ignored by the programs as comments generally are.  The
150
 
comma separated list of <VAR>flag</VAR>s is used by the <CODE>msgfmt</CODE>
151
 
program to give the user some better diagnostic messages.  Currently
152
 
there are two forms of flags defined:
153
 
 
154
 
</P>
155
 
<DL COMPACT>
156
 
 
157
 
<DT><KBD>fuzzy</KBD>
158
 
<DD>
159
 
This flag can be generated by the <CODE>msgmerge</CODE> program or it can be
160
 
inserted by the translator herself.  It shows that the <CODE>msgstr</CODE>
161
 
string might not be a correct translation (anymore).  Only the translator
162
 
can judge if the translation requires further modification, or is
163
 
acceptable as is.  Once satisfied with the translation, she then removes
164
 
this <KBD>fuzzy</KBD> attribute.  The <CODE>msgmerge</CODE> program inserts this
165
 
when it combined the <CODE>msgid</CODE> and <CODE>msgstr</CODE> entries after fuzzy
166
 
search only.  See section <A HREF="gettext_6.html#SEC25">6.3  Fuzzy Entries</A>.
167
 
 
168
 
<DT><KBD>c-format</KBD>
169
 
<DD>
170
 
<DT><KBD>no-c-format</KBD>
171
 
<DD>
172
 
These flags should not be added by a human.  Instead only the
173
 
<CODE>xgettext</CODE> program adds them.  In an automatized PO file processing
174
 
system as proposed here the user changes would be thrown away again as
175
 
soon as the <CODE>xgettext</CODE> program generates a new template file.
176
 
 
177
 
In case the <KBD>c-format</KBD> flag is given for a string the <CODE>msgfmt</CODE>
178
 
does some more tests to check to validity of the translation.
179
 
See section <A HREF="gettext_7.html#SEC35">7.1  Invoking the <CODE>msgfmt</CODE> Program</A>.
180
 
 
181
 
</DL>
182
 
 
183
 
<P>
184
 
A different kind of entries is used for translations which involve
185
 
plural forms.
186
 
 
187
 
</P>
188
 
 
189
 
<PRE>
190
 
<VAR>white-space</VAR>
191
 
#  <VAR>translator-comments</VAR>
192
 
#. <VAR>automatic-comments</VAR>
193
 
#: <VAR>reference</VAR>...
194
 
#, <VAR>flag</VAR>...
195
 
msgid <VAR>untranslated-string-singular</VAR>
196
 
msgid_plural <VAR>untranslated-string-plural</VAR>
197
 
msgstr[0] <VAR>translated-string-case-0</VAR>
198
 
...
199
 
msgstr[N] <VAR>translated-string-case-n</VAR>
200
 
</PRE>
201
 
 
202
 
<P>
203
 
It happens that some lines, usually whitespace or comments, follow the
204
 
very last entry of a PO file.  Such lines are not part of any entry,
205
 
and PO mode is unable to take action on those lines.  By using the
206
 
PO mode function <KBD>M-x po-normalize</KBD>, the translator may get
207
 
rid of those spurious lines.  See section <A HREF="gettext_2.html#SEC12">2.5  Normalizing Strings in Entries</A>.
208
 
 
209
 
</P>
210
 
<P>
211
 
The remainder of this section may be safely skipped by those using
212
 
PO mode, yet it may be interesting for everybody to have a better
213
 
idea of the precise format of a PO file.  On the other hand, those
214
 
not having Emacs handy should carefully continue reading on.
215
 
 
216
 
</P>
217
 
<P>
218
 
Each of <VAR>untranslated-string</VAR> and <VAR>translated-string</VAR> respects
219
 
the C syntax for a character string, including the surrounding quotes
220
 
and imbedded backslashed escape sequences.  When the time comes
221
 
to write multi-line strings, one should not use escaped newlines.
222
 
Instead, a closing quote should follow the last character on the
223
 
line to be continued, and an opening quote should resume the string
224
 
at the beginning of the following PO file line.  For example:
225
 
 
226
 
</P>
227
 
 
228
 
<PRE>
229
 
msgid ""
230
 
"Here is an example of how one might continue a very long string\n"
231
 
"for the common case the string represents multi-line output.\n"
232
 
</PRE>
233
 
 
234
 
<P>
235
 
In this example, the empty string is used on the first line, to
236
 
allow better alignment of the <KBD>H</KBD> from the word <SAMP>`Here'</SAMP>
237
 
over the <KBD>f</KBD> from the word <SAMP>`for'</SAMP>.  In this example, the
238
 
<CODE>msgid</CODE> keyword is followed by three strings, which are meant
239
 
to be concatenated.  Concatenating the empty string does not change
240
 
the resulting overall string, but it is a way for us to comply with
241
 
the necessity of <CODE>msgid</CODE> to be followed by a string on the same
242
 
line, while keeping the multi-line presentation left-justified, as
243
 
we find this to be a cleaner disposition.  The empty string could have
244
 
been omitted, but only if the string starting with <SAMP>`Here'</SAMP> was
245
 
promoted on the first line, right after <CODE>msgid</CODE>.<A NAME="DOCF2" HREF="gettext_foot.html#FOOT2">(2)</A> It was not really necessary
246
 
either to switch between the two last quoted strings immediately after
247
 
the newline <SAMP>`\n'</SAMP>, the switch could have occurred after <EM>any</EM>
248
 
other character, we just did it this way because it is neater.
249
 
 
250
 
</P>
251
 
<P>
252
 
One should carefully distinguish between end of lines marked as
253
 
<SAMP>`\n'</SAMP> <EM>inside</EM> quotes, which are part of the represented
254
 
string, and end of lines in the PO file itself, outside string quotes,
255
 
which have no incidence on the represented string.
256
 
 
257
 
</P>
258
 
<P>
259
 
Outside strings, white lines and comments may be used freely.
260
 
Comments start at the beginning of a line with <SAMP>`#'</SAMP> and extend
261
 
until the end of the PO file line.  Comments written by translators
262
 
should have the initial <SAMP>`#'</SAMP> immediately followed by some white
263
 
space.  If the <SAMP>`#'</SAMP> is not immediately followed by white space,
264
 
this comment is most likely generated and managed by specialized GNU
265
 
tools, and might disappear or be replaced unexpectedly when the PO
266
 
file is given to <CODE>msgmerge</CODE>.
267
 
 
268
 
</P>
269
 
 
270
 
 
271
 
<H2><A NAME="SEC10" HREF="gettext_toc.html#TOC10">2.3  Main PO mode Commands</A></H2>
272
 
 
273
 
<P>
274
 
After setting up Emacs with something similar to the lines in
275
 
section <A HREF="gettext_2.html#SEC8">2.1  Completing GNU <CODE>gettext</CODE> Installation</A>, PO mode is activated for a window when Emacs finds a
276
 
PO file in that window.  This puts the window read-only and establishes a
277
 
po-mode-map, which is a genuine Emacs mode, in a way that is not derived
278
 
from text mode in any way.  Functions found on <CODE>po-mode-hook</CODE>,
279
 
if any, will be executed.
280
 
 
281
 
</P>
282
 
<P>
283
 
When PO mode is active in a window, the letters <SAMP>`PO'</SAMP> appear
284
 
in the mode line for that window.  The mode line also displays how
285
 
many entries of each kind are held in the PO file.  For example,
286
 
the string <SAMP>`132t+3f+10u+2o'</SAMP> would tell the translator that the
287
 
PO mode contains 132 translated entries (see section <A HREF="gettext_6.html#SEC24">6.2  Translated Entries</A>,
288
 
3 fuzzy entries (see section <A HREF="gettext_6.html#SEC25">6.3  Fuzzy Entries</A>), 10 untranslated entries
289
 
(see section <A HREF="gettext_6.html#SEC26">6.4  Untranslated Entries</A>) and 2 obsolete entries (see section <A HREF="gettext_6.html#SEC27">6.5  Obsolete Entries</A>).  Zero-coefficients items are not shown.  So, in this example, if
290
 
the fuzzy entries were unfuzzied, the untranslated entries were translated
291
 
and the obsolete entries were deleted, the mode line would merely display
292
 
<SAMP>`145t'</SAMP> for the counters.
293
 
 
294
 
</P>
295
 
<P>
296
 
The main PO commands are those which do not fit into the other categories of
297
 
subsequent sections.  These allow for quitting PO mode or for managing windows
298
 
in special ways.
299
 
 
300
 
</P>
301
 
<DL COMPACT>
302
 
 
303
 
<DT><KBD>U</KBD>
304
 
<DD>
305
 
Undo last modification to the PO file.
306
 
 
307
 
<DT><KBD>Q</KBD>
308
 
<DD>
309
 
Quit processing and save the PO file.
310
 
 
311
 
<DT><KBD>q</KBD>
312
 
<DD>
313
 
Quit processing, possibly after confirmation.
314
 
 
315
 
<DT><KBD>O</KBD>
316
 
<DD>
317
 
Temporary leave the PO file window.
318
 
 
319
 
<DT><KBD>?</KBD>
320
 
<DD>
321
 
<DT><KBD>h</KBD>
322
 
<DD>
323
 
Show help about PO mode.
324
 
 
325
 
<DT><KBD>=</KBD>
326
 
<DD>
327
 
Give some PO file statistics.
328
 
 
329
 
<DT><KBD>V</KBD>
330
 
<DD>
331
 
Batch validate the format of the whole PO file.
332
 
 
333
 
</DL>
334
 
 
335
 
<P>
336
 
The command <KBD>U</KBD> (<CODE>po-undo</CODE>) interfaces to the Emacs
337
 
<EM>undo</EM> facility.  See section `Undoing Changes' in <CITE>The Emacs Editor</CITE>.  Each time <KBD>U</KBD> is typed, modifications which the translator
338
 
did to the PO file are undone a little more.  For the purpose of
339
 
undoing, each PO mode command is atomic.  This is especially true for
340
 
the <KBD><KBD>RET</KBD></KBD> command: the whole edition made by using a single
341
 
use of this command is undone at once, even if the edition itself
342
 
implied several actions.  However, while in the editing window, one
343
 
can undo the edition work quite parsimoniously.
344
 
 
345
 
</P>
346
 
<P>
347
 
The commands <KBD>Q</KBD> (<CODE>po-quit</CODE>) and <KBD>q</KBD>
348
 
(<CODE>po-confirm-and-quit</CODE>) are used when the translator is done with the
349
 
PO file.  The former is a bit less verbose than the latter.  If the file
350
 
has been modified, it is saved to disk first.  In both cases, and prior to
351
 
all this, the commands check if some untranslated message remains in the
352
 
PO file and, if yes, the translator is asked if she really wants to leave
353
 
off working with this PO file.  This is the preferred way of getting rid
354
 
of an Emacs PO file buffer.  Merely killing it through the usual command
355
 
<KBD>C-x k</KBD> (<CODE>kill-buffer</CODE>) is not the tidiest way to proceed.
356
 
 
357
 
</P>
358
 
<P>
359
 
The command <KBD>O</KBD> (<CODE>po-other-window</CODE>) is another, softer way,
360
 
to leave PO mode, temporarily.  It just moves the cursor to some other
361
 
Emacs window, and pops one if necessary.  For example, if the translator
362
 
just got PO mode to show some source context in some other, she might
363
 
discover some apparent bug in the program source that needs correction.
364
 
This command allows the translator to change sex, become a programmer,
365
 
and have the cursor right into the window containing the program she
366
 
(or rather <EM>he</EM>) wants to modify.  By later getting the cursor back
367
 
in the PO file window, or by asking Emacs to edit this file once again,
368
 
PO mode is then recovered.
369
 
 
370
 
</P>
371
 
<P>
372
 
The command <KBD>h</KBD> (<CODE>po-help</CODE>) displays a summary of all available PO
373
 
mode commands.  The translator should then type any character to resume
374
 
normal PO mode operations.  The command <KBD>?</KBD> has the same effect
375
 
as <KBD>h</KBD>.
376
 
 
377
 
</P>
378
 
<P>
379
 
The command <KBD>=</KBD> (<CODE>po-statistics</CODE>) computes the total number of
380
 
entries in the PO file, the ordinal of the current entry (counted from
381
 
1), the number of untranslated entries, the number of obsolete entries,
382
 
and displays all these numbers.
383
 
 
384
 
</P>
385
 
<P>
386
 
The command <KBD>V</KBD> (<CODE>po-validate</CODE>) launches <CODE>msgfmt</CODE> in verbose
387
 
mode over the current PO file.  This command first offers to save the
388
 
current PO file on disk.  The <CODE>msgfmt</CODE> tool, from GNU <CODE>gettext</CODE>,
389
 
has the purpose of creating a MO file out of a PO file, and PO mode uses
390
 
the features of this program for checking the overall format of a PO file,
391
 
as well as all individual entries.
392
 
 
393
 
</P>
394
 
<P>
395
 
The program <CODE>msgfmt</CODE> runs asynchronously with Emacs, so the
396
 
translator regains control immediately while her PO file is being studied.
397
 
Error output is collected in the Emacs <SAMP>`*compilation*'</SAMP> buffer,
398
 
displayed in another window.  The regular Emacs command <KBD>C-x`</KBD>
399
 
(<CODE>next-error</CODE>), as well as other usual compile commands, allow the
400
 
translator to reposition quickly to the offending parts of the PO file.
401
 
Once the cursor is on the line in error, the translator may decide on
402
 
any PO mode action which would help correcting the error.
403
 
 
404
 
</P>
405
 
 
406
 
 
407
 
<H2><A NAME="SEC11" HREF="gettext_toc.html#TOC11">2.4  Entry Positioning</A></H2>
408
 
 
409
 
<P>
410
 
The cursor in a PO file window is almost always part of
411
 
an entry.  The only exceptions are the special case when the cursor
412
 
is after the last entry in the file, or when the PO file is
413
 
empty.  The entry where the cursor is found to be is said to be the
414
 
current entry.  Many PO mode commands operate on the current entry,
415
 
so moving the cursor does more than allowing the translator to browse
416
 
the PO file, this also selects on which entry commands operate.
417
 
 
418
 
</P>
419
 
<P>
420
 
Some PO mode commands alter the position of the cursor in a specialized
421
 
way.  A few of those special purpose positioning are described here,
422
 
the others are described in following sections.
423
 
 
424
 
</P>
425
 
<DL COMPACT>
426
 
 
427
 
<DT><KBD>.</KBD>
428
 
<DD>
429
 
Redisplay the current entry.
430
 
 
431
 
<DT><KBD>n</KBD>
432
 
<DD>
433
 
<DT><KBD>n</KBD>
434
 
<DD>
435
 
Select the entry after the current one.
436
 
 
437
 
<DT><KBD>p</KBD>
438
 
<DD>
439
 
<DT><KBD>p</KBD>
440
 
<DD>
441
 
Select the entry before the current one.
442
 
 
443
 
<DT><KBD>&#60;</KBD>
444
 
<DD>
445
 
Select the first entry in the PO file.
446
 
 
447
 
<DT><KBD>&#62;</KBD>
448
 
<DD>
449
 
Select the last entry in the PO file.
450
 
 
451
 
<DT><KBD>m</KBD>
452
 
<DD>
453
 
Record the location of the current entry for later use.
454
 
 
455
 
<DT><KBD>l</KBD>
456
 
<DD>
457
 
Return to a previously saved entry location.
458
 
 
459
 
<DT><KBD>x</KBD>
460
 
<DD>
461
 
Exchange the current entry location with the previously saved one.
462
 
 
463
 
</DL>
464
 
 
465
 
<P>
466
 
Any Emacs command able to reposition the cursor may be used
467
 
to select the current entry in PO mode, including commands which
468
 
move by characters, lines, paragraphs, screens or pages, and search
469
 
commands.  However, there is a kind of standard way to display the
470
 
current entry in PO mode, which usual Emacs commands moving
471
 
the cursor do not especially try to enforce.  The command <KBD>.</KBD>
472
 
(<CODE>po-current-entry</CODE>) has the sole purpose of redisplaying the
473
 
current entry properly, after the current entry has been changed by
474
 
means external to PO mode, or the Emacs screen otherwise altered.
475
 
 
476
 
</P>
477
 
<P>
478
 
It is yet to be decided if PO mode helps the translator, or otherwise
479
 
irritates her, by forcing a rigid window disposition while she
480
 
is doing her work.  We originally had quite precise ideas about
481
 
how windows should behave, but on the other hand, anyone used to
482
 
Emacs is often happy to keep full control.  Maybe a fixed window
483
 
disposition might be offered as a PO mode option that the translator
484
 
might activate or deactivate at will, so it could be offered on an
485
 
experimental basis.  If nobody feels a real need for using it, or
486
 
a compulsion for writing it, we should drop this whole idea.
487
 
The incentive for doing it should come from translators rather than
488
 
programmers, as opinions from an experienced translator are surely
489
 
more worth to me than opinions from programmers <EM>thinking</EM> about
490
 
how <EM>others</EM> should do translation.
491
 
 
492
 
</P>
493
 
<P>
494
 
The commands <KBD>n</KBD> (<CODE>po-next-entry</CODE>) and <KBD>p</KBD>
495
 
(<CODE>po-previous-entry</CODE>) move the cursor the entry following,
496
 
or preceding, the current one.  If <KBD>n</KBD> is given while the
497
 
cursor is on the last entry of the PO file, or if <KBD>p</KBD>
498
 
is given while the cursor is on the first entry, no move is done.
499
 
 
500
 
</P>
501
 
<P>
502
 
The commands <KBD>&#60;</KBD> (<CODE>po-first-entry</CODE>) and <KBD>&#62;</KBD>
503
 
(<CODE>po-last-entry</CODE>) move the cursor to the first entry, or last
504
 
entry, of the PO file.  When the cursor is located past the last
505
 
entry in a PO file, most PO mode commands will return an error saying
506
 
<SAMP>`After last entry'</SAMP>.  Moreover, the commands <KBD>&#60;</KBD> and <KBD>&#62;</KBD>
507
 
have the special property of being able to work even when the cursor
508
 
is not into some PO file entry, and one may use them for nicely
509
 
correcting this situation.  But even these commands will fail on a
510
 
truly empty PO file.  There are development plans for the PO mode for it
511
 
to interactively fill an empty PO file from sources.  See section <A HREF="gettext_3.html#SEC16">3.3  Marking Translatable Strings</A>.
512
 
 
513
 
</P>
514
 
<P>
515
 
The translator may decide, before working at the translation of
516
 
a particular entry, that she needs to browse the remainder of the
517
 
PO file, maybe for finding the terminology or phraseology used
518
 
in related entries.  She can of course use the standard Emacs idioms
519
 
for saving the current cursor location in some register, and use that
520
 
register for getting back, or else, use the location ring.
521
 
 
522
 
</P>
523
 
<P>
524
 
PO mode offers another approach, by which cursor locations may be saved
525
 
onto a special stack.  The command <KBD>m</KBD> (<CODE>po-push-location</CODE>)
526
 
merely adds the location of current entry to the stack, pushing
527
 
the already saved locations under the new one.  The command
528
 
<KBD>r</KBD> (<CODE>po-pop-location</CODE>) consumes the top stack element and
529
 
repositions the cursor to the entry associated with that top element.
530
 
This position is then lost, for the next <KBD>r</KBD> will move the cursor
531
 
to the previously saved location, and so on until no locations remain
532
 
on the stack.
533
 
 
534
 
</P>
535
 
<P>
536
 
If the translator wants the position to be kept on the location stack,
537
 
maybe for taking a look at the entry associated with the top
538
 
element, then go elsewhere with the intent of getting back later, she
539
 
ought to use <KBD>m</KBD> immediately after <KBD>r</KBD>.
540
 
 
541
 
</P>
542
 
<P>
543
 
The command <KBD>x</KBD> (<CODE>po-exchange-location</CODE>) simultaneously
544
 
repositions the cursor to the entry associated with the top element of
545
 
the stack of saved locations, and replaces that top element with the
546
 
location of the current entry before the move.  Consequently, repeating
547
 
the <KBD>x</KBD> command toggles alternatively between two entries.
548
 
For achieving this, the translator will position the cursor on the
549
 
first entry, use <KBD>m</KBD>, then position to the second entry, and
550
 
merely use <KBD>x</KBD> for making the switch.
551
 
 
552
 
</P>
553
 
 
554
 
 
555
 
<H2><A NAME="SEC12" HREF="gettext_toc.html#TOC12">2.5  Normalizing Strings in Entries</A></H2>
556
 
 
557
 
<P>
558
 
There are many different ways for encoding a particular string into a
559
 
PO file entry, because there are so many different ways to split and
560
 
quote multi-line strings, and even, to represent special characters
561
 
by backslahsed escaped sequences.  Some features of PO mode rely on
562
 
the ability for PO mode to scan an already existing PO file for a
563
 
particular string encoded into the <CODE>msgid</CODE> field of some entry.
564
 
Even if PO mode has internally all the built-in machinery for
565
 
implementing this recognition easily, doing it fast is technically
566
 
difficult.  To facilitate a solution to this efficiency problem,
567
 
we decided on a canonical representation for strings.
568
 
 
569
 
</P>
570
 
<P>
571
 
A conventional representation of strings in a PO file is currently
572
 
under discussion, and PO mode experiments with a canonical representation.
573
 
Having both <CODE>xgettext</CODE> and PO mode converging towards a uniform
574
 
way of representing equivalent strings would be useful, as the internal
575
 
normalization needed by PO mode could be automatically satisfied
576
 
when using <CODE>xgettext</CODE> from GNU <CODE>gettext</CODE>.  An explicit
577
 
PO mode normalization should then be only necessary for PO files
578
 
imported from elsewhere, or for when the convention itself evolves.
579
 
 
580
 
</P>
581
 
<P>
582
 
So, for achieving normalization of at least the strings of a given
583
 
PO file needing a canonical representation, the following PO mode
584
 
command is available:
585
 
 
586
 
</P>
587
 
<DL COMPACT>
588
 
 
589
 
<DT><KBD>M-x po-normalize</KBD>
590
 
<DD>
591
 
Tidy the whole PO file by making entries more uniform.
592
 
 
593
 
</DL>
594
 
 
595
 
<P>
596
 
The special command <KBD>M-x po-normalize</KBD>, which has no associated
597
 
keys, revises all entries, ensuring that strings of both original
598
 
and translated entries use uniform internal quoting in the PO file.
599
 
It also removes any crumb after the last entry.  This command may be
600
 
useful for PO files freshly imported from elsewhere, or if we ever
601
 
improve on the canonical quoting format we use.  This canonical format
602
 
is not only meant for getting cleaner PO files, but also for greatly
603
 
speeding up <CODE>msgid</CODE> string lookup for some other PO mode commands.
604
 
 
605
 
</P>
606
 
<P>
607
 
<KBD>M-x po-normalize</KBD> presently makes three passes over the entries.
608
 
The first implements heuristics for converting PO files for GNU
609
 
<CODE>gettext</CODE> 0.6 and earlier, in which <CODE>msgid</CODE> and <CODE>msgstr</CODE>
610
 
fields were using K&#38;R style C string syntax for multi-line strings.
611
 
These heuristics may fail for comments not related to obsolete
612
 
entries and ending with a backslash; they also depend on subsequent
613
 
passes for finalizing the proper commenting of continued lines for
614
 
obsolete entries.  This first pass might disappear once all oldish PO
615
 
files would have been adjusted.  The second and third pass normalize
616
 
all <CODE>msgid</CODE> and <CODE>msgstr</CODE> strings respectively.  They also
617
 
clean out those trailing backslashes used by XView's <CODE>msgfmt</CODE>
618
 
for continued lines.
619
 
 
620
 
</P>
621
 
<P>
622
 
Having such an explicit normalizing command allows for importing PO
623
 
files from other sources, but also eases the evolution of the current
624
 
convention, evolution driven mostly by aesthetic concerns, as of now.
625
 
It is easy to make suggested adjustments at a later time, as the
626
 
normalizing command and eventually, other GNU <CODE>gettext</CODE> tools
627
 
should greatly automate conformance.  A description of the canonical
628
 
string format is given below, for the particular benefit of those not
629
 
having Emacs handy, and who would nevertheless want to handcraft
630
 
their PO files in nice ways.
631
 
 
632
 
</P>
633
 
<P>
634
 
Right now, in PO mode, strings are single line or multi-line.  A string
635
 
goes multi-line if and only if it has <EM>embedded</EM> newlines, that
636
 
is, if it matches <SAMP>`[^\n]\n+[^\n]'</SAMP>.  So, we would have:
637
 
 
638
 
</P>
639
 
 
640
 
<PRE>
641
 
msgstr "\n\nHello, world!\n\n\n"
642
 
</PRE>
643
 
 
644
 
<P>
645
 
but, replacing the space by a newline, this becomes:
646
 
 
647
 
</P>
648
 
 
649
 
<PRE>
650
 
msgstr ""
651
 
"\n"
652
 
"\n"
653
 
"Hello,\n"
654
 
"world!\n"
655
 
"\n"
656
 
"\n"
657
 
</PRE>
658
 
 
659
 
<P>
660
 
We are deliberately using a caricatural example, here, to make the
661
 
point clearer.  Usually, multi-lines are not that bad looking.
662
 
It is probable that we will implement the following suggestion.
663
 
We might lump together all initial newlines into the empty string,
664
 
and also all newlines introducing empty lines (that is, for <VAR>n</VAR>
665
 
&#62; 1, the <VAR>n</VAR>-1'th last newlines would go together on a separate
666
 
string), so making the previous example appear:
667
 
 
668
 
</P>
669
 
 
670
 
<PRE>
671
 
msgstr "\n\n"
672
 
"Hello,\n"
673
 
"world!\n"
674
 
"\n\n"
675
 
</PRE>
676
 
 
677
 
<P>
678
 
There are a few yet undecided little points about string normalization,
679
 
to be documented in this manual, once these questions settle.
680
 
 
681
 
</P>
682
 
<P><HR><P>
683
 
Go to the <A HREF="gettext_1.html">first</A>, <A HREF="gettext_1.html">previous</A>, <A HREF="gettext_3.html">next</A>, <A HREF="gettext_14.html">last</A> section, <A HREF="gettext_toc.html">table of contents</A>.
684
 
</BODY>
685
 
</HTML>