]> git.saurik.com Git - wxWidgets.git/blame - docs/html/gettext/gettext_6.html
Corrected assertion
[wxWidgets.git] / docs / html / gettext / gettext_6.html
CommitLineData
f6bcfd97
BP
1<HTML>
2<HEAD>
3<!-- This HTML file has been created by texi2html 1.54
4 from gettext.texi on 25 January 1999 -->
5
6<TITLE>GNU gettext utilities - Producing Binary MO Files</TITLE>
7<link href="gettext_7.html" rel=Next>
8<link href="gettext_5.html" rel=Previous>
9<link href="gettext_toc.html" rel=ToC>
10
11</HEAD>
12<BODY>
13<p>Go to the <A HREF="gettext_1.html">first</A>, <A HREF="gettext_5.html">previous</A>, <A HREF="gettext_7.html">next</A>, <A HREF="gettext_12.html">last</A> section, <A HREF="gettext_toc.html">table of contents</A>.
14<P><HR><P>
15
16
17<H1><A NAME="SEC32" HREF="gettext_toc.html#TOC32">Producing Binary MO Files</A></H1>
18
19
20
21<H2><A NAME="SEC33" HREF="gettext_toc.html#TOC33">Invoking the <CODE>msgfmt</CODE> Program</A></H2>
22
23
24<PRE>
25Usage: msgfmt [<VAR>option</VAR>] <VAR>filename</VAR>.po ...
26</PRE>
27
28<DL COMPACT>
29
30<DT><SAMP>`-a <VAR>number</VAR>'</SAMP>
31<DD>
32<DT><SAMP>`--alignment=<VAR>number</VAR>'</SAMP>
33<DD>
34Align strings to <VAR>number</VAR> bytes (default: 1).
35
36<DT><SAMP>`-h'</SAMP>
37<DD>
38<DT><SAMP>`--help'</SAMP>
39<DD>
40Display this help and exit.
41
42<DT><SAMP>`--no-hash'</SAMP>
43<DD>
44Binary file will not include the hash table.
45
46<DT><SAMP>`-o <VAR>file</VAR>'</SAMP>
47<DD>
48<DT><SAMP>`--output-file=<VAR>file</VAR>'</SAMP>
49<DD>
50Specify output file name as <VAR>file</VAR>.
51
52<DT><SAMP>`--strict'</SAMP>
53<DD>
54Direct the program to work strictly following the Uniforum/Sun
55implementation. Currently this only affects the naming of the output
56file. If this option is not given the name of the output file is the
57same as the domain name. If the strict Uniforum mode is enable the
58suffix <TT>`.mo'</TT> is added to the file name if it is not already
59present.
60
61We find this behaviour of Sun's implementation rather silly and so by
62default this mode is <EM>not</EM> selected.
63
64<DT><SAMP>`-v'</SAMP>
65<DD>
66<DT><SAMP>`--verbose'</SAMP>
67<DD>
68Detect and diagnose input file anomalies which might represent
69translation errors. The <CODE>msgid</CODE> and <CODE>msgstr</CODE> strings are
70studied and compared. It is considered abnormal that one string
71starts or ends with a newline while the other does not.
72
73Also, if the string represents a format sring used in a
74<CODE>printf</CODE>-like function both strings should have the same number of
75<SAMP>`%'</SAMP> format specifiers, with matching types. If the flag
76<CODE>c-format</CODE> or <CODE>possible-c-format</CODE> appears in the special
77comment <KBD>#,</KBD> for this entry a check is performed. For example, the
78check will diagnose using <SAMP>`%.*s'</SAMP> against <SAMP>`%s'</SAMP>, or <SAMP>`%d'</SAMP>
79against <SAMP>`%s'</SAMP>, or <SAMP>`%d'</SAMP> against <SAMP>`%x'</SAMP>. It can even handle
80positional parameters.
81
82Normally the <CODE>xgettext</CODE> program automatically decides whether a
83string is a format string or not. This algorithm is not perfect,
84though. It might regard a string as a format string though it is not
85used in a <CODE>printf</CODE>-like function and so <CODE>msgfmt</CODE> might report
86errors where there are none. Or the other way round: a string is not
87regarded as a format string but it is used in a <CODE>printf</CODE>-like
88function.
89
90So solve this problem the programmer can dictate the decision to the
91<CODE>xgettext</CODE> program (see section <A HREF="gettext_3.html#SEC17">Special Comments preceding Keywords</A>). The translator should not
92consider removing the flag from the <KBD>#,</KBD> line. This "fix" would be
93reversed again as soon as <CODE>msgmerge</CODE> is called the next time.
94
95<DT><SAMP>`-V'</SAMP>
96<DD>
97<DT><SAMP>`--version'</SAMP>
98<DD>
99Output version information and exit.
100
101</DL>
102
103<P>
104If input file is <SAMP>`-'</SAMP>, standard input is read. If output file
105is <SAMP>`-'</SAMP>, output is written to standard output.
106
107</P>
108
109
110<H2><A NAME="SEC34" HREF="gettext_toc.html#TOC34">The Format of GNU MO Files</A></H2>
111
112<P>
113The format of the generated MO files is best described by a picture,
114which appears below.
115
116</P>
117<P>
118The first two words serve the identification of the file. The magic
119number will always signal GNU MO files. The number is stored in the
120byte order of the generating machine, so the magic number really is
121two numbers: <CODE>0x950412de</CODE> and <CODE>0xde120495</CODE>. The second
122word describes the current revision of the file format. For now the
123revision is 0. This might change in future versions, and ensures
124that the readers of MO files can distinguish new formats from old
125ones, so that both can be handled correctly. The version is kept
126separate from the magic number, instead of using different magic
127numbers for different formats, mainly because <TT>`/etc/magic'</TT> is
128not updated often. It might be better to have magic separated from
129internal format version identification.
130
131</P>
132<P>
133Follow a number of pointers to later tables in the file, allowing
134for the extension of the prefix part of MO files without having to
135recompile programs reading them. This might become useful for later
136inserting a few flag bits, indication about the charset used, new
137tables, or other things.
138
139</P>
140<P>
141Then, at offset <VAR>O</VAR> and offset <VAR>T</VAR> in the picture, two tables
142of string descriptors can be found. In both tables, each string
143descriptor uses two 32 bits integers, one for the string length,
144another for the offset of the string in the MO file, counting in bytes
145from the start of the file. The first table contains descriptors
146for the original strings, and is sorted so the original strings
147are in increasing lexicographical order. The second table contains
148descriptors for the translated strings, and is parallel to the first
149table: to find the corresponding translation one has to access the
150array slot in the second array with the same index.
151
152</P>
153<P>
154Having the original strings sorted enables the use of simple binary
155search, for when the MO file does not contain an hashing table, or
156for when it is not practical to use the hashing table provided in
157the MO file. This also has another advantage, as the empty string
158in a PO file GNU <CODE>gettext</CODE> is usually <EM>translated</EM> into
159some system information attached to that particular MO file, and the
160empty string necessarily becomes the first in both the original and
161translated tables, making the system information very easy to find.
162
163</P>
164<P>
165The size <VAR>S</VAR> of the hash table can be zero. In this case, the
166hash table itself is not contained in the MO file. Some people might
167prefer this because a precomputed hashing table takes disk space, and
168does not win <EM>that</EM> much speed. The hash table contains indices
169to the sorted array of strings in the MO file. Conflict resolution is
170done by double hashing. The precise hashing algorithm used is fairly
171dependent of GNU <CODE>gettext</CODE> code, and is not documented here.
172
173</P>
174<P>
175As for the strings themselves, they follow the hash file, and each
176is terminated with a <KBD>NUL</KBD>, and this <KBD>NUL</KBD> is not counted in
177the length which appears in the string descriptor. The <CODE>msgfmt</CODE>
178program has an option selecting the alignment for MO file strings.
179With this option, each string is separately aligned so it starts at
180an offset which is a multiple of the alignment value. On some RISC
181machines, a correct alignment will speed things up.
182
183</P>
184<P>
185Nothing prevents a MO file from having embedded <KBD>NUL</KBD>s in strings.
186However, the program interface currently used already presumes
187that strings are <KBD>NUL</KBD> terminated, so embedded <KBD>NUL</KBD>s are
188somewhat useless. But MO file format is general enough so other
189interfaces would be later possible, if for example, we ever want to
190implement wide characters right in MO files, where <KBD>NUL</KBD> bytes may
191accidently appear.
192
193</P>
194<P>
195This particular issue has been strongly debated in the GNU
196<CODE>gettext</CODE> development forum, and it is expectable that MO file
197format will evolve or change over time. It is even possible that many
198formats may later be supported concurrently. But surely, we have to
199start somewhere, and the MO file format described here is a good start.
200Nothing is cast in concrete, and the format may later evolve fairly
201easily, so we should feel comfortable with the current approach.
202
203</P>
204
205<PRE>
206 byte
207 +------------------------------------------+
208 0 | magic number = 0x950412de |
209 | |
210 4 | file format revision = 0 |
211 | |
212 8 | number of strings | == N
213 | |
214 12 | offset of table with original strings | == O
215 | |
216 16 | offset of table with translation strings | == T
217 | |
218 20 | size of hashing table | == S
219 | |
220 24 | offset of hashing table | == H
221 | |
222 . .
223 . (possibly more entries later) .
224 . .
225 | |
226 O | length &#38; offset 0th string ----------------.
227 O + 8 | length &#38; offset 1st string ------------------.
228 ... ... | |
229O + ((N-1)*8)| length &#38; offset (N-1)th string | | |
230 | | | |
231 T | length &#38; offset 0th translation ---------------.
232 T + 8 | length &#38; offset 1st translation -----------------.
233 ... ... | | | |
234T + ((N-1)*8)| length &#38; offset (N-1)th translation | | | | |
235 | | | | | |
236 H | start hash table | | | | |
237 ... ... | | | |
238 H + S * 4 | end hash table | | | | |
239 | | | | | |
240 | NUL terminated 0th string &#60;----------------' | | |
241 | | | | |
242 | NUL terminated 1st string &#60;------------------' | |
243 | | | |
244 ... ... | |
245 | | | |
246 | NUL terminated 0th translation &#60;---------------' |
247 | | |
248 | NUL terminated 1st translation &#60;-----------------'
249 | |
250 ... ...
251 | |
252 +------------------------------------------+
253</PRE>
254
255<P><HR><P>
256<p>Go to the <A HREF="gettext_1.html">first</A>, <A HREF="gettext_5.html">previous</A>, <A HREF="gettext_7.html">next</A>, <A HREF="gettext_12.html">last</A> section, <A HREF="gettext_toc.html">table of contents</A>.
257</BODY>
258</HTML>