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

(-)a/misc/translator/LangInstaller.pm (-2 / +3 lines)
Lines 34-39 use File::Spec; Link Here
34
use File::Temp qw( tempdir tempfile );
34
use File::Temp qw( tempdir tempfile );
35
use Template::Parser;
35
use Template::Parser;
36
use PPI;
36
use PPI;
37
use Encode qw( encode_utf8 );
37
38
38
39
39
$YAML::Syck::ImplicitTyping = 1;
40
$YAML::Syck::ImplicitTyping = 1;
Lines 830-836 sub extract_messages_from_templates { Link Here
830
            File::Spec->catfile($tempdir, 'koha-tmpl', 'opac-tmpl', $file);
831
            File::Spec->catfile($tempdir, 'koha-tmpl', 'opac-tmpl', $file);
831
832
832
        make_path(dirname($destfile));
833
        make_path(dirname($destfile));
833
        open my $fh, '>', $destfile;
834
        open my $fh, '>:encoding(utf-8)', $destfile;
834
835
835
        my @blocks = ($data->{BLOCK}, values %{ $data->{DEFBLOCKS} });
836
        my @blocks = ($data->{BLOCK}, values %{ $data->{DEFBLOCKS} });
836
        foreach my $block (@blocks) {
837
        foreach my $block (@blocks) {
Lines 880-886 sub extract_messages_from_templates { Link Here
880
                push @required_args, shift @args if $keyword =~ /n/;
881
                push @required_args, shift @args if $keyword =~ /n/;
881
                push @required_args, shift @args if $keyword =~ /p/;
882
                push @required_args, shift @args if $keyword =~ /p/;
882
883
883
                say $fh "$keyword(" . join(', ', @required_args) . ");";
884
                say $fh encode_utf8 "$keyword(" . join(', ', @required_args) . ");";
884
            }
885
            }
885
886
886
        }
887
        }
(-)a/misc/translator/tmpl_process3.pl (-19 / +19 lines)
Lines 22-27 use Locale::PO; Link Here
22
use File::Temp qw( :POSIX );
22
use File::Temp qw( :POSIX );
23
use TmplTokenizer;
23
use TmplTokenizer;
24
use VerboseWarnings qw( :warn :die );
24
use VerboseWarnings qw( :warn :die );
25
use Encode qw( encode_utf8 );
25
26
26
###############################################################################
27
###############################################################################
27
28
Lines 127-153 sub text_replace (**) { Link Here
127
        print $output find_translation($t);
128
        print $output find_translation($t);
128
    } elsif ($kind eq C4::TmplTokenType::TEXT_PARAMETRIZED) {
129
    } elsif ($kind eq C4::TmplTokenType::TEXT_PARAMETRIZED) {
129
        my $fmt = find_translation($s->form);
130
        my $fmt = find_translation($s->form);
130
        print $output TmplTokenizer::parametrize($fmt, 1, $s, sub {
131
        print $output encode_utf8 TmplTokenizer::parametrize($fmt, 1, $s, sub {
131
        $_ = $_[0];
132
        $_ = $_[0];
132
        my($kind, $t, $attr) = ($_->type, $_->string, $_->attributes);
133
        my($kind, $t, $attr) = ($_->type, $_->string, $_->attributes);
133
        $kind == C4::TmplTokenType::TAG && %$attr?
134
        $kind == C4::TmplTokenType::TAG && %$attr?
134
            text_replace_tag($t, $attr): $t });
135
            text_replace_tag($t, $attr): $t });
135
    } elsif ($kind eq C4::TmplTokenType::TAG && %$attr) {
136
    } elsif ($kind eq C4::TmplTokenType::TAG && %$attr) {
136
        print $output text_replace_tag($t, $attr);
137
        print $output encode_utf8(text_replace_tag($t, $attr));
137
    } elsif ($s->has_js_data) {
138
    } elsif ($s->has_js_data) {
138
        for my $t (@{$s->js_data}) {
139
        for my $t (@{$s->js_data}) {
139
        # FIXME for this whole block
140
        # FIXME for this whole block
140
        if ($t->[0]) {
141
        if ($t->[0]) {
141
            printf $output "%s%s%s", $t->[2], find_translation $t->[3],
142
            printf $output "%s%s%s", encode_utf8($t->[2]), encode_utf8(find_translation $t->[3]),
142
                $t->[2];
143
                encode_utf8($t->[2]);
143
        } else {
144
        } else {
144
            print $output $t->[1];
145
            print $output encode_utf8($t->[1]);
145
        }
146
        }
146
        }
147
        }
147
    } elsif (defined $t) {
148
    } elsif (defined $t) {
148
        # Quick fix to bug 4472
149
        # Quick fix to bug 4472
149
        $t = "<!DOCTYPE stylesheet ["  if $t =~ /DOCTYPE stylesheet/ ;
150
        $t = "<!DOCTYPE stylesheet ["  if $t =~ /DOCTYPE stylesheet/ ;
150
        print $output $t;
151
        print $output encode_utf8($t);
151
    }
