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) {
43 push(r, "/* Built by po2mpsl - Don't modify, change the .po file instead */");
44 push(r, "__I18N__ = {");
46 while ((l = read(f)) != NULL) {
50 local s = regex([ '/^(msgid|msgstr)*/', '/\s*\".*\"$/' ], l);
51 s[1] = convert_po_line(s[1]);
53 if (s[0] eq 'msgid') {
55 k = grep(sub (e) { e != NULL; }, k);
56 v = grep(sub (e) { e != NULL; }, v);
73 if (s[0] eq 'msgstr') {
83 push(r, "\t\"-\" => \"-\"\n};");
88 /* back to default encoding */
96 foreach (f, glob('po/*.po')) { /**/
97 local output = parse_po_file(f);
99 /* strip extension and path */
100 f = shift(split('.po', f));
101 f = pop(split('/', f));
103 local o = open('lang/' ~ f ~ '.mpsl', 'w');