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

(-)a/misc/translator/LangInstaller.pm (-36 / +80 lines)
Lines 75-82 sub new { Link Here
75
75
76
    # Get all available language codes
76
    # Get all available language codes
77
    opendir $fh, $self->{path_po};
77
    opendir $fh, $self->{path_po};
78
    my @langs =  map { ($_) =~ /(.*)-i-opac/ } 
78
    my @langs =  map { ($_) =~ /(.*)-pref/ }
79
        grep { $_ =~ /.*-opac-t-prog/ } readdir($fh);
79
        grep { $_ =~ /.*-pref/ } readdir($fh);
80
    closedir $fh;
80
    closedir $fh;
81
    $self->{langs} = \@langs;
81
    $self->{langs} = \@langs;
82
82
Lines 86-97 sub new { Link Here
86
        {
86
        {
87
            name   => 'OPAC prog',
87
            name   => 'OPAC prog',
88
            dir    => "$opachtdocs/prog",
88
            dir    => "$opachtdocs/prog",
89
            suffix => '-i-opac-t-prog-v-3006000.po',
89
            suffix => '-opac-prog.po',
90
        },
90
        },
91
        {
91
        {
92
            name   => 'Intranet prog UI',
92
            name   => 'Intranet prog UI',
93
            dir    => $context->config('intrahtdocs') . '/prog',
93
            dir    => $context->config('intrahtdocs') . '/prog',
94
            suffix => '-i-staff-t-prog-v-3006000.po',
94
            suffix => '-staff-prog.po',
95
        },
95
        },
96
        {
96
        {
97
            name   => 'Intranet prog help',
97
            name   => 'Intranet prog help',
Lines 110-115 sub new { Link Here
110
        };
110
        };
111
    }
111
    }
112
112
113
    # MARC flavours (hardcoded list)
114
    for ( "MARC21", "UNIMARC", "NORMARC" ) {
115
        my $dirs = $context->config('intrahtdocs') . '/prog';
116
        opendir $fh, $context->config('opachtdocs');
117
        for ( grep { not /^\.|\.\.|lib$/ } readdir($fh) ) {
118
            $dirs .= ' ' . "$opachtdocs/$_";
119
        }
120
        push @{$self->{interface}}, {
121
            name   => "$_",
122
            dir    => $dirs,
123
            suffix => "-marc-$_.po",
124
        };
125
    }
126
113
    bless $self, $class;
127
    bless $self, $class;
114
}
128
}
115
129
Lines 329-357 sub install_tmpl { Link Here
329
    my ($self, $files) = @_;
343
    my ($self, $files) = @_;
330
    say "Install templates" if $self->{verbose};
344
    say "Install templates" if $self->{verbose};
331
    for my $trans ( @{$self->{interface}} ) {
345
    for my $trans ( @{$self->{interface}} ) {
332
        print
346
        my @t_dirs = split(" ", $trans->{dir});
333
            "  Install templates '$trans->{name}'\n",
347
        for my $t_dir ( @t_dirs ) {
334
            "    From: $trans->{dir}/en/\n",
348
            print
335
            "    To  : $trans->{dir}/$self->{lang}\n",
349
                "  Install templates '$trans->{name}'\n",
336
            "    With: $self->{path_po}/$self->{lang}$trans->{suffix}\n"
350
                "    From: $t_dir/en/\n",
351
                "    To  : $t_dir/$self->{lang}\n",
352
                "    With: $self->{path_po}/$self->{lang}$trans->{suffix}\n"
337
                if $self->{verbose};
353
                if $self->{verbose};
338
354
339
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
355
            my $trans_dir = ( $trans->{name} =~ /help/ )?"$t_dir":"$t_dir/en/";
340
        my $lang_dir  = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/$self->{lang}";
356
            my $lang_dir  = ( $trans->{name} =~ /help/ )?"$t_dir":"$t_dir/$self->{lang}";
341
        $lang_dir =~ s|/en/|/$self->{lang}/|;
357
            $lang_dir =~ s|/en/|/$self->{lang}/|;
342
        mkdir $lang_dir unless -d $lang_dir;
358
            mkdir $lang_dir unless -d $lang_dir;
343
        my $excludes  = ( $trans->{name} =~ /UI/   )?"-x 'help'":"";
359
            my $excludes  = ( $trans->{name} !~ /help/   )?"":"-x 'help'";
344
360
            my $match     = ( $trans->{name} =~ /MARC/ )?"-m \"$trans->{name}\"":"";            # for MARC translations
345
        system
361
            my $nomatch   = ( $trans->{name} !~ /MARC/ )?"-n \"marc21|unimarc|normarc\"":"";    # hardcoded MARC variants
346
            "$self->{process} install " .
362
347
            "-i $trans_dir " .
363
            system
348
            "-o $lang_dir  ".
364
                "$self->{process} install " .
349
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r $excludes" .
365
                "-i $trans_dir " .
350
            (
366
                "-o $lang_dir  ".
351
                @$files
367
                "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
352
                    ? ' -f ' . join ' -f ', @$files
368
                "$excludes " .
353
                    : ''
369
                "$match " .
354
            )
370
                "$nomatch " .
371
                (
372
                    @$files
373
                        ? ' -f ' . join ' -f ', @$files
374
                        : ''
375
                )
376
        }
355
    }
377
    }
356
}
378
}
357
379
Lines 366-381 sub update_tmpl { Link Here
366
            "    From: $trans->{dir}/en/\n",
388
            "    From: $trans->{dir}/en/\n",
367
            "    To  : $self->{path_po}/$self->{lang}$trans->{suffix}\n"
389
            "    To  : $self->{path_po}/$self->{lang}$trans->{suffix}\n"
368
                if $self->{verbose};
390
                if $self->{verbose};
369
        my $lang_dir = "$trans->{dir}/$self->{lang}";
370
        mkdir $lang_dir unless -d $lang_dir;
371
391
372
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
392
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
373
        my $excludes  = ( $trans->{name} =~ /UI/   )?"-x 'help'":"";
393
        my $excludes  = ( $trans->{name} !~ /help/ )?"":"-x 'help'";
394
        my $match     = ( $trans->{name} =~ /MARC/ )?"-m \"$trans->{name}\"":"";                      # for MARC translations
395
        my $dirs      = ( $trans->{name} =~ /MARC/ )?"-d ".join(" -d ",split(" ",$trans->{dir})):"";  # for MARC translations;
396
        my $nomatch   = ( $trans->{name} !~ /MARC/ )?"-n \"marc21|unimarc|normarc\"":"";              # hardcoded MARC variants
397
374
398
375
        system
399
        system
376
            "$self->{process} update " .
400
            "$self->{process} update " .
377
            "-i $trans_dir " .
401
            "-i $trans_dir " .
378
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r $excludes" .
402
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
403
            "$excludes " .
404
            "$dirs " .
405
            "$match " .
406
            "$nomatch " .
379
            (
407
            (
380
                @$files
408
                @$files
381
                    ? ' -f ' . join ' -f ', @$files
409
                    ? ' -f ' . join ' -f ', @$files
Lines 409-420 sub create_tmpl { Link Here
409
                if $self->{verbose};
437
                if $self->{verbose};
410
438
411
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
439
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
412
        my $excludes  = ( $trans->{name} =~ /UI/   )?"-x 'help'":"";
440
        my $excludes  = ( $trans->{name} !~ /help/ )?"":"-x 'help'";
441
        my $match     = ( $trans->{name} =~ /MARC/ )?"-m \"$trans->{name}\"":"";                      # for MARC translations
442
        my $dirs      = ( $trans->{name} =~ /MARC/ )?"-d ".join(" -d ",split(" ",$trans->{dir})):"";  # for MARC translations;
443
        my $nomatch   = ( $trans->{name} !~ /MARC/ )?"-n \"marc21|unimarc|normarc\"":"";              # hardcoded MARC variants
413
444
414
        system
445
        system
415
            "$self->{process} create " .
446
            "$self->{process} create " .
416
            "-i $trans_dir " .
447
            "-i $trans_dir " .
417
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r $excludes" .
448
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
449
            "$excludes " .
450
            "$dirs " .
451
            "$match " .
452
            "$nomatch " .
418
            (
453
            (
419
                @$files
454
                @$files
420
                    ? ' -f ' . join ' -f ', @$files
455
                    ? ' -f ' . join ' -f ', @$files
Lines 504-520 appropriate directory. Link Here
504
539
505
=item translate create F<lang>
540
=item translate create F<lang>
506
541
507
Create 3 .po files in F<po> subdirectory: (1) from opac pages templates, (2)
542
Create 4 kinds of .po files in F<po> subdirectory:
508
intranet templates, and (3) from preferences.
543
(1) one from each theme on opac pages templates,
544
(2) intranet templates and help,
545
(3) preferences, and
546
(4) one for each MARC dialect.
547
509
548
510
=over
549
=over
511
550
512
=item F<lang>-opac.po
551
=item F<lang>-opac-{theme}.po
513
552
514
Contains extracted text from english (en) OPAC templates found in
553
Contains extracted text from english (en) OPAC templates found in
515
<KOHA_ROOT>/koha-tmpl/opac-tmpl/prog/en/ directory.
554
<KOHA_ROOT>/koha-tmpl/opac-tmpl/{theme}/en/ directory.
516
555
517
=item F<lang>-intranet.po
556
=item F<lang>-staff-prog.po and F<lang>-staff-help.po
518
557
519
Contains extracted text from english (en) intranet templates found in
558
Contains extracted text from english (en) intranet templates found in
520
<KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
559
<KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
Lines 525-530 Contains extracted text from english (en) preferences. They are found in files Link Here
525
located in <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/admin/preferences
564
located in <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/admin/preferences
526
directory.
565
directory.
527
566
567
=item F<lang>-marc-{MARC}.po
568
569
Contains extracted text from english (en) files from opac and intranet,
570
related with MARC dialects.
571
528
=back
572
=back
529
573
530
=item pref-trans update F<lang>
574
=item pref-trans update F<lang>
(-)a/misc/translator/tmpl_process3.pl (-11 / +30 lines)
Lines 3-8 Link Here
3
# Parts copyright 2003-2004 Paul Poulain
3
# Parts copyright 2003-2004 Paul Poulain
4
# Parts copyright 2003-2004 Jerome Vizcaino
4
# Parts copyright 2003-2004 Jerome Vizcaino
5
# Parts copyright 2004 Ambrose Li
5
# Parts copyright 2004 Ambrose Li
6
# Parts copyrigth 2014 Bernardo Gonzalez Kriegel
6
7
7
=head1 NAME
8
=head1 NAME
8
9
Lines 24-29 use VerboseWarnings qw( :warn :die ); Link Here
24
25
25
use vars qw( $in_dir @filenames $str_file $out_dir $quiet );
26
use vars qw( $in_dir @filenames $str_file $out_dir $quiet );
26
use vars qw( @excludes $exclude_regex );
27
use vars qw( @excludes $exclude_regex );
28
use vars qw( @dirs $match $nomatch );
27
use vars qw( $recursive_p );
29
use vars qw( $recursive_p );
28
use vars qw( $pedantic_p );
30
use vars qw( $pedantic_p );
29
use vars qw( $href );
31
use vars qw( $href );
Lines 144-152 sub listfiles { Link Here
144
            || (defined $exclude_regex && $dirent =~ /^(?:$exclude_regex)$/)) {
146
            || (defined $exclude_regex && $dirent =~ /^(?:$exclude_regex)$/)) {
145
            ;
147
            ;
146
            } elsif (-f $path) {
148
            } elsif (-f $path) {
147
                my $basename = basename $path;
149
                my $basename = fileparse( $path );
148
                push @it, $path
150
                push @it, $path
149
                    if ( not @$filenames or ( grep { $path =~ /$_/ } @$filenames ) )
151
                    if ( not @$filenames or ( grep { $path =~ /$_/ } @$filenames ) )
152
                       and ( not defined $match   or $basename =~ /($match)/i )   # files to include
153
                       and ( not defined $nomatch or $basename !~ /($nomatch)/i ) # files not to include
150
                       and (!defined $type || $dirent =~ /\.(?:$type)$/) || $action eq 'install';
154
                       and (!defined $type || $dirent =~ /\.(?:$type)$/) || $action eq 'install';
151
            } elsif (-d $path && $recursive_p) {
155
            } elsif (-d $path && $recursive_p) {
152
                push @it, listfiles($path, $type, $action, $filenames);
156
                push @it, listfiles($path, $type, $action, $filenames);
Lines 194-200 Create or update PO files from templates, or install translated templates. Link Here
194
                              If given, only these files will be processed.
198
                              If given, only these files will be processed.
195
  -s, --str-file=FILE         Specify FILE as the translation (po) file
199
  -s, --str-file=FILE         Specify FILE as the translation (po) file
196
                              for input (install) or output (create, update)
200
                              for input (install) or output (create, update)
197
  -x, --exclude=REGEXP        Exclude files matching the given REGEXP
201
  -x, --exclude=REGEXP        Exclude dirs matching the given REGEXP
202
  -d, --dir=DIRECTORY         Get or update strings from DIRECTORY. Can have
203
                              multiple values. Using this ignore -i
204
  -m, --match=REGEXP          Pipe (|) separated list. Include only files
205
                              matching the given REGEXP.
206
  -n, --nomatch=REGEXP        Pipe (|) separated list. Exclude all files
207
                              matching the given REGEXP.
198
      --help                  Display this help and exit
208
      --help                  Display this help and exit
199
  -q, --quiet                 no output to screen (except for errors)
209
  -q, --quiet                 no output to screen (except for errors)
200
210
Lines 223-228 GetOptions( Link Here
223
    'recursive|r'           => \$recursive_p,
233
    'recursive|r'           => \$recursive_p,
224
    'str-file|s=s'          => \$str_file,
234
    'str-file|s=s'          => \$str_file,
225
    'exclude|x=s'           => \@excludes,
235
    'exclude|x=s'           => \@excludes,
236
    'dir|d=s'               => \@dirs,
237
    'match|m=s'             => \$match,
238
    'nomatch|n=s'           => \$nomatch,
226
    'quiet|q'               => \$quiet,
239
    'quiet|q'               => \$quiet,
227
    'pedantic-warnings|pedantic'    => sub { $pedantic_p = 1 },
240
    'pedantic-warnings|pedantic'    => sub { $pedantic_p = 1 },
228
    'help'              => \&usage,
241
    'help'              => \&usage,
Lines 261-267 for my $fn ( @filenames ) { Link Here
261
    die "You cannot specify input files and directories at the same time.\n"
274
    die "You cannot specify input files and directories at the same time.\n"
262
        if -d $fn;
275
        if -d $fn;
263
}
276
}
264
@in_files = listfiles($in_dir, $type, $action, \@filenames);
277
if ( @dirs ) { # with any -d ignore -i
278
    foreach ( @dirs ) {
279
        s/\/$//;
280
        @in_files = ( @in_files, listfiles($_, $type, $action, \@filenames));
281
    }
282
} else {
283
    @in_files = listfiles($in_dir, $type, $action, \@filenames);
284
}
265
285
266
# restores the string list from file
286
# restores the string list from file
267
$href = Locale::PO->load_file_ashash($str_file);
287
$href = Locale::PO->load_file_ashash($str_file);
Lines 348-354 if ($action eq 'create') { Link Here
348
        close INPUT;
368
        close INPUT;
349
        close OUTPUT;
369
        close OUTPUT;
350
    }
370
    }
351
    $st = system("msgmerge -U ".($quiet?'-q':'')." -s $str_file $tmpfile2");
371
    $st = system("msgmerge ".($quiet?'-q':'')." -s $str_file $tmpfile2 -o - | msgattrib --no-obsolete -o $str_file");
352
    } else {
372
    } else {
353
    error_normal "Text extraction failed: $xgettext: $!\n", undef;
373
    error_normal "Text extraction failed: $xgettext: $!\n", undef;
354
    error_additional "Will not run msgmerge\n", undef;
374
    error_additional "Will not run msgmerge\n", undef;
Lines 377-386 if ($action eq 'create') { Link Here
377
        if ( @filenames ) {
397
        if ( @filenames ) {
378
            my ($tmph3, $tmpfile3) = tmpnam();
398
            my ($tmph3, $tmpfile3) = tmpnam();
379
            $st = system("msgcat $str_file $tmpfile2 > $tmpfile3");
399
            $st = system("msgcat $str_file $tmpfile2 > $tmpfile3");
380
            $st = system("msgmerge -U ".($quiet?'-q':'')." -s $str_file $tmpfile3")
400
            $st = system("msgmerge ".($quiet?'-q':'')." -s $str_file $tmpfile3 -o - | msgattrib --no-obsolete -o $str_file")
381
                unless $st;
401
                unless $st;
382
        } else {
402
        } else {
383
            $st = system("msgmerge -U ".($quiet?'-q':'')." -s $str_file $tmpfile2");
403
            $st = system("msgmerge ".($quiet?'-q':'')." -s $str_file $tmpfile2 -o - | msgattrib --no-obsolete -o $str_file");
384
        }
404
        }
385
    } else {
405
    } else {
386
        error_normal "Text extraction failed: $xgettext: $!\n", undef;
406
        error_normal "Text extraction failed: $xgettext: $!\n", undef;
Lines 532-541 actual work. Link Here
532
552
533
=head1 BUGS
553
=head1 BUGS
534
554
535
xgettext.pl must be present in the current directory; the
555
xgettext.pl must be present in the current directory;
536
msgmerge(1) command must also be present in the search path.
556
msgmerge(1) and msgattrib(1) commands must also be present
537
The script currently does not check carefully whether these
557
in the search path. The script currently does not check
538
dependent commands are present.
558
carefully whether these dependent commands are present.
539
559
540
Locale::PO(3) has a lot of bugs. It can neither parse nor
560
Locale::PO(3) has a lot of bugs. It can neither parse nor
541
generate GNU PO files properly; a couple of workarounds have
561
generate GNU PO files properly; a couple of workarounds have
542
- 

Return to bug 7939