]>
git.ipfire.org Git - thirdparty/cups.git/blob - locale/po2strings.c
4 * Convert GNU gettext .po files to Apple .strings file (UTF-16 BE text file).
8 * po2strings filename.strings filename.po
12 * gcc -o po2strings po2strings.c `cups-config --libs`
16 * main() - Convert .po file to .strings.
17 * write_string() - Write a string to the .strings file.
22 #include <cups/i18n.h>
26 * The .strings file format is simple:
31 * Both the id and str strings use standard C quoting for special characters
32 * like newline and the double quote character.
39 static void write_string(FILE *strings
, const char *s
);
43 * main() - Convert .po file to .strings.
46 int /* O - Exit code */
47 main(int argc
, /* I - Number of command-line args */
48 char *argv
[]) /* I - Command-line arguments */
50 FILE *strings
; /* .strings file */
51 cups_array_t
*po
; /* .po file */
52 char iconv
[1024]; /* iconv command */
53 _cups_message_t
*msg
; /* Current message */
58 puts("Usage: po2strings filename.po filename.strings");
63 * Use the CUPS .po loader to get the message strings...
66 if ((po
= _cupsMessageLoad(argv
[1])) == NULL
)
73 * Cheat by using iconv to write the .strings file with a UTF-16 encoding.
74 * The .po file uses UTF-8...
77 snprintf(iconv
, sizeof(iconv
), "iconv -f utf-8 -t utf-16 >'%s'", argv
[2]);
78 if ((strings
= popen(iconv
, "w")) == NULL
)
85 for (msg
= (_cups_message_t
*)cupsArrayFirst(po
);
87 msg
= (_cups_message_t
*)cupsArrayNext(po
))
89 write_string(strings
, msg
->id
);
90 fputs(" = ", strings
);
91 write_string(strings
, msg
->str
);
92 fputs(";\n", strings
);
95 printf("%s: %d messages.\n", argv
[2], cupsArrayCount(po
));
105 * 'write_string()' - Write a string to the .strings file.
109 write_string(FILE *strings
, /* I - .strings file */
110 const char *s
) /* I - String to write */
119 fputs("\\n", strings
);
122 fputs("\\t", strings
);
125 fputs("\\\\", strings
);
128 fputs("\\\"", strings
);