line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::I18N::Command::Server; |
2
|
1
|
|
|
1
|
|
2055
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw(App::I18N::Command); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
97
|
|
5
|
1
|
|
|
1
|
|
10
|
use App::I18N::Web; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
729
|
use App::I18N::Web::View; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use App::I18N::Web::Handler; |
8
|
|
|
|
|
|
|
use Tatsumaki::Application; |
9
|
|
|
|
|
|
|
use Plack::Runner; |
10
|
|
|
|
|
|
|
use File::Basename; |
11
|
|
|
|
|
|
|
use File::ShareDir qw(); |
12
|
|
|
|
|
|
|
use File::Path qw(mkpath); |
13
|
|
|
|
|
|
|
use Locale::Language; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use constant debug => 1; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub options { ( |
18
|
|
|
|
|
|
|
'l|lang=s' => 'language', |
19
|
|
|
|
|
|
|
'f|file=s' => 'pofile', |
20
|
|
|
|
|
|
|
'dir=s@' => 'directories', |
21
|
|
|
|
|
|
|
'podir=s' => 'podir', |
22
|
|
|
|
|
|
|
'mo' => 'mo', |
23
|
|
|
|
|
|
|
'verbose' => 'verbose', |
24
|
|
|
|
|
|
|
'locale' => 'locale', |
25
|
|
|
|
|
|
|
) } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# %podata |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# { |
30
|
|
|
|
|
|
|
# [lang_code] => { |
31
|
|
|
|
|
|
|
# name => 'Language Name', |
32
|
|
|
|
|
|
|
# path => 'po file path', |
33
|
|
|
|
|
|
|
# }, |
34
|
|
|
|
|
|
|
# ... |
35
|
|
|
|
|
|
|
# } |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub run { |
40
|
|
|
|
|
|
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->{mo} = 1 if $self->{locale}; |
44
|
|
|
|
|
|
|
my $podir = $self->{podir}; |
45
|
|
|
|
|
|
|
$podir = App::I18N->guess_podir( $self ) unless $podir; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my @dirs = @{ $self->{directories} || [] }; |
48
|
|
|
|
|
|
|
my $logger = App::I18N->logger; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# pre-process messages |
51
|
|
|
|
|
|
|
my $lme = App::I18N->lm_extract; |
52
|
|
|
|
|
|
|
if( @dirs ) { |
53
|
|
|
|
|
|
|
App::I18N->extract_messages( @dirs ); |
54
|
|
|
|
|
|
|
mkpath [ $podir ]; |
55
|
|
|
|
|
|
|
App::I18N->update_catalog( |
56
|
|
|
|
|
|
|
File::Spec->catfile( $podir, |
57
|
|
|
|
|
|
|
App::I18N->pot_name . ".pot") ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ( $self->{language} ) { |
60
|
|
|
|
|
|
|
App::I18N->update_catalog( |
61
|
|
|
|
|
|
|
File::Spec->catfile( $podir, $self->{'language'} . ".po") ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
|
|
|
|
|
|
App::I18N->update_catalogs( $podir ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# init po database in memory |
69
|
|
|
|
|
|
|
my $db; |
70
|
|
|
|
|
|
|
eval { |
71
|
|
|
|
|
|
|
require App::I18N::DB; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
if( $@ ) { |
74
|
|
|
|
|
|
|
warn $@; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$db = App::I18N::DB->new(); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# $lang = code2language('en'); # $lang gets 'English' |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$logger->info("Importing messages to sqlite memory database."); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my @pofiles = ( $self->{pofile} ) || File::Find::Rule->file()->name("*.po")->in( $podir ); |
84
|
|
|
|
|
|
|
my %podata = (); |
85
|
|
|
|
|
|
|
for my $file ( @pofiles ) { |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $langname; |
88
|
|
|
|
|
|
|
my $code; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
if( $self->{locale} ) { |
91
|
|
|
|
|
|
|
($langname) = ( $file =~ m{/([a-zA-Z-_]+)/LC_MESSAGES} ); |
92
|
|
|
|
|
|
|
($code) = ( $langname =~ m{^([a-zA-Z]+)} ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
|
|
|
|
|
|
($langname) = ( $file =~ m{([a-zA-Z-_]+)\.po$} ); |
96
|
|
|
|
|
|
|
($code) = ( $langname =~ m{^([a-zA-Z]+)} ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$logger->info( "Importing $langname: $file" ); |
100
|
|
|
|
|
|
|
$db->import_po( $langname , $file ); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$podata{ $langname } = { |
103
|
|
|
|
|
|
|
code => $code, |
104
|
|
|
|
|
|
|
name => code2language( $code ), |
105
|
|
|
|
|
|
|
path => $file, |
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$SIG{INT} = sub { |
110
|
|
|
|
|
|
|
# XXX: write sqlite data to po file here. |
111
|
|
|
|
|
|
|
$logger->info("Exporting messages from sqlite memory database..."); |
112
|
|
|
|
|
|
|
for my $langname ( keys %podata ) { |
113
|
|
|
|
|
|
|
my $opt = $podata{ $langname }; |
114
|
|
|
|
|
|
|
$db->export_po( $langname , $opt->{path} ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
exit; |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Template::Declare->init( dispatch_to => ['App::I18N::Web::View'] ); |
120
|
|
|
|
|
|
|
my $app = App::I18N::Web->new( [ |
121
|
|
|
|
|
|
|
"/api/(.*)" => "App::I18N::Web::Handler::API", |
122
|
|
|
|
|
|
|
"(/.*)" => "App::I18N::Web::Handler", |
123
|
|
|
|
|
|
|
] ); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $shareroot = |
126
|
|
|
|
|
|
|
( -e "./share" ) |
127
|
|
|
|
|
|
|
? 'share' |
128
|
|
|
|
|
|
|
: File::ShareDir::dist_dir( "App-I18N" ); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$logger->info("share root: $shareroot"); |
131
|
|
|
|
|
|
|
$logger->info("podir: $podir") if $podir; |
132
|
|
|
|
|
|
|
$logger->info("pofile: @{[ $self->{pofile} ]}") if $self->{pofile}; |
133
|
|
|
|
|
|
|
$logger->info("language: @{[ $self->{language} ]}") if $self->{language}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$app->options({ |
136
|
|
|
|
|
|
|
podir => $podir, |
137
|
|
|
|
|
|
|
shareroot => $shareroot, |
138
|
|
|
|
|
|
|
map { $_ => $self->{$_} } grep { $self->{$_} } qw(language pofile locale), |
139
|
|
|
|
|
|
|
}); |
140
|
|
|
|
|
|
|
$app->podata( \%podata ); |
141
|
|
|
|
|
|
|
$app->db( $db ); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$app->template_path( $shareroot . "/templates" ); |
144
|
|
|
|
|
|
|
$app->static_path( $shareroot . "/static" ); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
my $runner = Plack::Runner->new; |
150
|
|
|
|
|
|
|
$runner->parse_options(@ARGV); |
151
|
|
|
|
|
|
|
$runner->run($app->psgi_app); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
155
|
|
|
|
|
|
|
__END__ |