1 /* Creates an English translation catalog.
2 Copyright (C) 2001-2007, 2009-2010, 2012, 2015 Free Software
4 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "error-progname.h"
35 #include "relocatable.h"
38 #include "read-catalog.h"
40 #include "read-properties.h"
41 #include "read-stringtable.h"
42 #include "msgl-english.h"
43 #include "msgl-header.h"
44 #include "write-catalog.h"
46 #include "write-properties.h"
47 #include "write-stringtable.h"
49 #include "propername.h"
52 #define _(str) gettext (str)
55 /* Force output of PO file even if empty. */
59 static const struct option long_options[] =
61 { "add-location", optional_argument, NULL, 'n' },
62 { "color", optional_argument, NULL, CHAR_MAX + 5 },
63 { "directory", required_argument, NULL, 'D' },
64 { "escape", no_argument, NULL, 'E' },
65 { "force-po", no_argument, &force_po, 1 },
66 { "help", no_argument, NULL, 'h' },
67 { "indent", no_argument, NULL, 'i' },
68 { "lang", required_argument, NULL, CHAR_MAX + 4 },
69 { "no-escape", no_argument, NULL, 'e' },
70 { "no-location", no_argument, NULL, CHAR_MAX + 7 },
71 { "no-wrap", no_argument, NULL, CHAR_MAX + 1 },
72 { "output-file", required_argument, NULL, 'o' },
73 { "properties-input", no_argument, NULL, 'P' },
74 { "properties-output", no_argument, NULL, 'p' },
75 { "sort-by-file", no_argument, NULL, 'F' },
76 { "sort-output", no_argument, NULL, 's' },
77 { "strict", no_argument, NULL, 'S' },
78 { "stringtable-input", no_argument, NULL, CHAR_MAX + 2 },
79 { "stringtable-output", no_argument, NULL, CHAR_MAX + 3 },
80 { "style", required_argument, NULL, CHAR_MAX + 6 },
81 { "version", no_argument, NULL, 'V' },
82 { "width", required_argument, NULL, 'w', },
87 /* Forward declaration of local functions. */
88 static void usage (int status)
89 #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2)
90 __attribute__ ((noreturn))
96 main (int argc, char **argv)
102 msgdomain_list_ty *result;
103 catalog_input_format_ty input_syntax = &input_format_po;
104 catalog_output_format_ty output_syntax = &output_format_po;
105 bool sort_by_filepos = false;
106 bool sort_by_msgid = false;
107 /* Language (ISO-639 code) and optional territory (ISO-3166 code). */
108 const char *catalogname = NULL;
110 /* Set program name for messages. */
111 set_program_name (argv[0]);
112 error_print_progname = maybe_print_progname;
114 #ifdef HAVE_SETLOCALE
115 /* Set locale via LC_ALL. */
116 setlocale (LC_ALL, "");
119 /* Set the text message domain. */
120 bindtextdomain (PACKAGE, relocate (LOCALEDIR));
121 bindtextdomain ("bison-runtime", relocate (BISON_LOCALEDIR));
122 textdomain (PACKAGE);
124 /* Ensure that write errors on stdout are detected. */
125 atexit (close_stdout);
127 /* Set default values for variables. */
132 while ((opt = getopt_long (argc, argv,
134 long_options, NULL)) != EOF)
137 case '\0': /* Long option. */
141 dir_list_append (optarg);
145 message_print_style_escape (false);
149 message_print_style_escape (true);
153 sort_by_filepos = true;
161 message_print_style_indent ();
165 if (handle_filepos_comment_option (optarg))
166 usage (EXIT_FAILURE);
170 output_file = optarg;
174 output_syntax = &output_format_properties;
178 input_syntax = &input_format_properties;
182 sort_by_msgid = true;
186 message_print_style_uniforum ();
197 value = strtol (optarg, &endp, 10);
199 message_page_width_set (value);
203 case CHAR_MAX + 1: /* --no-wrap */
204 message_page_width_ignore ();
207 case CHAR_MAX + 2: /* --stringtable-input */
208 input_syntax = &input_format_stringtable;
211 case CHAR_MAX + 3: /* --stringtable-output */
212 output_syntax = &output_format_stringtable;
215 case CHAR_MAX + 4: /* --lang */
216 catalogname = optarg;
219 case CHAR_MAX + 5: /* --color */
220 if (handle_color_option (optarg) || color_test_mode)
221 usage (EXIT_FAILURE);
224 case CHAR_MAX + 6: /* --style */
225 handle_style_option (optarg);
228 case CHAR_MAX + 7: /* --no-location */
229 message_print_style_filepos (filepos_comment_none);
233 usage (EXIT_FAILURE);
237 /* Version information is requested. */
240 printf ("%s (GNU %s) %s\n", basename (program_name), PACKAGE, VERSION);
241 /* xgettext: no-wrap */
242 printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\
243 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
244 This is free software: you are free to change and redistribute it.\n\
245 There is NO WARRANTY, to the extent permitted by law.\n\
248 printf (_("Written by %s.\n"), proper_name ("Bruno Haible"));
252 /* Help is requested. */
254 usage (EXIT_SUCCESS);
256 /* Test whether we have an .po file name as argument. */
259 error (EXIT_SUCCESS, 0, _("no input file given"));
260 usage (EXIT_FAILURE);
262 if (optind + 1 != argc)
264 error (EXIT_SUCCESS, 0, _("exactly one input file required"));
265 usage (EXIT_FAILURE);
268 /* Verify selected options. */
269 if (sort_by_msgid && sort_by_filepos)
270 error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
271 "--sort-output", "--sort-by-file");
273 /* Read input file. */
274 result = read_catalog_file (argv[optind], input_syntax);
276 /* Add English translations. */
277 result = msgdomain_list_english (result);
279 /* Sort the results. */
281 msgdomain_list_sort_by_filepos (result);
282 else if (sort_by_msgid)
283 msgdomain_list_sort_by_msgid (result);
285 /* Set the Language field in the header. */
286 if (catalogname != NULL)
287 msgdomain_list_set_header_field (result, "Language:", catalogname);
289 /* Write the merged message list out. */
290 msgdomain_list_print (result, output_file, output_syntax, force_po, false);
296 /* Display usage information and exit. */
300 if (status != EXIT_SUCCESS)
301 fprintf (stderr, _("Try '%s --help' for more information.\n"),
306 Usage: %s [OPTION] INPUTFILE\n\
309 /* xgettext: no-wrap */
311 Creates an English translation catalog. The input file is the last\n\
312 created English PO file, or a PO Template file (generally created by\n\
313 xgettext). Untranslated entries are assigned a translation that is\n\
314 identical to the msgid.\n\
318 Mandatory arguments to long options are mandatory for short options too.\n"));
321 Input file location:\n"));
323 INPUTFILE input PO or POT file\n"));
325 -D, --directory=DIRECTORY add DIRECTORY to list for input files search\n"));
327 If input file is -, standard input is read.\n"));
330 Output file location:\n"));
332 -o, --output-file=FILE write output to specified file\n"));
334 The results are written to standard output if no output file is specified\n\
338 Input file syntax:\n"));
340 -P, --properties-input input file is in Java .properties syntax\n"));
342 --stringtable-input input file is in NeXTstep/GNUstep .strings syntax\n"));
345 Output details:\n"));
347 --lang=CATALOGNAME set 'Language' field in the header entry\n"));
349 --color use colors and other text attributes always\n\
350 --color=WHEN use colors and other text attributes if WHEN.\n\
351 WHEN may be 'always', 'never', 'auto', or 'html'.\n"));
353 --style=STYLEFILE specify CSS style rule file for --color\n"));
355 -e, --no-escape do not use C escapes in output (default)\n"));
357 -E, --escape use C escapes in output, no extended chars\n"));
359 --force-po write PO file even if empty\n"));
361 -i, --indent indented output style\n"));
363 --no-location suppress '#: filename:line' lines\n"));
365 -n, --add-location preserve '#: filename:line' lines (default)\n"));
367 --strict strict Uniforum output style\n"));
369 -p, --properties-output write out a Java .properties file\n"));
371 --stringtable-output write out a NeXTstep/GNUstep .strings file\n"));
373 -w, --width=NUMBER set output page width\n"));
375 --no-wrap do not break long message lines, longer than\n\
376 the output page width, into several lines\n"));
378 -s, --sort-output generate sorted output\n"));
380 -F, --sort-by-file sort output by file location\n"));
383 Informative output:\n"));
385 -h, --help display this help and exit\n"));
387 -V, --version output version information and exit\n"));
389 /* TRANSLATORS: The placeholder indicates the bug-reporting address
390 for this package. Please add _another line_ saying
391 "Report translation bugs to <...>\n" with the address for translation
392 bugs (typically your translation team's web or email address). */
393 fputs (_("Report bugs to <bug-gnu-gettext@gnu.org>.\n"),