]>
git.ipfire.org Git - thirdparty/cups.git/blob - locale/po2strings.c
2 * "$Id: po2strings.c 6921 2007-09-06 13:38:37Z mike $"
4 * Convert GNU gettext .po files to Apple .strings file (UTF-16 BE text file).
6 * Copyright 2007-2010 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
16 * po2strings filename.strings filename.po
20 * gcc -o po2strings po2strings.c `cups-config --libs`
24 * main() - Convert .po file to .strings.
25 * write_string() - Write a string to the .strings file.
28 #include <cups/cups-private.h>
32 * The .strings file format is simple:
37 * Both the id and str strings use standard C quoting for special characters
38 * like newline and the double quote character.
45 static void write_string(FILE *strings
, const char *s
);
49 * main() - Convert .po file to .strings.
52 int /* O - Exit code */
53 main(int argc
, /* I - Number of command-line args */
54 char *argv
[]) /* I - Command-line arguments */
56 int i
; /* Looping var */
57 FILE *strings
; /* .strings file */
58 cups_array_t
*po
; /* .po file */
59 char iconv
[1024]; /* iconv command */
60 _cups_message_t
*msg
; /* Current message */
61 const char *srcfile
, /* Source file */
62 *dstfile
; /* Destination file */
63 int use_msgid
; /* Use msgid strings for msgstr? */
71 for (i
= 1; i
< argc
; i
++)
72 if (!strcmp(argv
[i
], "-m"))
74 else if (argv
[i
][0] == '-')
76 puts("Usage: po2strings [-m] filename.po filename.strings");
79 else if (srcfile
== NULL
)
81 else if (dstfile
== NULL
)
85 puts("Usage: po2strings [-m] filename.po filename.strings");
89 if (!srcfile
|| !dstfile
)
91 puts("Usage: po2strings [-m] filename.po filename.strings");
96 * Use the CUPS .po loader to get the message strings...
99 if ((po
= _cupsMessageLoad(srcfile
, 1)) == NULL
)
106 * Cheat by using iconv to write the .strings file with a UTF-16 encoding.
107 * The .po file uses UTF-8...
110 snprintf(iconv
, sizeof(iconv
), "iconv -f utf-8 -t utf-16 >'%s'", dstfile
);
111 if ((strings
= popen(iconv
, "w")) == NULL
)
114 _cupsMessageFree(po
);
118 for (msg
= (_cups_message_t
*)cupsArrayFirst(po
);
120 msg
= (_cups_message_t
*)cupsArrayNext(po
))
122 write_string(strings
, msg
->id
);
123 fputs(" = ", strings
);
124 write_string(strings
, use_msgid
? msg
->id
: msg
->str
);
125 fputs(";\n", strings
);
128 printf("%s: %d messages.\n", argv
[2], cupsArrayCount(po
));
131 _cupsMessageFree(po
);
138 * 'write_string()' - Write a string to the .strings file.
142 write_string(FILE *strings
, /* I - .strings file */
143 const char *s
) /* I - String to write */
152 fputs("\\n", strings
);
155 fputs("\\t", strings
);
158 fputs("\\\\", strings
);
161 fputs("\\\"", strings
);
176 * End of "$Id: po2strings.c 6921 2007-09-06 13:38:37Z mike $".