• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1@c This file is part of the GNU gettext manual.
2@c Copyright (C) 1995-2019 Free Software Foundation, Inc.
3@c See the file gettext.texi for copying conditions.
4
5@pindex msgfilter
6@cindex @code{msgfilter} program, usage
7@example
8msgfilter [@var{option}] @var{filter} [@var{filter-option}]
9@end example
10
11@cindex apply a filter to translations
12The @code{msgfilter} program applies a filter to all translations of a
13translation catalog.
14
15@vindex MSGFILTER_MSGCTXT@r{, environment variable}
16@vindex MSGFILTER_MSGID@r{, environment variable}
17@vindex MSGFILTER_MSGID_PLURAL@r{, environment variable}
18@vindex MSGFILTER_LOCATION@r{, environment variable}
19@vindex MSGFILTER_PLURAL_FORM@r{, environment variable}
20@vindex MSGFILTER_PREV_MSGCTXT@r{, environment variable}
21@vindex MSGFILTER_PREV_MSGID@r{, environment variable}
22@vindex MSGFILTER_PREV_MSGID_PLURAL@r{, environment variable}
23During each @var{filter} invocation, the environment variable
24@code{MSGFILTER_MSGID} is bound to the message's msgid, and the environment
25variable @code{MSGFILTER_LOCATION} is bound to the location in the PO file
26of the message.  If the message has a context, the environment variable
27@code{MSGFILTER_MSGCTXT} is bound to the message's msgctxt, otherwise it is
28unbound.  If the message has a plural form, environment variable
29@code{MSGFILTER_MSGID_PLURAL} is bound to the message's msgid_plural and
30@code{MSGFILTER_PLURAL_FORM} is bound to the order number of the plural
31actually processed (starting with 0), otherwise both are unbound.
32If the message has a previous msgid (added by @code{msgmerge}),
33environment variable @code{MSGFILTER_PREV_MSGCTXT} is bound to the
34message's previous msgctxt, @code{MSGFILTER_PREV_MSGID} is bound to
35the previous msgid, and @code{MSGFILTER_PREV_MSGID_PLURAL} is bound to
36the previous msgid_plural.
37
38@subsection Input file location
39
40@table @samp
41@item -i @var{inputfile}
42@itemx --input=@var{inputfile}
43@opindex -i@r{, @code{msgfilter} option}
44@opindex --input@r{, @code{msgfilter} option}
45Input PO file.
46
47@item -D @var{directory}
48@itemx --directory=@var{directory}
49@opindex -D@r{, @code{msgfilter} option}
50@opindex --directory@r{, @code{msgfilter} option}
51Add @var{directory} to the list of directories.  Source files are
52searched relative to this list of directories.  The resulting @file{.po}
53file will be written relative to the current directory, though.
54
55@end table
56
57If no @var{inputfile} is given or if it is @samp{-}, standard input is read.
58
59@subsection Output file location
60
61@table @samp
62@item -o @var{file}
63@itemx --output-file=@var{file}
64@opindex -o@r{, @code{msgfilter} option}
65@opindex --output-file@r{, @code{msgfilter} option}
66Write output to specified file.
67
68@end table
69
70The results are written to standard output if no output file is specified
71or if it is @samp{-}.
72
73@subsection The filter
74
75The @var{filter} can be any program that reads a translation from standard
76input and writes a modified translation to standard output.  A frequently
77used filter is @samp{sed}.  A few particular built-in filters are also
78recognized.
79
80@table @samp
81@item --newline
82@opindex --newline@r{, @code{msgfilter} option}
83Add newline at the end of each input line and also strip the ending
84newline from the output line.
85
86@end table
87
88@cindex @code{msgfilter} filter and catalog encoding
89Note: If the filter is not a built-in filter, you have to care about encodings:
90It is your responsibility to ensure that the @var{filter} can cope
91with input encoded in the translation catalog's encoding.  If the
92@var{filter} wants input in a particular encoding, you can in a first step
93convert the translation catalog to that encoding using the @samp{msgconv}
94program, before invoking @samp{msgfilter}.  If the @var{filter} wants input
95in the locale's encoding, but you want to avoid the locale's encoding, then
96you can first convert the translation catalog to UTF-8 using the
97@samp{msgconv} program and then make @samp{msgfilter} work in an UTF-8
98locale, by using the @code{LC_ALL} environment variable.
99
100@cindex portability problems with @code{sed}
101Note: Most translations in a translation catalog don't end with a
102newline character.  For this reason, unless the @code{--newline}
103option is used, it is important that the @var{filter} recognizes its
104last input line even if it ends without a newline, and that it doesn't
105add an undesired trailing newline at the end.  The @samp{sed} program on
106some platforms is known to ignore the last line of input if it is not
107terminated with a newline.  You can use GNU @code{sed} instead; it does
108not have this limitation.
109
110@subsection Useful @var{filter-option}s when the @var{filter} is @samp{sed}
111
112@table @samp
113@item -e @var{script}
114@itemx --expression=@var{script}
115@opindex -e@r{, @code{msgfilter} option}
116@opindex --expression@r{, @code{msgfilter} option}
117Add @var{script} to the commands to be executed.
118
119@item -f @var{scriptfile}
120@itemx --file=@var{scriptfile}
121@opindex -f@r{, @code{msgfilter} option}
122@opindex --file@r{, @code{msgfilter} option}
123Add the contents of @var{scriptfile} to the commands to be executed.
124
125@item -n
126@itemx --quiet
127@itemx --silent
128@opindex -n@r{, @code{msgfilter} option}
129@opindex --quiet@r{, @code{msgfilter} option}
130@opindex --silent@r{, @code{msgfilter} option}
131Suppress automatic printing of pattern space.
132
133@end table
134
135@subsection Built-in @var{filter}s
136
137@pindex recode-sr-latin
138@cindex @code{recode-sr-latin} program
139The filter @samp{recode-sr-latin} is recognized as a built-in filter.
140The command @samp{recode-sr-latin} converts Serbian text, written in the
141Cyrillic script, to the Latin script.
142The command @samp{msgfilter recode-sr-latin} applies this conversion to the
143translations of a PO file.  Thus, it can be used to convert an @file{sr.po}
144file to an @file{sr@@latin.po} file.
145
146@pindex quot
147The filter @samp{quot} is recognized as a built-in filter.
148The command @samp{msgfilter quot} converts any quotations surrounded
149by a pair of @samp{"}, @samp{'}, and @samp{`}.
150
151@pindex boldquot
152The filter @samp{boldquot} is recognized as a built-in filter.
153The command @samp{msgfilter boldquot} converts any quotations
154surrounded by a pair of @samp{"}, @samp{'}, and @samp{`}, also adding the
155VT100 escape sequences to the text to decorate it as bold.
156
157The use of built-in filters is not sensitive to the current locale's encoding.
158Moreover, when used with a built-in filter, @samp{msgfilter} can automatically
159convert the message catalog to the UTF-8 encoding when needed.
160
161@subsection Input file syntax
162
163@table @samp
164@item -P
165@itemx --properties-input
166@opindex -P@r{, @code{msgfilter} option}
167@opindex --properties-input@r{, @code{msgfilter} option}
168Assume the input file is a Java ResourceBundle in Java @code{.properties}
169syntax, not in PO file syntax.
170
171@item --stringtable-input
172@opindex --stringtable-input@r{, @code{msgfilter} option}
173Assume the input file is a NeXTstep/GNUstep localized resource file in
174@code{.strings} syntax, not in PO file syntax.
175
176@end table
177
178@subsection Output details
179
180@c --no-escape and --escape omitted on purpose.  They are not useful.
181
182@table @samp
183@item --color
184@itemx --color=@var{when}
185@opindex --color@r{, @code{msgfilter} option}
186Specify whether or when to use colors and other text attributes.
187See @ref{The --color option} for details.
188
189@item --style=@var{style_file}
190@opindex --style@r{, @code{msgfilter} option}
191Specify the CSS style rule file to use for @code{--color}.
192See @ref{The --style option} for details.
193
194@item --force-po
195@opindex --force-po@r{, @code{msgfilter} option}
196Always write an output file even if it contains no message.
197
198@item --indent
199@opindex --indent@r{, @code{msgfilter} option}
200Write the .po file using indented style.
201
202@item --keep-header
203@opindex --keep-header@r{, @code{msgfilter} option}
204Keep the header entry, i.e.@: the message with @samp{msgid ""}, unmodified,
205instead of filtering it.  By default, the header entry is subject to
206filtering like any other message.
207
208@item --no-location
209@opindex --no-location@r{, @code{msgfilter} option}
210Do not write @samp{#: @var{filename}:@var{line}} lines.
211
212@item -n
213@itemx --add-location=@var{type}
214@opindex --add-location@r{, @code{msgfilter} option}
215Generate @samp{#: @var{filename}:@var{line}} lines (default).
216
217The optional @var{type} can be either @samp{full}, @samp{file}, or
218@samp{never}.  If it is not given or @samp{full}, it generates the
219lines with both file name and line number.  If it is @samp{file}, the
220line number part is omitted.  If it is @samp{never}, it completely
221suppresses the lines (same as @code{--no-location}).
222
223@item --strict
224@opindex --strict@r{, @code{msgfilter} option}
225Write out a strict Uniforum conforming PO file.  Note that this
226Uniforum format should be avoided because it doesn't support the
227GNU extensions.
228
229@item -p
230@itemx --properties-output
231@opindex -p@r{, @code{msgfilter} option}
232@opindex --properties-output@r{, @code{msgfilter} option}
233Write out a Java ResourceBundle in Java @code{.properties} syntax.  Note
234that this file format doesn't support plural forms and silently drops
235obsolete messages.
236
237@item --stringtable-output
238@opindex --stringtable-output@r{, @code{msgfilter} option}
239Write out a NeXTstep/GNUstep localized resource file in @code{.strings} syntax.
240Note that this file format doesn't support plural forms.
241
242@item -w @var{number}
243@itemx --width=@var{number}
244@opindex -w@r{, @code{msgfilter} option}
245@opindex --width@r{, @code{msgfilter} option}
246Set the output page width.  Long strings in the output files will be
247split across multiple lines in order to ensure that each line's width
248(= number of screen columns) is less or equal to the given @var{number}.
249
250@item --no-wrap
251@opindex --no-wrap@r{, @code{msgfilter} option}
252Do not break long message lines.  Message lines whose width exceeds the
253output page width will not be split into several lines.  Only file reference
254lines which are wider than the output page width will be split.
255
256@item -s
257@itemx --sort-output
258@opindex -s@r{, @code{msgfilter} option}
259@opindex --sort-output@r{, @code{msgfilter} option}
260Generate sorted output.  Note that using this option makes it much harder
261for the translator to understand each message's context.
262
263@item -F
264@itemx --sort-by-file
265@opindex -F@r{, @code{msgfilter} option}
266@opindex --sort-by-file@r{, @code{msgfilter} option}
267Sort output by file location.
268
269@end table
270
271@subsection Informative output
272
273@table @samp
274@item -h
275@itemx --help
276@opindex -h@r{, @code{msgfilter} option}
277@opindex --help@r{, @code{msgfilter} option}
278Display this help and exit.
279
280@item -V
281@itemx --version
282@opindex -V@r{, @code{msgfilter} option}
283@opindex --version@r{, @code{msgfilter} option}
284Output version information and exit.
285
286@end table
287
288@subsection Examples
289
290To convert German translations to Swiss orthography (in an UTF-8 locale):
291
292@smallexample
293msgconv -t UTF-8 de.po | msgfilter sed -e 's/@ss{}/ss/g'
294@end smallexample
295
296To convert Serbian translations in Cyrillic script to Latin script:
297
298@smallexample
299msgfilter recode-sr-latin < sr.po
300@end smallexample
301