]>
git.ipfire.org Git - thirdparty/cups.git/blob - locale/strings2po.c
4 * Convert Apple .strings file (UTF-16 BE text file) to GNU gettext .po files.
6 * Copyright 2007-2014 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 * strings2po filename.strings filename.po
20 * gcc -o strings2po strings2po.c
28 * The .strings file format is simple:
33 * Both the id and str strings use standard C quoting for special characters
34 * like newline and the double quote character.
41 static int read_strings(FILE *strings
, char *buffer
, size_t bufsize
,
42 char **id
, char **str
);
43 static void write_po(FILE *po
, const char *what
, const char *s
);
47 * main() - Convert .strings file to .po.
50 int /* O - Exit code */
51 main(int argc
, /* I - Number of command-line args */
52 char *argv
[]) /* I - Command-line arguments */
54 FILE *strings
, /* .strings file */
56 char iconv
[1024], /* iconv command */
57 buffer
[8192], /* Line buffer */
59 *str
; /* Translation string */
60 int count
; /* Number of messages converted */
65 puts("Usage: strings2po filename.strings filename.po");
70 * Cheat by using iconv to convert the .strings file from UTF-16 to UTF-8
71 * which is what we need for the .po file (and it makes things a lot
75 snprintf(iconv
, sizeof(iconv
), "iconv -f utf-16 -t utf-8 '%s'", argv
[1]);
76 if ((strings
= popen(iconv
, "r")) == NULL
)
82 if ((po
= fopen(argv
[2], "w")) == NULL
)
91 while (read_strings(strings
, buffer
, sizeof(buffer
), &id
, &str
))
94 write_po(po
, "msgid", id
);
95 write_po(po
, "msgstr", str
);
101 printf("%s: %d messages.\n", argv
[2], count
);
108 * 'read_strings()' - Read a line from a .strings file.
111 static int /* O - 1 on success, 0 on failure */
112 read_strings(FILE *strings
, /* I - .strings file */
113 char *buffer
, /* I - Line buffer */
114 size_t bufsize
, /* I - Size of line buffer */
115 char **id
, /* O - Pointer to ID string */
116 char **str
) /* O - Pointer to translation string */
118 char *bufptr
; /* Pointer into buffer */
121 while (fgets(buffer
, (int)bufsize
, strings
))
123 if (buffer
[0] != '\"')
128 for (bufptr
= buffer
+ 1; *bufptr
&& *bufptr
!= '\"'; bufptr
++)
137 while (*bufptr
&& *bufptr
!= '\"')
146 for (; *bufptr
&& *bufptr
!= '\"'; bufptr
++)
163 * 'write_po()' - Write a line to the .po file.
167 write_po(FILE *po
, /* I - .po file */
168 const char *what
, /* I - Type of string */
169 const char *s
) /* I - String to write */
171 fprintf(po
, "%s \"%s\"\n", what
, s
);