-
Notifications
You must be signed in to change notification settings - Fork 5
/
po2perl.pl
executable file
·71 lines (59 loc) · 1.15 KB
/
po2perl.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use Locale::PO;
sub massage
{
my ( $string ) = @_;
$string =~ s/@/\\@/g;
$string =~ s/\\\\n/\\n/g;
$string =~ s/\[/~[/g;
$string =~ s/\]/~]/g;
$string =~ s/\%s/[_1]/;
$string =~ s/\%s/[_2]/;
$string =~ s/\%s/[_3]/;
$string =~ s#\\\\/#/#g;
$string =~ s#\\\\([1-9])#[_$1]#;
return $string;
}
sub my_warn
{
return 1;
}
if (@ARGV != 2) {
die "Usage: $0 POFILE LANGUAGECODE\n";
}
my $aref;
{
local $SIG{__WARN__} = 'my_warn';
$aref = Locale::PO->load_file_asarray($ARGV[0]);
}
shift(@$aref);
my $lang = $ARGV[1];
print 'package Lingua::@TEANGA@::Gramadoir::Languages::'."$lang;\n\n";
print 'use strict;'."\n";
print 'use warnings;'."\n";
print 'use utf8;'."\n";
print 'use base qw(Lingua::@TEANGA@::Gramadoir::Languages);'."\n";
print 'use vars qw(%Lexicon);'."\n\n";
print '%Lexicon = ('."\n";
foreach my $msg (@$aref) {
my $id = $msg->msgid();
my $str = $msg->msgstr();
if (defined($id) && defined($str)) {
$id = massage($id);
$str = massage($str);
if ($str eq '""') {
$str = $id;
}
print " ";
print $id;
print "\n";
print " => ";
print $str;
print ",\n\n";
}
}
print ");\n";
print "1;\n";
exit 0;