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

(-)a/misc/translator/LangInstaller.pm (-11 / +48 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)
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}} ) {
346
    my @t_dirs = split(" ", $trans->{dir});
347
    for my $t_dir ( @t_dirs ) {
332
        print
348
        print
333
            "  Install templates '$trans->{name}'\n",
349
            "  Install templates '$trans->{name}'\n",
334
            "    From: $trans->{dir}/en/\n",
350
            "    From: $t_dir/en/\n",
335
            "    To  : $trans->{dir}/$self->{lang}\n",
351
            "    To  : $t_dir/$self->{lang}\n",
336
            "    With: $self->{path_po}/$self->{lang}$trans->{suffix}\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} =~ /UI/   )?"-x 'help'":"";
360
        my $match     = ( $trans->{name} =~ /MARC/ )?"-m \"$trans->{name}\"":"";                      # for MARC translations
361
        my $nomatch   = ( $trans->{name} !~ /MARC/ )?"-n \"marc21|unimarc|normarc\"":"";              # hardcoded MARC variants
344
362
345
        system
363
        system
346
            "$self->{process} install " .
364
            "$self->{process} install " .
347
            "-i $trans_dir " .
365
            "-i $trans_dir " .
348
            "-o $lang_dir  ".
366
            "-o $lang_dir  ".
349
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r $excludes" .
367
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
368
            "$excludes " .
369
            "$match " .
370
            "$nomatch " .
350
            (
371
            (
351
                @$files
372
                @$files
352
                    ? ' -f ' . join ' -f ', @$files
373
                    ? ' -f ' . join ' -f ', @$files
353
                    : ''
374
                    : ''
354
            )
375
            )
376
        }
355
    }
377
    }
356
}
378
}
357
379
Lines 371-381 sub update_tmpl { Link Here
371
393
372
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
394
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
373
        my $excludes  = ( $trans->{name} =~ /UI/   )?"-x 'help'":"";
395
        my $excludes  = ( $trans->{name} =~ /UI/   )?"-x 'help'":"";
396
        my $match     = ( $trans->{name} =~ /MARC/ )?"-m \"$trans->{name}\"":"";                      # for MARC translations
397
        my $dirs      = ( $trans->{name} =~ /MARC/ )?"-d ".join(" -d ",split(" ",$trans->{dir})):"";  # for MARC translations;
398
        my $nomatch   = ( $trans->{name} !~ /MARC/ )?"-n \"marc21|unimarc|normarc\"":"";              # hardcoded MARC variants
399
374
400
375
        system
401
        system
376
            "$self->{process} update " .
402
            "$self->{process} update " .
377
            "-i $trans_dir " .
403
            "-i $trans_dir " .
378
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r $excludes" .
404
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
405
            "$excludes " .
406
            "$dirs " .
407
            "$match " .
408
            "$nomatch " .
379
            (
409
            (
380
                @$files
410
                @$files
381
                    ? ' -f ' . join ' -f ', @$files
411
                    ? ' -f ' . join ' -f ', @$files
Lines 410-420 sub create_tmpl { Link Here
410
440
411
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
441
        my $trans_dir = ( $trans->{name} =~ /help/ )?"$trans->{dir}":"$trans->{dir}/en/";
412
        my $excludes  = ( $trans->{name} =~ /UI/   )?"-x 'help'":"";
442
        my $excludes  = ( $trans->{name} =~ /UI/   )?"-x 'help'":"";
443
        my $match     = ( $trans->{name} =~ /MARC/ )?"-m \"$trans->{name}\"":"";                      # for MARC translations
444
        my $dirs      = ( $trans->{name} =~ /MARC/ )?"-d ".join(" -d ",split(" ",$trans->{dir})):"";  # for MARC translations;
445
        my $nomatch   = ( $trans->{name} !~ /MARC/ )?"-n \"marc21|unimarc|normarc\"":"";              # hardcoded MARC variants
413
446
414
        system
447
        system
415
            "$self->{process} create " .
448
            "$self->{process} create " .
416
            "-i $trans_dir " .
449
            "-i $trans_dir " .
417
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r $excludes" .
450
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
451
            "$excludes " .
452
            "$dirs " .
453
            "$match " .
454
            "$nomatch " .
418
            (
455
            (
419
                @$files
456
                @$files
420
                    ? ' -f ' . join ' -f ', @$files
457
                    ? ' -f ' . join ' -f ', @$files
(-)a/misc/translator/tmpl_process3.pl (-7 / +26 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;
387
- 

Return to bug 7939