]>
git.ipfire.org Git - thirdparty/cups.git/blob - locale/strings2po.c
2 * Convert Apple .strings file (UTF-16 BE text file) to GNU gettext .po files.
4 * Copyright 2007-2014 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
10 * strings2po filename.strings filename.po
14 * gcc -o strings2po strings2po.c
22 * The .strings file format is simple:
27 * Both the id and str strings use standard C quoting for special characters
28 * like newline and the double quote character.
35 static int read_strings(FILE *strings
, char *buffer
, size_t bufsize
,
36 char **id
, char **str
);
37 static void write_po(FILE *po
, const char *what
, const char *s
);
41 * main() - Convert .strings file to .po.
44 int /* O - Exit code */
45 main(int argc
, /* I - Number of command-line args */
46 char *argv
[]) /* I - Command-line arguments */
48 FILE *strings
, /* .strings file */
50 char iconv
[1024], /* iconv command */
51 buffer
[8192], /* Line buffer */
53 *str
; /* Translation string */
54 int count
; /* Number of messages converted */
59 puts("Usage: strings2po filename.strings filename.po");
64 * Cheat by using iconv to convert the .strings file from UTF-16 to UTF-8
65 * which is what we need for the .po file (and it makes things a lot
69 snprintf(iconv
, sizeof(iconv
), "iconv -f utf-16 -t utf-8 '%s'", argv
[1]);
70 if ((strings
= popen(iconv
, "r")) == NULL
)
76 if ((po
= fopen(argv
[2], "w")) == NULL
)
85 while (read_strings(strings
, buffer
, sizeof(buffer
), &id
, &str
))
88 write_po(po
, "msgid", id
);
89 write_po(po
, "msgstr", str
);
95 printf("%s: %d messages.\n", argv
[2], count
);
102 * 'read_strings()' - Read a line from a .strings file.
105 static int /* O - 1 on success, 0 on failure */
106 read_strings(FILE *strings
, /* I - .strings file */
107 char *buffer
, /* I - Line buffer */
108 size_t bufsize
, /* I - Size of line buffer */
109 char **id
, /* O - Pointer to ID string */
110 char **str
) /* O - Pointer to translation string */
112 char *bufptr
; /* Pointer into buffer */
115 while (fgets(buffer
, (int)bufsize
, strings
))
117 if (buffer
[0] != '\"')
122 for (bufptr
= buffer
+ 1; *bufptr
&& *bufptr
!= '\"'; bufptr
++)
131 while (*bufptr
&& *bufptr
!= '\"')
140 for (; *bufptr
&& *bufptr
!= '\"'; bufptr
++)
157 * 'write_po()' - Write a line to the .po file.
161 write_po(FILE *po
, /* I - .po file */
162 const char *what
, /* I - Type of string */
163 const char *s
) /* I - String to write */
165 fprintf(po
, "%s \"%s\"\n", what
, s
);