Lines 29-34
use FindBin qw( $Bin );
Link Here
|
29 |
use File::Path qw( make_path ); |
29 |
use File::Path qw( make_path ); |
30 |
use File::Copy; |
30 |
use File::Copy; |
31 |
use File::Slurp qw( read_file ); |
31 |
use File::Slurp qw( read_file ); |
|
|
32 |
use JSON qw( decode_json encode_json ); |
33 |
|
34 |
use Koha::Plugins; |
32 |
|
35 |
|
33 |
sub set_lang { |
36 |
sub set_lang { |
34 |
my ($self, $lang) = @_; |
37 |
my ($self, $lang) = @_; |
Lines 38-45
sub set_lang {
Link Here
|
38 |
"/prog/$lang/modules/admin/preferences"; |
41 |
"/prog/$lang/modules/admin/preferences"; |
39 |
} |
42 |
} |
40 |
|
43 |
|
|
|
44 |
sub _identify_translatable_plugins { |
45 |
my ($args) = @_; |
46 |
|
47 |
my @plugins = Koha::Plugins::GetPlugins( |
48 |
{ |
49 |
metadata => { has_translations => 1 }, |
50 |
} |
51 |
); |
52 |
|
53 |
return () if scalar( @plugins == 0 ); |
54 |
|
55 |
my @plugin_dirs; |
56 |
foreach my $plugin (@plugins) { |
57 |
my @path_params = split( /\//,$plugin->{_bundle_path}); |
58 |
my $translation_data = { |
59 |
bundle_path => $plugin->{_bundle_path}, |
60 |
name => $path_params[-1], |
61 |
}; |
62 |
|
63 |
push @plugin_dirs, $translation_data; |
64 |
} |
65 |
return \@plugin_dirs; |
66 |
} |
67 |
|
41 |
sub new { |
68 |
sub new { |
42 |
my ($class, $lang, $pref_only, $verbose) = @_; |
69 |
my ($class, $args) = @_; |
|
|
70 |
|
71 |
my $lang = $args->{lang}; |
72 |
my $pref_only = $args->{pref_only}; |
73 |
my $verbose = $args->{verbose}; |
74 |
my $plugin_dirs = $args->{plugin_dirs} || _identify_translatable_plugins(); |
43 |
|
75 |
|
44 |
my $self = { }; |
76 |
my $self = { }; |
45 |
|
77 |
|
Lines 56-61
sub new {
Link Here
|
56 |
$self->{po2json} = "yarn run po2json"; |
88 |
$self->{po2json} = "yarn run po2json"; |
57 |
$self->{gzip} = `which gzip`; |
89 |
$self->{gzip} = `which gzip`; |
58 |
$self->{gunzip} = `which gunzip`; |
90 |
$self->{gunzip} = `which gunzip`; |
|
|
91 |
$self->{plugin_dirs} = $plugin_dirs; |
59 |
chomp $self->{msgfmt}; |
92 |
chomp $self->{msgfmt}; |
60 |
chomp $self->{gzip}; |
93 |
chomp $self->{gzip}; |
61 |
chomp $self->{gunzip}; |
94 |
chomp $self->{gunzip}; |
Lines 132-137
sub new {
Link Here
|
132 |
suffix => "-installer-UNIMARC.po", |
165 |
suffix => "-installer-UNIMARC.po", |
133 |
}; |
166 |
}; |
134 |
|
167 |
|
|
|
168 |
|
135 |
bless $self, $class; |
169 |
bless $self, $class; |
136 |
} |
170 |
} |
137 |
|
171 |
|
Lines 317-322
sub install_tmpl {
Link Here
|
317 |
( @nomarc ? ' -n ' . join ' -n ', @nomarc : ''); |
351 |
( @nomarc ? ' -n ' . join ' -n ', @nomarc : ''); |
318 |
} |
352 |
} |
319 |
} |
353 |
} |
|
|
354 |
|
355 |
for my $plugin ( @{$self->{plugin_dirs}} ) { |
356 |
print |
357 |
" Install templates from plugin: '$plugin->{name}'\n", |
358 |
if $self->{verbose}; |
359 |
|
360 |
my $trans_dir = $plugin->{bundle_path} . "/views/en/"; |
361 |
my $lang_dir = $plugin->{bundle_path} . "/views/$self->{lang}"; |
362 |
mkdir $lang_dir unless -d $lang_dir; |
363 |
|
364 |
system "$self->{process} install " |
365 |
. "-i $trans_dir " |
366 |
. "-o $lang_dir " |
367 |
. "-s $plugin->{bundle_path}/translator/po/$self->{lang}-$plugin->{name}-template.po -r " |
368 |
} |
320 |
} |
369 |
} |
321 |
|
370 |
|
322 |
sub translate_yaml { |
371 |
sub translate_yaml { |
Lines 460-466
sub install_messages {
Link Here
|
460 |
`$po2json_cmd`; |
509 |
`$po2json_cmd`; |
461 |
my $json = read_file($tmp_po); |
510 |
my $json = read_file($tmp_po); |
462 |
|
511 |
|
463 |
my $js_locale_data = sprintf 'var json_locale_data = {"Koha":%s};', $json; |
512 |
# Add plugin javascript to the same file to avoid needing multiple imports in doc-head template files |
|
|
513 |
my $js_po_data = decode_json($json); |
514 |
foreach my $plugin ( @{$self->{plugin_dirs}} ) { |
515 |
my $tmp_pluginpo = sprintf '/tmp/%s-%s.po', $plugin->{name}, $self->{lang}; |
516 |
my $plugin_po2json_cmd = sprintf '%s %s %s', $self->{po2json}, $plugin->{bundle_path} . '/translator/po/' . $self->{lang} . '-' . $plugin->{name} . '-js.po', $tmp_pluginpo; |
517 |
`$plugin_po2json_cmd`; |
518 |
my $plugin_json = read_file($tmp_pluginpo); |
519 |
|
520 |
my $plugin_js_po_data = decode_json($plugin_json); |
521 |
delete $plugin_js_po_data->{''}; |
522 |
|
523 |
foreach my $key (keys %$plugin_js_po_data) { |
524 |
$js_po_data->{$key} = $plugin_js_po_data->{$key} unless exists $js_po_data->{$key}; |
525 |
} |
526 |
} |
527 |
my $combined_json = encode_json($js_po_data); |
528 |
|
529 |
my $js_locale_data = sprintf 'var json_locale_data = {"Koha":%s};', $combined_json; |
464 |
my $progdir = C4::Context->config('intrahtdocs') . '/prog'; |
530 |
my $progdir = C4::Context->config('intrahtdocs') . '/prog'; |
465 |
mkdir "$progdir/$self->{lang}/js"; |
531 |
mkdir "$progdir/$self->{lang}/js"; |
466 |
open my $fh, '>', "$progdir/$self->{lang}/js/locale_data.js"; |
532 |
open my $fh, '>', "$progdir/$self->{lang}/js/locale_data.js"; |
Lines 538-544
LangInstaller.pm - Handle templates and preferences translation
Link Here
|
538 |
|
604 |
|
539 |
=head1 SYNOPSYS |
605 |
=head1 SYNOPSYS |
540 |
|
606 |
|
541 |
my $installer = LangInstaller->new( 'fr-FR' ); |
607 |
my $installer = LangInstaller->new( { lang => 'fr-FR' } ); |
542 |
$installer->create(); |
608 |
$installer->create(); |
543 |
$installer->update(); |
609 |
$installer->update(); |
544 |
$installer->install(); |
610 |
$installer->install(); |