3 Parses .po files and dumps MPSL code.
5 Angel Ortega <angel@triptico.com>
9 sub convert_po_line(line)
11 line = sregex('/^\s*"/', line);
12 line = sregex('/"$/', line);
14 line = split(NULL, line);
19 sprintf("\\x{%04x}", ord(e)) ||
30 sub parse_po_file(pofile)
35 /* only UTF-8 po files are supported */
38 if ((f = open(pofile, "r")) != NULL) {
44 while ((l = read(f)) != NULL) {
48 local s = regex([ '/^(msgid|msgstr)*/', '/\s*\".*\"$/' ], l);
49 s[1] = convert_po_line(s[1]);
51 if (s[0] eq 'msgid') {
56 if (s[0] eq 'msgstr') {
65 push(r, "/* Built by po2mpsl - Don't modify, change the .po file instead */");
66 push(r, "__I18N__ = {");
70 push(r, "\t\"" ~ join('', l[0]) ~ "\" => \"" ~ join('', l[1]) ~ "\",");
73 push(r, "\t\"-\" => \"-\"\n};\n");
78 /* back to default encoding */
86 foreach (f, glob('po/*.po')) { /**/
87 local output = parse_po_file(f);
89 /* strip extension and path */
90 f = shift(split('.po', f));
91 f = pop(split('/', f));
93 local o = open('lang/' ~ f ~ '.mpsl', 'w');