From: Frank Lichtenheld Date: Sat, 17 Nov 2007 15:53:30 +0000 (+0100) Subject: Translation support for remaining scripts X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=92a6b3d4b5bcd96dfe05ee814722e5e0e47e1d3f;p=deb%2Fpackages.git Translation support for remaining scripts --- diff --git a/bin/create_index_pages b/bin/create_index_pages index eb797d3..973dff7 100755 --- a/bin/create_index_pages +++ b/bin/create_index_pages @@ -9,7 +9,6 @@ use DB_File; use Storable; use HTML::Entities; use URI::Escape; -use Locale::gettext; use Compress::Zlib; use lib './lib'; @@ -22,16 +21,6 @@ use Packages::SrcPage; use Packages::Sections; &Packages::Config::init( './' ); -delete $ENV{'LANGUAGE'}; -delete $ENV{'LANG'}; -delete $ENV{'LC_ALL'}; -delete $ENV{'LC_MESSAGES'}; -bindtextdomain ( 'pdo', $LOCALES ); -bindtextdomain ( 'templates', $LOCALES ); -bindtextdomain ( 'sections', $LOCALES ); -bindtextdomain ( 'langs', $LOCALES ); -textdomain( 'pdo' ); - my $wwwdir = "$TOPDIR/www"; tie my %packages, 'DB_File', "$DBDIR/packages_small.db", @@ -65,24 +54,21 @@ foreach my $s (@SUITES) { mkpath ( "$wwwdir/$key" ); mkpath ( "$wwwdir/source/$key" ); foreach my $lang (@LANGUAGES) { - my $locale = get_locale( $lang ); - my $charset = get_charset( $lang ); - setlocale ( LC_ALL, $locale ) or do { - warn "couldn't set locale ($lang/$locale)\n"; - next; - }; + my $charset = 'UTF-8'; + my $cat = Packages::I18N::Locale->get_handle($lang) + or die "get_handle failed for $lang"; print "writing $key/index (lang=$lang)...\n"; my %content = ( subsections => [], suite => $s, - lang => $lang, charset => $charset, + lang => $lang, charset => $charset, cat => $cat, used_langs => \@LANGUAGES, suites => \@SUITES ); foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) { next if $ssec eq '-'; if ($sections_descs{$ssec}) { push @{$content{subsections}}, { id => $ssec, - name => dgettext( 'sections', $sections_descs{$ssec}[0] ), - desc => dgettext( 'sections', $sections_descs{$ssec}[1] ), + name => $cat->g($sections_descs{$ssec}[0]), + desc => $cat->g($sections_descs{$ssec}[1]), }; } } @@ -100,7 +86,6 @@ foreach my $s (@SUITES) { } } -setlocale( LC_ALL, 'C' ) or die "couldn't reset locale"; print "collecting package info ...\n"; my %allpkgs; @@ -211,15 +196,12 @@ sub write_files { my $key = $s; mkpath ( "$wwwdir/$source$key" ); foreach my $lang (@LANGUAGES) { - my $locale = get_locale( $lang ); - my $charset = get_charset( $lang ); - setlocale ( LC_ALL, $locale ) or do { - warn "couldn't set locale ($lang/$locale)\n"; - next; - }; + my $charset = 'UTF-8'; + my $cat = Packages::I18N::Locale->get_handle($lang) + or die "get_handle failed for $lang"; my %lang_vars = ( lang => $lang, charset => $charset, - used_langs => \@LANGUAGES ); + cat => $cat, used_langs => \@LANGUAGES ); print "writing $source$s/allpackages (lang=$lang)...\n"; $template->page( 'index', { %lang_vars, packages => $pkgs->{$key}, suite => $s, is_source => $source }, @@ -247,7 +229,7 @@ sub write_files { print "writing $source$s/$sec/index (lang=$lang)...\n"; $template->page( 'index', { packages => [ grep { $_->{section} eq $sec } @{$pkgs->{$key}} ], %lang_vars, suite => $s, is_source => $source, - category => { id => _g('Section'), name => $sec } }, + category => { id => $cat->g('Section'), name => $sec } }, "$wwwdir/$source$key/$sec/index.$lang.html.new" ); rename( "$wwwdir/$source$key/$sec/index.$lang.html.new", "$wwwdir/$source$key/$sec/index.$lang.html" ); @@ -259,7 +241,7 @@ sub write_files { print "writing $source$s/$ssec/index (lang=$lang)...\n"; $template->page( 'index', { packages => [ grep { $_->{subsection} eq $ssec } @{$pkgs->{$key}} ], %lang_vars, suite => $s, is_source => $source, - category => { id => _g('Subsection'), name => $ssec } }, + category => { id => $cat->g('Subsection'), name => $ssec } }, "$wwwdir/$source$key/$ssec/index.$lang.html.new" ); rename( "$wwwdir/$source$key/$ssec/index.$lang.html.new", "$wwwdir/$source$key/$ssec/index.$lang.html" ); @@ -271,7 +253,7 @@ sub write_files { print "writing $source$s/$prio/index (lang=$lang)...\n"; $template->page( 'index', { packages => [ grep { $_->{priority} eq $prio } @{$pkgs->{$key}} ], %lang_vars, suite => $s, is_source => $source, - category => { id => _g('Priority'), name => $prio } }, + category => { id => $cat->g('Priority'), name => $prio } }, "$wwwdir/$source$key/$prio/index.$lang.html.new" ); rename( "$wwwdir/$source$key/$prio/index.$lang.html.new", "$wwwdir/$source$key/$prio/index.$lang.html" ); diff --git a/bin/parse-debtags-voc b/bin/parse-debtags-voc index 7e1453c..7ef06a0 100755 --- a/bin/parse-debtags-voc +++ b/bin/parse-debtags-voc @@ -28,7 +28,6 @@ use File::Path; use Data::Dumper; use HTML::Entities; use URI::Escape; -use Locale::gettext; use Deb::Versions; use Packages::Template; @@ -42,13 +41,6 @@ my (%voc, %voc_db); $/ = ""; -delete $ENV{'LANGUAGE'}; -delete $ENV{'LANG'}; -delete $ENV{'LC_ALL'}; -delete $ENV{'LC_MESSAGES'}; -bindtextdomain ( 'debtags', $LOCALES ); -textdomain( 'debtags' ); - sub process_desc { my ($desc) = @_; @@ -97,13 +89,12 @@ while () { $voc_db{$voc_key} = $sdesc || ""; foreach my $lang (@LANGUAGES) { - my $locale = get_locale( $lang ); - setlocale ( LC_ALL, $locale ) or do { - warn "couldn't set locale ($lang/$locale)\n"; - next; - }; + next if $lang eq 'en'; + + my $cat = Packages::I18N::Locale->get_handle($lang) + or die "get_handle failed for $lang"; - my $sdesc_trans = dgettext( 'debtags', $sdesc ); + my $sdesc_trans = $cat->maketext($sdesc); $voc_db{"$voc_key-$lang"} = $sdesc_trans if $sdesc_trans and $sdesc_trans ne $sdesc; } @@ -126,7 +117,7 @@ my @facets = sort( grep { exists $voc{$_}{facet} } keys %voc ); my @tags = sort( grep { exists $voc{$_}{tag} } keys %voc ); my %tags_by_facet; foreach (@tags) { - my ($facet, $tag) = split /::/, $_, 2; + my ($facet, $tag) = split m/::/, $_, 2; warn "No facet data available for $facet\n" unless exists $voc{$facet}; $tags_by_facet{$facet} ||= []; diff --git a/cron.d/500update_mo b/cron.d/500update_mo index 5855025..4bdc625 100755 --- a/cron.d/500update_mo +++ b/cron.d/500update_mo @@ -49,7 +49,7 @@ podomains="pdo templates sections langs debtags" # Update pot # # Common options for all calls -xgettext_opts="--language=Perl --keyword=N_ --keyword=_g --keyword=g --foreign-user --add-comments" +xgettext_opts="--language=Perl --keyword=N_ --keyword=g --foreign-user --add-comments" echo gettextfiles=$gettextfiles echo templatefiles=$templatefiles diff --git a/lib/Packages/Dispatcher.pm b/lib/Packages/Dispatcher.pm index ad4c8cb..e9b406f 100755 --- a/lib/Packages/Dispatcher.pm +++ b/lib/Packages/Dispatcher.pm @@ -30,7 +30,6 @@ use DB_File; use URI::Escape; use Benchmark ':hireswallclock'; use I18N::AcceptLanguage; -use Locale::gettext; use Deb::Versions; use Packages::Config qw( $DBDIR $ROOT $TEMPLATEDIR $CACHEDIR @@ -275,7 +274,8 @@ sub do_dispatch { my $charset = "UTF-8"; my $cat = Packages::I18N::Locale->get_handle( $opts{lang} ) - or die "get_handle failed"; + || Packages::I18N::Locale->get_handle( 'en' ); + die "get_handle failed for $opts{lang}" unless $cat; $opts{cat} = $cat; $opts{h_suites} = { map { $_ => 1 } @suites }; diff --git a/lib/Packages/DoIndex.pm b/lib/Packages/DoIndex.pm index 6d8d4b6..164e594 100644 --- a/lib/Packages/DoIndex.pm +++ b/lib/Packages/DoIndex.pm @@ -58,7 +58,7 @@ sub send_file { my $buffer; if (open( INDEX, '<', "$wwwdir/$path" )) { my %headers; - $headers{'-charset'} = get_charset( $opts->{lang} ); + $headers{'-charset'} = 'UTF-8'; $headers{'-type'} = get_mime( $opts->{format}, 'text/plain' ); $headers{'-content-encoding'} = $encoding{$opts->{format}} if exists $encoding{$opts->{format}}; my ($size,$mtime) = (stat("$wwwdir/$path"))[7,9]; diff --git a/lib/Packages/I18N/Locale.pm b/lib/Packages/I18N/Locale.pm index 8c27430..3b4ecc6 100644 --- a/lib/Packages/I18N/Locale.pm +++ b/lib/Packages/I18N/Locale.pm @@ -5,9 +5,16 @@ use warnings; use base 'Locale::Maketext'; use Locale::Maketext::Lexicon { + 'en' => [Gettext => '/home/djpig/debian/www.d.o/packages/po/pdo.pot', + Gettext => '/home/djpig/debian/www.d.o/packages/po/templates.pot', + Gettext => '/home/djpig/debian/www.d.o/packages/po/langs.pot', + Gettext => '/home/djpig/debian/www.d.o/packages/po/sections.pot', + Gettext => '/home/djpig/debian/www.d.o/packages/po/debtags.pot'], '*' => [Gettext => '/home/djpig/debian/www.d.o/packages/po/pdo.*.po', Gettext => '/home/djpig/debian/www.d.o/packages/po/templates.*.po', - Gettext => '/home/djpig/debian/www.d.o/packages/po/langs.*.po'], + Gettext => '/home/djpig/debian/www.d.o/packages/po/langs.*.po', + Gettext => '/home/djpig/debian/www.d.o/packages/po/sections.*.po', + Gettext => '/home/djpig/debian/www.d.o/packages/po/debtags.*.po'], _auto => 1, _style => 'gettext', }; diff --git a/lib/Packages/SrcPage.pm b/lib/Packages/SrcPage.pm index 7fc0e27..62d96d0 100644 --- a/lib/Packages/SrcPage.pm +++ b/lib/Packages/SrcPage.pm @@ -4,7 +4,6 @@ use strict; use warnings; use Data::Dumper; -use Locale::gettext; use Deb::Versions; use Packages::CGI; use Packages::Page qw( :all ); diff --git a/lib/Packages/Template.pm b/lib/Packages/Template.pm index 6ae96b4..28d8d1e 100644 --- a/lib/Packages/Template.pm +++ b/lib/Packages/Template.pm @@ -4,7 +4,6 @@ use strict; use warnings; use Template; -use Locale::gettext; use URI (); use HTML::Entities (); use URI::Escape (); @@ -77,6 +76,10 @@ sub page { #use Data::Dumper; #die Dumper($self, $action, $page_content); + if ($page_content->{cat}) { + $page_content->{g} = + sub { return Packages::I18N::Locale::g($page_content->{cat}, @_) }; + } $page_content->{used_langs} ||= \@LANGUAGES; $page_content->{langs} = languages( $page_content->{lang} || $self->{vars}{lang} || 'en', @@ -108,11 +111,13 @@ sub error_page { sub languages { my ( $lang, @used_langs ) = @_; - + my $cat = Packages::I18N::Locale->get_handle($lang) + || Packages::I18N::Locale->get_handle('en'); + my @langs; if (@used_langs) { - + my @printed_langs = (); foreach (@used_langs) { next if $_ eq $lang; # Never print the current language @@ -125,13 +130,14 @@ sub languages { foreach my $cur_lang (sort langcmp @printed_langs) { my %lang; $lang{lang} = $cur_lang; - $lang{tooltip} = dgettext( "langs", get_language_name($cur_lang) ); - $lang{selfname} = get_selfname($cur_lang); - $lang{transliteration} = get_transliteration($cur_lang) if defined get_transliteration($cur_lang); + $lang{tooltip} = $cat->g(get_language_name($cur_lang)); + $lang{selfname} = get_selfname($cur_lang); + $lang{transliteration} = get_transliteration($cur_lang) + if defined get_transliteration($cur_lang); push @langs, \%lang; } } - + return \@langs; }