X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=misc%2Ftranslator%2Fxgettext.pl;h=4e0c05f1e76655b34606486d607c4869f6846307;hb=3fcc028ed827962f2d9344d20251bc4941a4be21;hp=11a4f15bccd5e68079cd278f2a7f7cbb9432e1a9;hpb=10a00d1b5004b19d89650b141c0bd783b699dbde;p=koha.git diff --git a/misc/translator/xgettext.pl b/misc/translator/xgettext.pl index 11a4f15bcc..4e0c05f1e7 100755 --- a/misc/translator/xgettext.pl +++ b/misc/translator/xgettext.pl @@ -8,6 +8,7 @@ xgettext.pl - xgettext(1)-like interface for .tmpl strings extraction use strict; use Getopt::Long; +use POSIX; use Locale::PO; use TmplTokenizer; use VerboseWarnings; @@ -18,6 +19,9 @@ use vars qw( $extract_all_p ); use vars qw( $pedantic_p ); use vars qw( %text %translation ); use vars qw( $charset_in $charset_out ); +use vars qw( $disable_fuzzy_p ); +use vars qw( $verbose_p ); +use vars qw( $po_mode_p ); ############################################################################### @@ -55,8 +59,9 @@ sub remember ($$) { my($token, $string) = @_; # If we determine that the string is negligible, don't bother to remember unless (string_negligible_p( $string ) || token_negligible_p( $token )) { - $text{$string} = [] unless defined $text{$string}; - push @{$text{$string}}, $token; + my $key = TmplTokenizer::string_canon( $string ); + $text{$key} = [] unless defined $text{$key}; + push @{$text{$key}}, $token; } } @@ -111,7 +116,7 @@ sub text_extract (*) { sub generate_strings_list () { # Emit all extracted strings. for my $t (string_list) { - printf OUTPUT "%s\n", $t # unless negligible_p($t); + printf OUTPUT "%s\n", $t; } } @@ -121,18 +126,26 @@ sub generate_po_file () { # We don't emit the Plural-Forms header; it's meaningless for us my $pot_charset = (defined $charset_out? $charset_out: 'CHARSET'); $pot_charset = TmplTokenizer::charset_canon $pot_charset; + # Time stamps aren't exactly right semantically. I don't know how to fix it. + my $time = POSIX::strftime('%Y-%m-%d %H:%M%z', localtime(time)); + my $time_pot = $time; + my $time_po = $po_mode_p? $time: 'YEAR-MO-DA HO:MI+ZONE'; print OUTPUT <, YEAR. # +EOF + print OUTPUT <\\n" "Language-Team: LANGUAGE \\n" "MIME-Version: 1.0\\n" @@ -142,7 +155,50 @@ msgstr "" EOF my $directory_re = quotemeta("$directory/"); for my $t (string_list) { - #next if negligible_p($t); + if ($text{$t}->[0]->type == TmplTokenType::TEXT_PARAMETRIZED) { + my($token, $n) = ($text{$t}->[0], 0); + printf OUTPUT "#. For the first occurrence,\n" + if @{$text{$t}} > 1 && $token->parameters_and_fields > 0; + for my $param ($token->parameters_and_fields) { + $n += 1; + my $type = $param->type; + my $subtype = ($type == TmplTokenType::TAG + && $param->string =~ /^attributes->{'type'}->[1]: undef); + my $fmt = TmplTokenizer::_formalize( $param ); + $fmt =~ s/^%/%$n\$/; + if ($type == TmplTokenType::DIRECTIVE) { + $type = $param->string =~ /(TMPL_[A-Z]+)+/is? $1: 'ERROR'; + my $name = $param->string =~ /\bname=(["']?)([^\s"']+)\1/is? + $2: undef; + printf OUTPUT "#. %s: %s\n", $fmt, + "$type" . (defined $name? " name=$name": ''); + } else { + my $name = $param->attributes->{'name'}; + my $value = $param->attributes->{'value'} + unless $subtype =~ /^(?:text)$/; + printf OUTPUT "#. %s: %s\n", $fmt, "type=$subtype" + . (defined $name? " name=$name->[1]": '') + . (defined $value? " value=$value->[1]": ''); + } + } + } elsif ($text{$t}->[0]->type == TmplTokenType::TAG) { + my($token) = ($text{$t}->[0]); + printf OUTPUT "#. For the first occurrence,\n" + if @{$text{$t}} > 1 && $token->parameters_and_fields > 0; + if ($token->string =~ /^attributes->{'http-equiv'}->[1]; + print OUTPUT "#. META http-equiv=$type\n" if defined $type; + } elsif ($token->string =~ /^<([a-z0-9]+)/is) { + my $tag = uc($1); + my $type = (lc($tag) eq 'input'? + $token->attributes->{'type'}: undef); + my $name = $token->attributes->{'name'}; + printf OUTPUT "#. %s\n", $tag + . (defined $type? " type=$type->[1]": '') + . (defined $name? " name=$name->[1]": ''); + } + } my $cformat_p; for my $token (@{$text{$t}}) { my $pathname = $token->pathname; @@ -153,6 +209,7 @@ EOF } printf OUTPUT "#, c-format\n" if $cformat_p; printf OUTPUT "msgid %s\n", TmplTokenizer::quote_po + TmplTokenizer::string_canon TmplTokenizer::charset_convert $t, $charset_in, $charset_out; printf OUTPUT "msgstr %s\n\n", (defined $translation{$t}? TmplTokenizer::quote_po( $translation{$t} ): "\"\""); @@ -218,14 +275,17 @@ Output file location: HTML::Template options: -a, --extract-all Extract all strings --pedantic-warnings Issue warnings even for detected problems - which are likely to be harmless + which are likely to be harmless Output details: -s, --sort-output generate sorted output -F, --sort-by-file sort output by file location + -v, --verbose explain what is being done Informative output: --help Display this help and exit + +Try `perldoc $0' for perhaps more information. EOF exit($exitcode); } @@ -246,13 +306,16 @@ GetOptions( 'charset=s' => sub { $charset_in = $charset_out = $_[1] }, # INTERNAL 'convert-from=s' => \$convert_from, 'D|directory=s' => \$directory, + 'disable-fuzzy' => \$disable_fuzzy_p, # INTERNAL 'f|files-from=s' => \$files_from, 'I|input-charset=s' => \$charset_in, # INTERNAL 'pedantic-warnings|pedantic' => sub { $pedantic_p = 1 }, 'O|output-charset=s' => \$charset_out, # INTERNAL 'output|o=s' => \$output, + 'po-mode' => \$po_mode_p, # INTERNAL 's|sort-output' => sub { $sort = 's' }, 'F|sort-by-file' => sub { $sort = 'F' }, + 'v|verbose' => \$verbose_p, 'help' => sub { usage(0) }, ) || usage_error; @@ -267,22 +330,28 @@ usage_error('You cannot specify both --convert-from and --files-from') if defined $convert_from && defined $files_from; if (defined $output && $output ne '-') { + print STDERR "$0: Opening output file \"$output\"\n" if $verbose_p; open(OUTPUT, ">$output") || die "$output: $!\n"; } else { + print STDERR "$0: Outputting to STDOUT...\n" if $verbose_p; open(OUTPUT, ">&STDOUT"); } if (defined $files_from) { + print STDERR "$0: Opening input file list \"$files_from\"\n" if $verbose_p; open(INPUT, "<$files_from") || die "$files_from: $!\n"; while () { chomp; - my $h = TmplTokenizer->new( "$directory/$_" ); + my $input = /^\//? $_: "$directory/$_"; + my $h = TmplTokenizer->new( $input ); $h->set_allow_cformat( 1 ); - VerboseWarnings::set_input_file_name "$directory/$_"; + VerboseWarnings::set_input_file_name $input; + print STDERR "$0: Processing file \"$input\"\n" if $verbose_p; text_extract( $h ); } close INPUT; } else { + print STDERR "$0: Converting \"$convert_from\"\n" if $verbose_p; convert_translation_file; } generate_po_file; @@ -340,9 +409,9 @@ details. If you want to generate GNOME-style POTFILES.in files, such files (passed to -f) can be generated thus: - (cd ../.. && find koha-tmpl/opac-tmpl/default/en + (cd ../.. && find koha-tmpl/opac-tmpl/default/en \ -name \*.inc -o -name \*.tmpl) > opac/POTFILES.in - (cd ../.. && find koha-tmpl/intranet-tmpl/default/en + (cd ../.. && find koha-tmpl/intranet-tmpl/default/en \ -name \*.inc -o -name \*.tmpl) > intranet/POTFILES.in This is, however, quite pointless, because the "create" and