2 * "$Id: strings2po.c 7720 2008-07-11 22:46:21Z mike $"
4 * Convert Apple .strings file (UTF-16 BE text file) to GNU gettext .po files.
8 * strings2po filename.strings filename.po
12 * gcc -o strings2po strings2po.c
16 * main() - Convert .strings file to .po.
17 * read_strings() - Read a line from a .strings file.
18 * write_po() - Write a line to the .po file.
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, 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);
174 * End of "$Id: strings2po.c 7720 2008-07-11 22:46:21Z mike $".