View | Details | Raw Unified | Return to bug 37472
Collapse All | Expand All

(-)a/C4/Templates.pm (+3 lines)
Lines 179-184 sub _get_template_file { Link Here
179
    $tmplbase = "$htdocs/$theme/$lang/modules/$tmplbase" if $tmplbase !~ /^\//;
179
    $tmplbase = "$htdocs/$theme/$lang/modules/$tmplbase" if $tmplbase !~ /^\//;
180
        # do not prefix an absolute path
180
        # do not prefix an absolute path
181
181
182
    if ( $tmplbase =~ /plugin/ && $tmplbase =~ /^\// ) {
183
        $tmplbase =~ s/\/en\//\/$lang\//;
184
    }
182
    return ( $htdocs, $theme, $lang, $tmplbase );
185
    return ( $htdocs, $theme, $lang, $tmplbase );
183
}
186
}
184
187
(-)a/Koha/Plugins.pm (+9 lines)
Lines 278-283 sub InstallPlugins { Link Here
278
278
279
    my @plugin_classes = $self->plugins();
279
    my @plugin_classes = $self->plugins();
280
    my @plugins;
280
    my @plugins;
281
    my @plugins_to_translate;
281
282
282
    foreach my $plugin_class (@plugin_classes) {
283
    foreach my $plugin_class (@plugin_classes) {
283
        if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) {
284
        if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) {
Lines 308-316 sub InstallPlugins { Link Here
308
            }
309
            }
309
310
310
            push @plugins, $plugin;
311
            push @plugins, $plugin;
312
313
            my @path_params = split( /\//, $plugin->{_bundle_path} );
314
            my $translation_data = {
315
                bundle_path => $plugin->{_bundle_path},
316
                name => $path_params[-1],
317
            };
311
        }
318
        }
312
    }
319
    }
313
320
321
    # Add translator stuff here
322
314
    Koha::Cache::Memory::Lite->clear_from_cache(ENABLED_PLUGINS_CACHE_KEY);
323
    Koha::Cache::Memory::Lite->clear_from_cache(ENABLED_PLUGINS_CACHE_KEY);
315
324
316
    $self->_restart_after_change();
325
    $self->_restart_after_change();
(-)a/misc/translator/LangInstaller.pm (-3 / +69 lines)
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();
(-)a/misc/translator/translate (-2 / +7 lines)
Lines 55-61 usage() if $#ARGV != 1 && $#ARGV != 0; Link Here
55
my ($cmd, $lang) = @ARGV;
55
my ($cmd, $lang) = @ARGV;
56
$cmd = lc $cmd;
56
$cmd = lc $cmd;
57
if ( $cmd =~ /^(install|compress|uncompress)$/ ) {
57
if ( $cmd =~ /^(install|compress|uncompress)$/ ) {
58
    my $installer = LangInstaller->new( $lang, $pref, $verbose );
58
    my $installer = LangInstaller->new(
59
        {
60
            lang      => $lang,
61
            pref_only => $pref,
62
            verbose   => $verbose
63
        }
64
    );
59
    if ( $lang and not grep( {$_ eq $lang} @{ $installer->{langs} } ) ) {
65
    if ( $lang and not grep( {$_ eq $lang} @{ $installer->{langs} } ) ) {
60
        print "Unsupported language: $lang\n";
66
        print "Unsupported language: $lang\n";
61
        exit;
67
        exit;
62
- 

Return to bug 37472