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

(-)a/misc/translator/LangInstaller.pm (-12 / +27 lines)
Lines 321-327 sub install_prefs { Link Here
321
321
322
322
323
sub install_tmpl {
323
sub install_tmpl {
324
    my $self = shift;
324
    my ($self, $files) = @_;
325
    say "Install templates" if $self->{verbose};
325
    say "Install templates" if $self->{verbose};
326
    for my $trans ( @{$self->{interface}} ) {
326
    for my $trans ( @{$self->{interface}} ) {
327
        print
327
        print
Lines 336-348 sub install_tmpl { Link Here
336
            "$self->{process} install " .
336
            "$self->{process} install " .
337
            "-i $trans->{dir}/en/ " .
337
            "-i $trans->{dir}/en/ " .
338
            "-o $trans->{dir}/$self->{lang} ".
338
            "-o $trans->{dir}/$self->{lang} ".
339
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r"
339
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
340
            (
341
                $files
342
                    ? '-f ' . join ' -f ', @$files
343
                    : ''
344
            )
340
    }
345
    }
341
}
346
}
342
347
343
348
344
sub update_tmpl {
349
sub update_tmpl {
345
    my $self = shift;
350
    my ($self, $files) = @_;
346
351
347
    say "Update templates" if $self->{verbose};
352
    say "Update templates" if $self->{verbose};
348
    for my $trans ( @{$self->{interface}} ) {
353
    for my $trans ( @{$self->{interface}} ) {
Lines 356-362 sub update_tmpl { Link Here
356
        system
361
        system
357
            "$self->{process} update " .
362
            "$self->{process} update " .
358
            "-i $trans->{dir}/en/ " .
363
            "-i $trans->{dir}/en/ " .
359
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r"
364
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
365
            (
366
                $files
367
                    ? '-f ' . join ' -f ', @$files
368
                    : ''
369
            )
360
    }
370
    }
361
}
371
}
362
372
Lines 374-380 sub create_prefs { Link Here
374
384
375
385
376
sub create_tmpl {
386
sub create_tmpl {
377
    my $self = shift;
387
    my ($self, $files) = @_;
378
388
379
    say "Create templates\n" if $self->{verbose};
389
    say "Create templates\n" if $self->{verbose};
380
    for my $trans ( @{$self->{interface}} ) {
390
    for my $trans ( @{$self->{interface}} ) {
Lines 386-400 sub create_tmpl { Link Here
386
        system
396
        system
387
            "$self->{process} create " .
397
            "$self->{process} create " .
388
            "-i $trans->{dir}/en/ " .
398
            "-i $trans->{dir}/en/ " .
389
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r"
399
            "-s $self->{path_po}/$self->{lang}$trans->{suffix} -r " .
400
            (
401
                $files
402
                    ? '-f ' . join ' -f ', @$files
403
                    : ''
404
            )
390
    }
405
    }
391
}
406
}
392
407
393
408
394
sub install {
409
sub install {
395
    my $self = shift;
410
    my ($self, $files) = @_;
396
    return unless $self->{lang};
411
    return unless $self->{lang};
397
    $self->install_tmpl() unless $self->{pref_only};
412
    $self->install_tmpl($files) unless $self->{pref_only};
398
    $self->install_prefs();
413
    $self->install_prefs();
399
}
414
}
400
415
Lines 409-428 sub get_all_langs { Link Here
409
424
410
425
411
sub update {
426
sub update {
412
    my $self = shift;
427
    my ($self, $files) = @_;
413
    my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs();
428
    my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs();
414
    for my $lang ( @langs ) {
429
    for my $lang ( @langs ) {
415
        $self->set_lang( $lang );
430
        $self->set_lang( $lang );
416
        $self->update_tmpl() unless $self->{pref_only};
431
        $self->update_tmpl($files) unless $self->{pref_only};
417
        $self->update_prefs();
432
        $self->update_prefs();
418
    }
433
    }
419
}
434
}
420
435
421
436
422
sub create {
437
sub create {
423
    my $self = shift;
438
    my ($self, $files) = @_;
424
    return unless $self->{lang};
439
    return unless $self->{lang};
425
    $self->create_tmpl() unless $self->{pref_only};
440
    $self->create_tmpl($files) unless $self->{pref_only};
426
    $self->create_prefs();
441
    $self->create_prefs();
427
}
442
}
428
443
(-)a/misc/translator/tmpl_process3.pl (-45 / +42 lines)
Lines 13-18 using gettext-compatible translation files Link Here
13
13
14
use strict;
14
use strict;
15
#use warnings; FIXME - Bug 2505
15
#use warnings; FIXME - Bug 2505
16
use File::Basename;
16
use Getopt::Long;
17
use Getopt::Long;
17
use Locale::PO;
18
use Locale::PO;
18
use File::Temp qw( :POSIX );
19
use File::Temp qw( :POSIX );
Lines 21-27 use VerboseWarnings qw( :warn :die ); Link Here
21
22
22
###############################################################################
23
###############################################################################
23
24
24
use vars qw( @in_files $in_dir $str_file $out_dir $quiet );
25
use vars qw( $in_dir @filenames $str_file $out_dir $quiet );
25
use vars qw( @excludes $exclude_regex );
26
use vars qw( @excludes $exclude_regex );
26
use vars qw( $recursive_p );
27
use vars qw( $recursive_p );
27
use vars qw( $pedantic_p );
28
use vars qw( $pedantic_p );
Lines 131-155 sub text_replace (**) { Link Here
131
    }
132
    }
132
}
133
}
133
134
134
sub listfiles ($$$) {
135
sub listfiles {
135
    my($dir, $type, $action) = @_;
136
    my($dir, $type, $action, $filenames) = @_;
136
    my @it = ();
137
    my @it = ();
137
    if (opendir(DIR, $dir)) {
138
    if (opendir(DIR, $dir)) {
138
    my @dirent = readdir DIR;   # because DIR is shared when recursing
139
        my @dirent = readdir DIR;   # because DIR is shared when recursing
139
    closedir DIR;
140
        closedir DIR;
140
    for my $dirent (@dirent) {
141
        for my $dirent (@dirent) {
141
        my $path = "$dir/$dirent";
142
            my $path = "$dir/$dirent";
142
        if ($dirent =~ /^\./ || $dirent eq 'CVS' || $dirent eq 'RCS'
143
            if ($dirent =~ /^\./ || $dirent eq 'CVS' || $dirent eq 'RCS'
143
        || (defined $exclude_regex && $dirent =~ /^(?:$exclude_regex)$/)) {
144
            || (defined $exclude_regex && $dirent =~ /^(?:$exclude_regex)$/)) {
144
        ;
145
            ;
145
        } elsif (-f $path) {
146
            } elsif (-f $path) {
146
        push @it, $path if (!defined $type || $dirent =~ /\.(?:$type)$/) || $action eq 'install';
147
                my $basename = basename $path;
147
        } elsif (-d $path && $recursive_p) {
148
                push @it, $path
148
        push @it, listfiles($path, $type, $action);
149
                    if ( not @$filenames or ( grep { $basename =~ /$_/ } @$filenames ) )
150
                       and (!defined $type || $dirent =~ /\.(?:$type)$/) || $action eq 'install';
151
            } elsif (-d $path && $recursive_p) {
152
                push @it, listfiles($path, $type, $action, $filenames);
153
            }
149
        }
154
        }
150
    }
151
    } else {
155
    } else {
152
    warn_normal "$dir: $!", undef;
156
        warn_normal "$dir: $!", undef;
153
    }
157
    }
154
    return @it;
158
    return @it;
155
}
159
}
Lines 181-192 Usage: $0 create [OPTION] Link Here
181
  or:  $0 --help
185
  or:  $0 --help
182
Create or update PO files from templates, or install translated templates.
186
Create or update PO files from templates, or install translated templates.
183
187
184
  -i, --input=SOURCE          Get or update strings from SOURCE file.
188
  -i, --input=SOURCE          Get or update strings from SOURCE directory.
185
                              SOURCE is a directory if -r is also specified.
186
  -o, --outputdir=DIRECTORY   Install translation(s) to specified DIRECTORY
189
  -o, --outputdir=DIRECTORY   Install translation(s) to specified DIRECTORY
187
      --pedantic-warnings     Issue warnings even for detected problems
190
      --pedantic-warnings     Issue warnings even for detected problems
188
                              which are likely to be harmless
191
                              which are likely to be harmless
189
  -r, --recursive             SOURCE in the -i option is a directory
192
  -r, --recursive             SOURCE in the -i option is a directory
193
  -f, --filename=FILE         FILE is a specific filaneme.
194
                              If given, only these files will be processed.
190
  -s, --str-file=FILE         Specify FILE as the translation (po) file
195
  -s, --str-file=FILE         Specify FILE as the translation (po) file
191
                              for input (install) or output (create, update)
196
                              for input (install) or output (create, update)
192
  -x, --exclude=REGEXP        Exclude files matching the given REGEXP
197
  -x, --exclude=REGEXP        Exclude files matching the given REGEXP
Lines 212-218 sub usage_error (;$) { Link Here
212
###############################################################################
217
###############################################################################
213
218
214
GetOptions(
219
GetOptions(
215
    'input|i=s'             => \@in_files,
220
    'input|i=s'             => \$in_dir,
221
    'filename|f=s'          => \@filenames,
216
    'outputdir|o=s'         => \$out_dir,
222
    'outputdir|o=s'         => \$out_dir,
217
    'recursive|r'           => \$recursive_p,
223
    'recursive|r'           => \$recursive_p,
218
    'str-file|s=s'          => \$str_file,
224
    'str-file|s=s'          => \$str_file,
Lines 233-268 $SIG{__WARN__} = sub { Link Here
233
239
234
my $action = shift or usage_error('You must specify an ACTION.');
240
my $action = shift or usage_error('You must specify an ACTION.');
235
usage_error('You must at least specify input and string list filenames.')
241
usage_error('You must at least specify input and string list filenames.')
236
    if !@in_files || !defined $str_file;
242
    if !$in_dir || !defined $str_file;
237
243
238
# Type match defaults to *.tt plus *.inc if not specified
244
# Type match defaults to *.tt plus *.inc if not specified
239
$type = "tt|inc|xsl|xml" if !defined($type);
245
$type = "tt|inc|xsl|xml" if !defined($type);
240
246
241
# Check the inputs for being files or directories
247
# Check the inputs for being directories
242
for my $input (@in_files) {
248
usage_error("$in_dir: Input must be a directory.\n"
243
    usage_error("$input: Input must be a file or directory.\n"
249
    . "(Symbolic links are not supported at the moment)")
244
        . "(Symbolic links are not supported at the moment)")
250
    unless -d $in_dir;
245
    unless -d $input || -f $input;;
246
}
247
251
248
# Generates the global exclude regular expression
252
# Generates the global exclude regular expression
249
$exclude_regex =  '(?:'.join('|', @excludes).')' if @excludes;
253
$exclude_regex =  '(?:'.join('|', @excludes).')' if @excludes;
250
254
255
my @in_files;
251
# Generate the list of input files if a directory is specified
256
# Generate the list of input files if a directory is specified
252
if (-d $in_files[0]) {
257
# input is a directory, generates list of files to process
253
    die "If you specify a directory as input, you must specify only it.\n"
258
$in_dir =~ s/\/$//; # strips the trailing / if any
254
        if @in_files > 1;
259
255
260
for my $fn ( @filenames ) {
256
    # input is a directory, generates list of files to process
257
    $in_dir = $in_files[0];
258
    $in_dir =~ s/\/$//; # strips the trailing / if any
259
    @in_files = listfiles($in_dir, $type, $action);
260
} else {
261
    for my $input (@in_files) {
262
    die "You cannot specify input files and directories at the same time.\n"
261
    die "You cannot specify input files and directories at the same time.\n"
263
        unless -f $input;
262
        if -d $fn;
264
    }
265
}
263
}
264
@in_files = listfiles($in_dir, $type, $action, \@filenames);
266
265
267
# restores the string list from file
266
# restores the string list from file
268
$href = Locale::PO->load_file_ashash($str_file);
267
$href = Locale::PO->load_file_ashash($str_file);
Lines 405-427 if ($action eq 'create') { Link Here
405
    for my $input (@in_files) {
404
    for my $input (@in_files) {
406
        die "Assertion failed"
405
        die "Assertion failed"
407
            unless substr($input, 0, length($in_dir) + 1) eq "$in_dir/";
406
            unless substr($input, 0, length($in_dir) + 1) eq "$in_dir/";
408
#       print "$input / $type\n";
407
408
        my $target = $out_dir . substr($input, length($in_dir));
409
        my $targetdir = $` if $target =~ /[^\/]+$/s;
410
409
        if (!defined $type || $input =~ /\.(?:$type)$/) {
411
        if (!defined $type || $input =~ /\.(?:$type)$/) {
410
            my $h = TmplTokenizer->new( $input );
412
            my $h = TmplTokenizer->new( $input );
411
            $h->set_allow_cformat( 1 );
413
            $h->set_allow_cformat( 1 );
412
            VerboseWarnings::set_input_file_name $input;
414
            VerboseWarnings::set_input_file_name $input;
413
        
414
            my $target = $out_dir . substr($input, length($in_dir));
415
            my $targetdir = $` if $target =~ /[^\/]+$/s;
416
            mkdir_recursive($targetdir) unless -d $targetdir;
415
            mkdir_recursive($targetdir) unless -d $targetdir;
417
            print STDERR "Creating $target...\n" unless $quiet;
416
            print STDERR "Creating $target...\n" unless $quiet;
418
            open( OUTPUT, ">$target" ) || die "$target: $!\n";            
417
            open( OUTPUT, ">$target" ) || die "$target: $!\n";
419
            text_replace( $h, *OUTPUT );
418
            text_replace( $h, *OUTPUT );
420
            close OUTPUT;
419
            close OUTPUT;
421
        } else {
420
        } else {
422
        # just copying the file
421
        # just copying the file
423
            my $target = $out_dir . substr($input, length($in_dir));
424
            my $targetdir = $` if $target =~ /[^\/]+$/s;
425
            mkdir_recursive($targetdir) unless -d $targetdir;
422
            mkdir_recursive($targetdir) unless -d $targetdir;
426
            system("cp -f $input $target");
423
            system("cp -f $input $target");
427
            print STDERR "Copying $input...\n" unless $quiet;
424
            print STDERR "Copying $input...\n" unless $quiet;
(-)a/misc/translator/translate (-4 / +9 lines)
Lines 30-38 use Pod::Usage; Link Here
30
my $verbose     = 0;
30
my $verbose     = 0;
31
my $pref        = 0;
31
my $pref        = 0;
32
my $all         = 0;
32
my $all         = 0;
33
my @files;
33
GetOptions(
34
GetOptions(
34
    'v|verbose' => \$verbose,
35
    'v|verbose' => \$verbose,
35
    'p'         => \$pref,
36
    'p'         => \$pref,
37
    'f:s'       => \@files,
36
    'a|all'     => \$all,
38
    'a|all'     => \$all,
37
);
39
);
38
40
Lines 57-67 if ( $cmd =~ /create|install|update/ ) { Link Here
57
        usage() if $cmd eq 'create';
59
        usage() if $cmd eq 'create';
58
        for my $lang ( @{$installer->{langs}} ) {
60
        for my $lang ( @{$installer->{langs}} ) {
59
            $installer->set_lang( $lang );
61
            $installer->set_lang( $lang );
60
            $installer->$cmd();
62
            $installer->$cmd(\@files);
61
        }
63
        }
62
    }
64
    }
63
    else {
65
    else {
64
        $installer->$cmd();
66
        $installer->$cmd(\@files);
65
    }
67
    }
66
}
68
}
67
else {
69
else {
Lines 79-84 translate - Handle templates and preferences translation Link Here
79
  translate create fr-FR
81
  translate create fr-FR
80
  translate update fr-FR
82
  translate update fr-FR
81
  translate install fr-FR
83
  translate install fr-FR
84
  translate install fr-FR -f search -f memberentry
82
  translate -p install fr-FR
85
  translate -p install fr-FR
83
  translate install
86
  translate install
84
87
Lines 127-139 Update .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, all Link Here
127
available languages are updated. With -p option, only preferences .po file is
130
available languages are updated. With -p option, only preferences .po file is
128
updated.
131
updated.
129
132
130
=item translate [-p] install F<lang>
133
=item translate [-p|-f] install F<lang>
131
134
132
Use .po files to translate the english version of templates and preferences files
135
Use .po files to translate the english version of templates and preferences files
133
and copy those files in the appropriate directory. Without F<lang>, all
136
and copy those files in the appropriate directory. Without F<lang>, all
134
available languages are installed. With -p option, only preferences .po file is
137
available languages are installed. With -p option, only preferences .po file is
135
updated.
138
updated.
136
139
140
With -f parameter (repeatable) you can specify specific files to translate. For
141
example, -f search will translate all templates containing 'search'.
142
137
=back
143
=back
138
144
139
=cut
145
=cut
140
- 

Return to bug 9161