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

(-)a/Koha/Plugins.pm (-7 / +22 lines)
Lines 278-284 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;
282
281
283
    foreach my $plugin_class (@plugin_classes) {
282
    foreach my $plugin_class (@plugin_classes) {
284
        if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) {
283
        if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) {
Lines 309-324 sub InstallPlugins { Link Here
309
            }
308
            }
310
309
311
            push @plugins, $plugin;
310
            push @plugins, $plugin;
311
        }
312
    }
312
313
313
            my @path_params = split( /\//, $plugin->{_bundle_path} );
314
    my @plugin_languages;
314
            my $translation_data = {
315
    my $dev_detected;
315
                bundle_path => $plugin->{_bundle_path},
316
    foreach my $plugin (@plugins) {
316
                name => $path_params[-1],
317
        my $plugin_langs = $plugin->get_translated_languages();
317
            };
318
319
        foreach my $lang (@$plugin_langs) {
320
            push( @plugin_languages, $lang ) unless grep( $_ eq $lang, @plugin_languages );
318
        }
321
        }
322
323
        $dev_detected = 1 if ( $plugin->{_bundle_path} =~ /kohadev/i );
319
    }
324
    }
320
325
321
    # Add translator stuff here
326
    # Install translations if a language is already installed on the system
327
    if ( scalar(@plugin_languages) > 0 ) {
328
        my @translated_languages = map { $_->{rfc4646_subtag} }
329
            @{ C4::Languages::getTranslatedLanguages( "both", C4::Context->preference('template') ) };
330
        foreach my $lang (@plugin_languages) {
331
            next unless grep( $_ eq $lang, @translated_languages );
332
            my $translate_cmd = "koha-translate --update $lang";
333
            $translate_cmd .= " --dev kohadev" if $dev_detected;
334
            system $translate_cmd;
335
        }
336
    }
322
337
323
    Koha::Cache::Memory::Lite->clear_from_cache(ENABLED_PLUGINS_CACHE_KEY);
338
    Koha::Cache::Memory::Lite->clear_from_cache(ENABLED_PLUGINS_CACHE_KEY);
324
339
(-)a/Koha/Plugins/Base.pm (+23 lines)
Lines 392-397 sub disable { Link Here
392
    return $self;
392
    return $self;
393
}
393
}
394
394
395
=head2 get_translated_languages
396
397
Identifies whether a plugin has any translated languages
398
399
=cut
400
401
sub get_translated_languages {
402
    my ($self) = @_;
403
404
    my @path_params = split( /\//, $self->{_bundle_path} );
405
    my $name        = $path_params[-1];
406
    my $po_path     = $self->{_bundle_path} . "/translator/po";
407
408
    if ( -e $po_path ) {
409
        opendir my $fh, $po_path or die $!;
410
        my @langs = map { ($_) =~ /(.*)-$name-js/ }
411
            grep { $_ =~ /.*-$name-js/ } readdir($fh);
412
        closedir $fh;
413
        return \@langs;
414
    }
415
    return ();
416
}
417
395
1;
418
1;
396
__END__
419
__END__
397
420
(-)a/misc/translator/LangInstaller.pm (-51 / +58 lines)
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
- 

Return to bug 37472