line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HON::I18N::Converter; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
147778
|
use 5.006; |
|
6
|
|
|
|
|
22
|
|
4
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
136
|
|
5
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
186
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
5729
|
use Encode; |
|
6
|
|
|
|
|
70225
|
|
|
6
|
|
|
|
|
532
|
|
8
|
6
|
|
|
6
|
|
7899
|
use Spreadsheet::ParseExcel; |
|
6
|
|
|
|
|
432370
|
|
|
6
|
|
|
|
|
232
|
|
9
|
6
|
|
|
6
|
|
7039
|
use JSON::XS; |
|
6
|
|
|
|
|
84895
|
|
|
6
|
|
|
|
|
490
|
|
10
|
6
|
|
|
6
|
|
3687
|
use IO::All -utf8; |
|
6
|
|
|
|
|
48236
|
|
|
6
|
|
|
|
|
65
|
|
11
|
6
|
|
|
6
|
|
496
|
use Carp; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
513
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
HON::I18N::Converter - perl I18N Converter |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.03 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Convert Excel (2003) i18n file to another format |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use HON::I18N::Converter; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $converter = HON::I18N::Converter->new( excel => 'path/to/my/file.xls' ); |
32
|
|
|
|
|
|
|
$converter->build_properties_file('INI', 'destination/folder/', $comment); |
33
|
|
|
|
|
|
|
... |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
perl I18N Converter |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
42
|
6
|
|
|
6
|
|
8023
|
use Object::InsideOut; |
|
6
|
|
|
|
|
318098
|
|
|
6
|
|
|
|
|
39
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my @workbook : Field : Acc( 'Name' => 'workbook' ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#Tableau labels |
47
|
|
|
|
|
|
|
my @labels : Field : Type('Hash') : Acc( 'Name' => 'labels' ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#Table de hachage init_args |
50
|
|
|
|
|
|
|
my %init_args : InitArgs = ( |
51
|
|
|
|
|
|
|
'EXCEL' => { |
52
|
|
|
|
|
|
|
Regex => qr/^excel$/i, |
53
|
|
|
|
|
|
|
Mandatory => 1, |
54
|
|
|
|
|
|
|
Type => 'Scalar', |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub init : Init { |
59
|
9
|
|
|
0
|
0
|
19774
|
my ( $self, $args ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
9
|
|
|
|
|
274
|
$self->labels( {} ); |
62
|
|
|
|
|
|
|
|
63
|
9
|
|
|
|
|
160
|
my $parser = Spreadsheet::ParseExcel->new(); |
64
|
9
|
|
|
|
|
1944
|
$self->workbook( $parser->parse( $args->{EXCEL} ) ); |
65
|
|
|
|
|
|
|
|
66
|
9
|
100
|
|
|
|
149447
|
if ( !defined $self->workbook ) { |
67
|
1
|
|
|
|
|
12
|
die $parser->error(), ".\n"; |
68
|
|
|
|
|
|
|
} |
69
|
6
|
|
|
6
|
|
1652
|
} |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
26
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#Retourne le tableau contenant la liste des langues |
72
|
|
|
|
|
|
|
sub p_getLanguage { |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#La fonction shift prend un tableau en argument; elle supprime son premier element |
75
|
|
|
|
|
|
|
#(les autres sont alors decales) et renvoie cet element. |
76
|
7
|
|
|
7
|
0
|
643
|
my ($self) = shift; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#Declaration tableau vide |
79
|
7
|
|
|
|
|
17
|
my @line = (); |
80
|
|
|
|
|
|
|
|
81
|
7
|
|
|
|
|
182
|
for my $worksheet ( $self->workbook->worksheets() ) { |
82
|
21
|
|
|
|
|
192
|
my ( $col_min, $col_max ) = $worksheet->col_range(); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#Recuperation des cellules de la premiere ligne (ligne correspondant a la langue) |
85
|
21
|
|
|
|
|
174
|
for my $col ( $col_min .. $col_max ) { |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#Valeur de la cellule |
88
|
20
|
|
|
|
|
119
|
my $cell = $worksheet->get_cell( 0, $col ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#Va a la prochaine cellule sauf si la cellule est vide |
91
|
20
|
50
|
|
|
|
226
|
next unless $cell; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#Push permet d'ajouter une liste de valeurs scalaires au tableau @line |
94
|
20
|
|
|
|
|
72
|
push @line, $cell->value(); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#Retourne le tableau contenant la liste des langues |
99
|
7
|
|
|
|
|
38
|
return @line; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub p_buildHash { |
103
|
7
|
|
|
7
|
0
|
27
|
my ( $self, $languages ) = @_; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#Parcours ligne par ligne |
106
|
|
|
|
|
|
|
#Colonne par colonne |
107
|
7
|
|
|
|
|
175
|
for my $worksheet ( $self->workbook->worksheets() ) { |
108
|
|
|
|
|
|
|
|
109
|
21
|
|
|
|
|
325
|
my ( $row_min, $row_max ) = $worksheet->row_range(); |
110
|
21
|
|
|
|
|
168
|
my ( $col_min, $col_max ) = $worksheet->col_range(); |
111
|
|
|
|
|
|
|
|
112
|
21
|
|
|
|
|
170
|
for my $row ( 1 .. $row_max ) { |
113
|
|
|
|
|
|
|
|
114
|
14
|
|
|
|
|
280
|
my $label; |
115
|
|
|
|
|
|
|
|
116
|
14
|
|
|
|
|
32
|
for my $col ( $col_min .. $col_max ) { |
117
|
40
|
|
|
|
|
502
|
my $cell = $worksheet->get_cell( $row, $col ); |
118
|
40
|
50
|
|
|
|
435
|
next unless $cell; |
119
|
|
|
|
|
|
|
|
120
|
40
|
100
|
|
|
|
87
|
if ( $col == 0 ) { |
121
|
14
|
|
|
|
|
44
|
$label = $cell->value(); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
else { |
124
|
26
|
|
|
|
|
75
|
$self->labels->{ $languages->[$col] }->{$label} = $cell->value(); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
7
|
|
|
|
|
20
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#Fonction valable pour le javascript |
133
|
|
|
|
|
|
|
sub p_write_JS_i18n { |
134
|
2
|
|
|
2
|
0
|
6
|
my ( $self, $folder, $header ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#En tete du fichier jQuery |
137
|
2
|
|
|
|
|
7
|
my $content = $header . "(function(\$){\n"; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
#Pour encodage |
140
|
2
|
|
|
|
|
36
|
my $encoder = JSON::XS->new->ascii->pretty->allow_nonref; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#Parcours d'une table de hachage |
143
|
2
|
|
|
|
|
4
|
foreach my $lang ( keys %{ $self->labels } ) { |
|
2
|
|
|
|
|
48
|
|
144
|
|
|
|
|
|
|
|
145
|
4
|
|
|
|
|
103
|
my $json = $encoder->encode( { strings => $self->labels->{$lang} } ); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#Intitule de chaque section |
148
|
4
|
|
|
|
|
70
|
$content .= "\$.i18n.$lang = $json;\n"; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#Derniere ligne du document jQuery |
152
|
2
|
|
|
|
|
6
|
$content .= '})(jQuery);'; |
153
|
|
|
|
|
|
|
|
154
|
2
|
|
|
|
|
53
|
$content > io( $folder . '/jQuery-i18n.js' ); |
155
|
2
|
|
|
|
|
13273
|
return; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#Fonction valable pour le.ini |
159
|
|
|
|
|
|
|
sub p_write_INI_i18n { |
160
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $folder, $header ) = @_; |
161
|
|
|
|
|
|
|
|
162
|
2
|
|
|
|
|
4
|
foreach my $lang ( keys %{ $self->labels } ) { |
|
2
|
|
|
|
|
43
|
|
163
|
4
|
|
|
|
|
1767
|
my $content = $header; |
164
|
4
|
|
|
|
|
9
|
foreach my $LAB ( keys %{ $self->labels->{$lang} } ) { |
|
4
|
|
|
|
|
97
|
|
165
|
8
|
|
|
|
|
215
|
$content .= ( $LAB . q{=} . $self->labels->{$lang}->{$LAB} . "\n" ); |
166
|
|
|
|
|
|
|
} |
167
|
4
|
|
|
|
|
80
|
$content > io( $folder . q{/} . $lang . '.ini' ); |
168
|
|
|
|
|
|
|
} |
169
|
2
|
|
|
|
|
12981
|
return; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 $self->build_properties_file() |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Convert Excel file to INI or Jquery i18n plugin |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub build_properties_file { |
181
|
5
|
|
|
5
|
1
|
388
|
my ( $self, $format, $folder, $header ) = @_; |
182
|
5
|
|
|
|
|
31
|
my @languges = $self->p_getLanguage(); |
183
|
5
|
|
|
|
|
28
|
$self->p_buildHash( \@languges ); |
184
|
|
|
|
|
|
|
|
185
|
5
|
100
|
|
|
|
22
|
if ( $format eq 'JS' ) { |
|
|
100
|
|
|
|
|
|
186
|
2
|
|
|
|
|
9
|
return $self->p_write_JS_i18n( $folder, $header ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
elsif ( $format eq 'INI' ) { |
189
|
2
|
|
|
|
|
10
|
return $self->p_write_INI_i18n( $folder, $header ); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
else { |
192
|
1
|
|
|
|
|
23
|
croak 'Unknown format'; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 AUTHOR |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Samia Chahlal, C<< >> |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
204
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
205
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 SUPPORT |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
perldoc HON::I18N::Converter |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
You can also look for information at: |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=over 4 |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
L |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
L |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item * CPAN Ratings |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
L |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * Search CPAN |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
L |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=back |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Copyright 2013 Samia Chahlal. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
245
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
246
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=cut |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
1; # End of HON::I18N::Converter |