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

(-)a/misc/translator/LangInstaller.pm (-36 / +52 lines)
Lines 17-24 package LangInstaller; Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use C4::Context;
22
use C4::Context;
24
# WARNING: Any other tested YAML library fails to work properly in this
23
# WARNING: Any other tested YAML library fails to work properly in this
Lines 29-34 use FindBin qw( $Bin ); Link Here
29
28
30
$YAML::Syck::ImplicitTyping = 1;
29
$YAML::Syck::ImplicitTyping = 1;
31
30
31
32
sub set_lang {
32
sub set_lang {
33
    my ($self, $lang) = @_;
33
    my ($self, $lang) = @_;
34
34
Lines 63-83 sub new { Link Here
63
    # Get all available language codes
63
    # Get all available language codes
64
    opendir $fh, $self->{path_po};
64
    opendir $fh, $self->{path_po};
65
    my @langs =  map { ($_) =~ /(.*)-i-opac/ } 
65
    my @langs =  map { ($_) =~ /(.*)-i-opac/ } 
66
        grep { $_ =~ /.*-opac-/ } readdir($fh);
66
        grep { $_ =~ /.*-opac-t-prog/ } readdir($fh);
67
    closedir $fh;
67
    closedir $fh;
68
    $self->{langs} = \@langs;
68
    $self->{langs} = \@langs;
69
69
70
    # Map for both interfaces opac/intranet
70
    # Map for both interfaces opac/intranet
71
    $self->{interface} = {
71
    my $opachtdocs = $context->config('opachtdocs');
72
        opac => {
72
    $self->{interface} = [
73
            dir    => $context->config('opachtdocs') . '/prog',
73
        {
74
            name   => 'OPAC prog',
75
            dir    => "$opachtdocs/prog",
74
            suffix => '-i-opac-t-prog-v-3006000.po',
76
            suffix => '-i-opac-t-prog-v-3006000.po',
75
        },
77
        },
76
        intranet => {
78
        {
79
            name   => 'Intranet prog',
77
            dir    => $context->config('intrahtdocs') . '/prog',
80
            dir    => $context->config('intrahtdocs') . '/prog',
78
            suffix => '-i-staff-t-prog-v-3006000.po',
81
            suffix => '-i-staff-t-prog-v-3006000.po',
79
        }
82
        },
80
    };
83
    ];
84
85
    # Alternate opac themes
86
    opendir $fh, $context->config('opachtdocs');
87
    for ( grep { not /^\.|\.\.|prog|lib$/ } readdir($fh) ) {
88
        push @{$self->{interface}}, {
89
            name   => "OPAC $_",
90
            dir    => "$opachtdocs/$_",
91
            suffix => "-opac-$_.po",
92
        };
93
    }
81
94
82
    bless $self, $class;
95
    bless $self, $class;
83
}
96
}
Lines 211-217 sub save_po { Link Here
211
    my $self = shift;
224
    my $self = shift;
212
    # Write .po entries into a file put in Koha standard po directory
225
    # Write .po entries into a file put in Koha standard po directory
213
    Locale::PO->save_file_fromhash( $self->po_filename, $self->{po} );
226
    Locale::PO->save_file_fromhash( $self->po_filename, $self->{po} );
214
    print "Saved in file: ", $self->po_filename, "\n" if $self->{verbose};
227
    say "Saved in file: ", $self->po_filename if $self->{verbose};
215
}
228
}
216
229
217
230
Lines 291-311 sub install_prefs { Link Here
291
304
292
sub install_tmpl {
305
sub install_tmpl {
293
    my $self = shift;
306
    my $self = shift;
294
    print "Install templates\n" if $self->{verbose};
307
    say "Install templates" if $self->{verbose};
295
    while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
308
    for my $trans ( @{$self->{interface}} ) {
296
        print
309
        print
297
            "  Install templates '$interface\n",
310
            "  Install templates '$trans->{name}'\n",
298
            "    From: $tmpl->{dir}/en/\n",
311
            "    From: $trans->{dir}/en/\n",
299
            "    To  : $tmpl->{dir}/$self->{lang}\n",
312
            "    To  : $trans->{dir}/$self->{lang}\n",
300
            "    With: $self->{path_po}/$self->{lang}$tmpl->{suffix}\n"
313
            "    With: $self->{path_po}/$self->{lang}$trans->{suffix}\n"
301
                if $self->{verbose};
314
                if $self->{verbose};
302
        my $lang_dir = "$tmpl->{dir}/$self->{lang}";
315
        my $lang_dir = "$trans->{dir}/$self->{lang}";
303
        mkdir $lang_dir unless -d $lang_dir;
316
        mkdir $lang_dir unless -d $lang_dir;
304
        system
317
        system
305
            "$self->{process} install " .
318
            "$self->{process} install " .
306
            "-i $tmpl->{dir}/en/ " .
319
            "-i $trans->{dir}/en/ " .
307
            "-o $tmpl->{dir}/$self->{lang} ".
320
            "-o $trans->{dir}/$self->{lang} ".
308
            "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
321
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r"
309
    }
322
    }
310
}
323
}
311
324
Lines 313-331 sub install_tmpl { Link Here
313
sub update_tmpl {
326
sub update_tmpl {
314
    my $self = shift;
327
    my $self = shift;
315
328
316
    print "Update templates\n" if $self->{verbose};
329
    say "Update templates" if $self->{verbose};
317
    while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
330
    for my $trans ( @{$self->{interface}} ) {
318
        print
331
        print
319
            "  Update templates '$interface'\n",
332
            "  Update templates '$trans->{name}'\n",
320
            "    From: $tmpl->{dir}/en/\n",
333
            "    From: $trans->{dir}/en/\n",
321
            "    To  : $self->{path_po}/$self->{lang}$tmpl->{suffix}\n"
334
            "    To  : $self->{path_po}/$self->{lang}$trans->{suffix}\n"
322
                if $self->{verbose};
335
                if $self->{verbose};
323
        my $lang_dir = "$tmpl->{dir}/$self->{lang}";
336
        my $lang_dir = "$trans->{dir}/$self->{lang}";
324
        mkdir $lang_dir unless -d $lang_dir;
337
        mkdir $lang_dir unless -d $lang_dir;
325
        system
338
        system
326
            "$self->{process} update " .
339
            "$self->{process} update " .
327
            "-i $tmpl->{dir}/en/ " .
340
            "-i $trans->{dir}/en/ " .
328
            "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
341
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r"
329
    }
342
    }
330
}
343
}
331
344
Lines 333-338 sub update_tmpl { Link Here
333
sub create_prefs {
346
sub create_prefs {
334
    my $self = shift;
347
    my $self = shift;
335
348
349
    if ( -e $self->po_filename ) {
350
        say "Preferences .po file already exists. Delete it if you want to recreate it.";
351
        return;
352
    }
336
    $self->get_po_from_prefs();
353
    $self->get_po_from_prefs();
337
    $self->save_po();
354
    $self->save_po();
338
}
355
}
Lines 341-357 sub create_prefs { Link Here
341
sub create_tmpl {
358
sub create_tmpl {
342
    my $self = shift;
359
    my $self = shift;
343
360
344
    print "Create templates\n" if $self->{verbose};
361
    say "Create templates\n" if $self->{verbose};
345
    while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
362
    for my $trans ( @{$self->{interface}} ) {
346
        print
363
        print
347
            "  Create templates .po files for '$interface'\n",
364
            "  Create templates .po files for '$trans->{name}'\n",
348
            "    From: $tmpl->{dir}/en/\n",
365
            "    From: $trans->{dir}/en/\n",
349
            "    To  : $self->{path_po}/$self->{lang}$tmpl->{suffix}\n"
366
            "    To  : $self->{path_po}/$self->{lang}$trans->{suffix}\n"
350
                if $self->{verbose};
367
                if $self->{verbose};
351
        system
368
        system
352
            "$self->{process} create " .
369
            "$self->{process} create " .
353
            "-i $tmpl->{dir}/en/ " .
370
            "-i $trans->{dir}/en/ " .
354
            "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
371
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r"
355
    }
372
    }
356
}
373
}
357
374
358
- 

Return to bug 8633