]>
git.ipfire.org Git - thirdparty/cups.git/blob - locale/strings2po.c
6f912bb1908ca5270dd5c25fae3315a33ac2a52d
2 * Convert Apple .strings file (UTF-16 BE text file) to GNU gettext .po files.
4 * Copyright 2007-2014 by Apple Inc.
6 * These coded instructions, statements, and computer programs are the
7 * property of Apple Inc. and are protected by Federal copyright
8 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
9 * which should have been included with this file. If this file is
10 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * strings2po filename.strings filename.po
18 * gcc -o strings2po strings2po.c
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 int read_strings(FILE *strings
, char *buffer
, size_t bufsize
,
40 char **id
, char **str
);
41 static void write_po(FILE *po
, const char *what
, const char *s
);
45 * main() - Convert .strings file to .po.
48 int /* O - Exit code */
49 main(int argc
, /* I - Number of command-line args */
50 char *argv
[]) /* I - Command-line arguments */
52 FILE *strings
, /* .strings file */
54 char iconv
[1024], /* iconv command */
55 buffer
[8192], /* Line buffer */
57 *str
; /* Translation string */
58 int count
; /* Number of messages converted */
63 puts("Usage: strings2po filename.strings filename.po");
68 * Cheat by using iconv to convert the .strings file from UTF-16 to UTF-8
69 * which is what we need for the .po file (and it makes things a lot
73 snprintf(iconv
, sizeof(iconv
), "iconv -f utf-16 -t utf-8 '%s'", argv
[1]);
74 if ((strings
= popen(iconv
, "r")) == NULL
)
80 if ((po
= fopen(argv
[2], "w")) == NULL
)
89 while (read_strings(strings
, buffer
, sizeof(buffer
), &id
, &str
))
92 write_po(po
, "msgid", id
);
93 write_po(po
, "msgstr", str
);
99 printf("%s: %d messages.\n", argv
[2], count
);
106 * 'read_strings()' - Read a line from a .strings file.
109 static int /* O - 1 on success, 0 on failure */
110 read_strings(FILE *strings
, /* I - .strings file */
111 char *buffer
, /* I - Line buffer */
112 size_t bufsize
, /* I - Size of line buffer */
113 char **id
, /* O - Pointer to ID string */
114 char **str
) /* O - Pointer to translation string */
116 char *bufptr
; /* Pointer into buffer */
119 while (fgets(buffer
, (int)bufsize
, strings
))
121 if (buffer
[0] != '\"')
126 for (bufptr
= buffer
+ 1; *bufptr
&& *bufptr
!= '\"'; bufptr
++)
135 while (*bufptr
&& *bufptr
!= '\"')
144 for (; *bufptr
&& *bufptr
!= '\"'; bufptr
++)
161 * 'write_po()' - Write a line to the .po file.
165 write_po(FILE *po
, /* I - .po file */
166 const char *what
, /* I - Type of string */
167 const char *s
) /* I - String to write */
169 fprintf(po
, "%s \"%s\"\n", what
, s
);