-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathupdate_locale.pl
More file actions
executable file
·73 lines (62 loc) · 1.72 KB
/
update_locale.pl
File metadata and controls
executable file
·73 lines (62 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl
# This script helps to update all locale files
use strict;
use warnings;
if (not `which xgettext`) {
print "xgettext not found! Please install it from gettext utility first\n";
exit(1);
}
my $filelist = `find -name "*.po"`;
my @files = split(/\n/, $filelist);
foreach my $file (@files) {
`find -name "*.php" | xargs xgettext -j -kwa_gettext -o $file`;
`find -name "*.js" | xargs xgettext -j -LC -kwa_gettext -o $file`;
}
# Generate *.php and *.js from *.po
foreach my $po_file (@files) {
if ($po_file =~ /^(.*)[.]po$/) {
my $php_file = "$1.php";
my $js_file = "$1.js";
my $msg_lines = `grep "msg" $po_file`;
my @msgs = split(/\n/, $msg_lines);
open(PHP_FILE, '>:utf8', $php_file);
open(JS_FILE, '>:utf8', $js_file);
print PHP_FILE '<?php $wa_text = array();', "\n";
print JS_FILE 'var wa_text = new Array();', "\n";
while (@msgs) {
my $msgid = shift(@msgs);
if ($msgid =~ /^msgid "(.*)"/) {
$msgid = $1;
my $msgstr = shift(@msgs);
if ($msgstr =~ /^msgstr "(.*)"/) {
$msgstr = $1;
utf8::decode($msgstr) if (not utf8::is_utf8($msgstr));
print PHP_FILE "\$wa_text[\"$msgid\"]=\"$msgstr\";\n";
print JS_FILE "wa_text[\"$msgid\"]=\"$msgstr\";\n";
} else {
warn "Invalid msgstr: $msgstr";
}
} else {
warn "Invalid msgid: $msgid";
}
}
print JS_FILE '
function wa_gettext(text) {
if (wa_text[text]) {
return wa_text[text];
} else {
return text;
}
}';
print PHP_FILE '
function wa_gettext($text) {
global $wa_text;
return $wa_text[$text];
}
?>';
close(PHP_FILE);
close(JS_FILE);
} else {
warn "Unexpected file $po_file";
}
}