Lines 41-77
sub set_lang {
Link Here
|
41 |
"/prog/$lang/modules/admin/preferences"; |
41 |
"/prog/$lang/modules/admin/preferences"; |
42 |
} |
42 |
} |
43 |
|
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 |
|
68 |
sub new { |
44 |
sub new { |
69 |
my ($class, $args) = @_; |
45 |
my ($class, $args) = @_; |
70 |
|
46 |
|
71 |
my $lang = $args->{lang}; |
47 |
my $lang = $args->{lang}; |
72 |
my $pref_only = $args->{pref_only}; |
48 |
my $pref_only = $args->{pref_only}; |
73 |
my $verbose = $args->{verbose}; |
49 |
my $verbose = $args->{verbose}; |
74 |
my $plugin_dirs = $args->{plugin_dirs} || _identify_translatable_plugins(); |
|
|
75 |
|
50 |
|
76 |
my $self = { }; |
51 |
my $self = { }; |
77 |
|
52 |
|
Lines 88-94
sub new {
Link Here
|
88 |
$self->{po2json} = "yarn run po2json"; |
63 |
$self->{po2json} = "yarn run po2json"; |
89 |
$self->{gzip} = `which gzip`; |
64 |
$self->{gzip} = `which gzip`; |
90 |
$self->{gunzip} = `which gunzip`; |
65 |
$self->{gunzip} = `which gunzip`; |
91 |
$self->{plugin_dirs} = $plugin_dirs; |
66 |
$self->{plugin_dirs} = _identify_translatable_plugins(); |
92 |
chomp $self->{msgfmt}; |
67 |
chomp $self->{msgfmt}; |
93 |
chomp $self->{gzip}; |
68 |
chomp $self->{gzip}; |
94 |
chomp $self->{gunzip}; |
69 |
chomp $self->{gunzip}; |
Lines 352-370
sub install_tmpl {
Link Here
|
352 |
} |
327 |
} |
353 |
} |
328 |
} |
354 |
|
329 |
|
355 |
for my $plugin ( @{$self->{plugin_dirs}} ) { |
330 |
for my $plugin ( @{ $self->{plugin_dirs} } ) { |
356 |
print |
331 |
if ( grep( $self->{lang} eq $_, @{ $plugin->{plugin_langs} } ) ) { |
357 |
" Install templates from plugin: '$plugin->{name}'\n", |
332 |
print |
358 |
if $self->{verbose}; |
333 |
" Install templates from plugin: '$plugin->{name}'\n", |
359 |
|
334 |
if $self->{verbose}; |
360 |
my $trans_dir = $plugin->{bundle_path} . "/views/en/"; |
335 |
|
361 |
my $lang_dir = $plugin->{bundle_path} . "/views/$self->{lang}"; |
336 |
my $trans_dir = $plugin->{bundle_path} . "/views/en/"; |
362 |
mkdir $lang_dir unless -d $lang_dir; |
337 |
my $lang_dir = $plugin->{bundle_path} . "/views/$self->{lang}"; |
363 |
|
338 |
mkdir $lang_dir unless -d $lang_dir; |
364 |
system "$self->{process} install " |
339 |
|
365 |
. "-i $trans_dir " |
340 |
system "$self->{process} install " |
366 |
. "-o $lang_dir " |
341 |
. "-i $trans_dir " |
367 |
. "-s $plugin->{bundle_path}/translator/po/$self->{lang}-$plugin->{name}-template.po -r " |
342 |
. "-o $lang_dir " |
|
|
343 |
. "-s $plugin->{bundle_path}/translator/po/$self->{lang}-$plugin->{name}-template.po -r "; |
344 |
} |
368 |
} |
345 |
} |
369 |
} |
346 |
} |
370 |
|
347 |
|
Lines 511-527
sub install_messages {
Link Here
|
511 |
|
488 |
|
512 |
# Add plugin javascript to the same file to avoid needing multiple imports in doc-head template files |
489 |
# 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); |
490 |
my $js_po_data = decode_json($json); |
514 |
foreach my $plugin ( @{$self->{plugin_dirs}} ) { |
491 |
foreach my $plugin ( @{ $self->{plugin_dirs} } ) { |
515 |
my $tmp_pluginpo = sprintf '/tmp/%s-%s.po', $plugin->{name}, $self->{lang}; |
492 |
if ( grep( $self->{lang} eq $_, @{ $plugin->{plugin_langs} } ) ) { |
516 |
my $plugin_po2json_cmd = sprintf '%s %s %s', $self->{po2json}, $plugin->{bundle_path} . '/translator/po/' . $self->{lang} . '-' . $plugin->{name} . '-js.po', $tmp_pluginpo; |
493 |
my $tmp_pluginpo = sprintf '/tmp/%s-%s.po', $plugin->{name}, $self->{lang}; |
517 |
`$plugin_po2json_cmd`; |
494 |
my $plugin_po2json_cmd = sprintf '%s %s %s', $self->{po2json}, |
518 |
my $plugin_json = read_file($tmp_pluginpo); |
495 |
$plugin->{bundle_path} . '/translator/po/' . $self->{lang} . '-' . $plugin->{name} . '-js.po', |
519 |
|
496 |
$tmp_pluginpo; |
520 |
my $plugin_js_po_data = decode_json($plugin_json); |
497 |
`$plugin_po2json_cmd`; |
521 |
delete $plugin_js_po_data->{''}; |
498 |
my $plugin_json = read_file($tmp_pluginpo); |
522 |
|
499 |
|
523 |
foreach my $key (keys %$plugin_js_po_data) { |
500 |
my $plugin_js_po_data = decode_json($plugin_json); |
524 |
$js_po_data->{$key} = $plugin_js_po_data->{$key} unless exists $js_po_data->{$key}; |
501 |
delete $plugin_js_po_data->{''}; |
|
|
502 |
|
503 |
foreach my $key ( keys %$plugin_js_po_data ) { |
504 |
$js_po_data->{$key} = $plugin_js_po_data->{$key} unless exists $js_po_data->{$key}; |
505 |
} |
525 |
} |
506 |
} |
526 |
} |
507 |
} |
527 |
my $combined_json = encode_json($js_po_data); |
508 |
my $combined_json = encode_json($js_po_data); |
Lines 595-600
sub get_all_langs {
Link Here
|
595 |
@files = map { $_ =~ s/-pref.(po|po.gz)$//r } @files; |
576 |
@files = map { $_ =~ s/-pref.(po|po.gz)$//r } @files; |
596 |
} |
577 |
} |
597 |
|
578 |
|
|
|
579 |
sub _identify_translatable_plugins { |
580 |
my ($args) = @_; |
581 |
|
582 |
my @plugins = Koha::Plugins::GetPlugins( |
583 |
{ |
584 |
metadata => { has_translations => 1 }, |
585 |
} |
586 |
); |
587 |
|
588 |
return () if scalar( @plugins == 0 ); |
589 |
|
590 |
my @plugin_dirs; |
591 |
foreach my $plugin (@plugins) { |
592 |
my $plugin_langs = $plugin->get_translated_languages(); |
593 |
my @path_params = split( /\//, $plugin->{_bundle_path} ); |
594 |
my $translation_data = { |
595 |
bundle_path => $plugin->{_bundle_path}, |
596 |
name => $path_params[-1], |
597 |
plugin_langs => $plugin_langs |
598 |
}; |
599 |
|
600 |
push @plugin_dirs, $translation_data; |
601 |
} |
602 |
return \@plugin_dirs; |
603 |
} |
604 |
|
605 |
|
598 |
1; |
606 |
1; |
599 |
|
607 |
|
600 |
|
608 |
|
601 |
- |
|
|