152
    }
152
    }
153
    }
153
}
154
}
Lines 377-390 if ($action eq 'create') { Link Here
377
    # FIXME: need to check the return value
378
    # FIXME: need to check the return value
378
    unless (-f $str_file) {
379
    unless (-f $str_file) {
379
        local(*INPUT, *OUTPUT);
380
        local(*INPUT, *OUTPUT);
380
        open(INPUT, "<$tmpfile2");
381
        open(my $input_fh, '<:encoding(utf-8)', $tmpfile2);
381
        open(OUTPUT, ">$str_file");
382
        open(my $output_fh, '>:encoding(utf-8)', $str_file);
382
        while (<INPUT>) {
383
        while (<$input_fh>) {
383
        print OUTPUT;
384
            print encode_utf8 $output_fh;
384
        last if /^\n/s;
385
            last if /^\n/s;
385
        }
386
        }
386
        close INPUT;
387
        close $input_fh;
387
        close OUTPUT;
388
        close $output_fh;
388
    }
389
    }
389
    $st = system("msgmerge ".($quiet?'-q':'')." -s $str_file $tmpfile2 -o - | msgattrib --no-obsolete -o $str_file");
390
    $st = system("msgmerge ".($quiet?'-q':'')." -s $str_file $tmpfile2 -o - | msgattrib --no-obsolete -o $str_file");
390
    } else {
391
    } else {
Lines 448-455 if ($action eq 'create') { Link Here
448
    -d $out_dir || die "$out_dir: The directory does not exist\n";
449
    -d $out_dir || die "$out_dir: The directory does not exist\n";
449
450
450
    # Try to open the file, because Locale::PO doesn't check :-/
451
    # Try to open the file, because Locale::PO doesn't check :-/
451
    open(INPUT, "<$str_file") || die "$str_file: $!\n";
452
    open(my $input_fh, '<:encoding(utf-8)', $str_file) || die "$str_file: $!\n";
452
    close INPUT;
453
    close $input_fh;
453
454
454
    # creates the new tmpl file using the new translation
455
    # creates the new tmpl file using the new translation
455
    for my $input (@in_files) {
456
    for my $input (@in_files) {
Lines 465-473 if ($action eq 'create') { Link Here
465
            VerboseWarnings::set_input_file_name $input;
466
            VerboseWarnings::set_input_file_name $input;
466
            mkdir_recursive($targetdir) unless -d $targetdir;
467
            mkdir_recursive($targetdir) unless -d $targetdir;
467
            print STDERR "Creating $target...\n" unless $quiet;
468
            print STDERR "Creating $target...\n" unless $quiet;
468
            open( OUTPUT, ">$target" ) || die "$target: $!\n";
469
            open( my $output_fh, '>encoding(utf-8)' ) || die "$target: $!\n";
469
            text_replace( $h, *OUTPUT );
470
            text_replace( $h, *$output_fh);
470
            close OUTPUT;
471
            close $output_fh;
471
        } else {
472
        } else {
472
        # just copying the file
473
        # just copying the file
473
            mkdir_recursive($targetdir) unless -d $targetdir;
474
            mkdir_recursive($targetdir) unless -d $targetdir;
474
- 

Return to bug 25501