3 Parses .po files and dumps MPSL code.
5 Angel Ortega <angel@triptico.com>
9 sub convert_po_line(line)
11 return line->sregex('/^\s*"/')->
17 sprintf("\\x{%04x}", ord(e)) ||
25 sub parse_po_file(pofile)
30 /* only UTF-8 po files are supported */
33 if ((f = open(pofile, "r")) != NULL) {
39 while ((l = read(f)) != NULL) {
43 local s = regex(l, [ '/^(msgid|msgstr)*/', '/\s*\".*\"$/' ]);
44 s[1] = convert_po_line(s[1]);
46 if (s[0] eq 'msgid') {
51 if (s[0] eq 'msgstr') {
60 push(r, "/* Built by po2mpsl - Don't modify, change the .po file instead */");
61 push(r, "__I18N__ = {");
65 push(r, "\t\"" ~ join(l[0]) ~ "\" => \"" ~ join(l[1]) ~ "\",");
68 push(r, "\t\"-\" => \"-\"\n};\n");
73 /* back to default encoding */
81 foreach (f, glob('po/*.po')) { /**/
82 local output = parse_po_file(f);
84 /* strip extension and path */
85 f = shift(split(f, '.po'));
86 f = pop(split(f, '/'));
88 local o = open('lang/' ~ f ~ '.mpsl', 'w');