From: Frank Lichtenheld Date: Tue, 5 Feb 2008 21:15:59 +0000 (+0100) Subject: Separate handling of po translations and DDTP translations X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=ca605dba77e7901e6b99a59fe8d8a9de776614b7;p=deb%2Fpackages.git Separate handling of po translations and DDTP translations This way we don't need to immediatly fall back to English if people have more than one preferred language for which only part of the page content is available. If e.g. they would have "ca;q=0.9, de;q=0.5, en;q=0.1" in their Accept-Language header (insert any DDTP-only language for ca and any PO-available language for de), we can show the description in Catalan if available, and the po contents in German. The code will usually try to fall back to $po_lang if a description is not available in $ddtp_lang. Not implemented (yet) is a DDTP language negotiation _after_ we actually know which DDTP translations are available. The 'lang' query parameter overrides both values and has only the fallback English (But you shouldn't use it anyway ;). --- diff --git a/bin/create_index_pages b/bin/create_index_pages index 4e09430..05123e7 100755 --- a/bin/create_index_pages +++ b/bin/create_index_pages @@ -60,7 +60,8 @@ foreach my $s (@SUITES) { print "writing $key/index (lang=$lang)...\n"; my %content = ( subsections => [], suite => $s, - lang => $lang, charset => $charset, cat => $cat, + po_lang => $lang, ddtp_lang => $lang, + charset => $charset, cat => $cat, used_langs => \@LANGUAGES, suites => \@SUITES ); foreach my $ssec (sort (keys %{$subsections->{$s}}, 'virtual')) { next if $ssec eq '-'; @@ -200,7 +201,8 @@ sub write_files { my $cat = Packages::I18N::Locale->get_handle($lang) or die "get_handle failed for $lang"; - my %lang_vars = ( lang => $lang, charset => $charset, + my %lang_vars = ( po_lang => $lang, ddtp_lang => $lang, + charset => $charset, cat => $cat, used_langs => \@LANGUAGES ); print "writing $source$s/allpackages (lang=$lang)...\n"; $template->page( 'index', { %lang_vars, packages => $pkgs->{$key}, diff --git a/lib/Packages/Dispatcher.pm b/lib/Packages/Dispatcher.pm index e6a9d52..9f844f2 100755 --- a/lib/Packages/Dispatcher.pm +++ b/lib/Packages/Dispatcher.pm @@ -1,7 +1,7 @@ #!/usr/bin/perl -T # Packages::Dispatcher -- CGI interface for packages.debian.org # -# Copyright (C) 2004-2007 Frank Lichtenheld +# Copyright (C) 2004-2008 Frank Lichtenheld # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -92,14 +92,16 @@ sub do_dispatch { &Packages::Config::init( $homedir ); &Packages::DB::init(); - my $acc = I18N::AcceptLanguage->new(); - my %all_langs = map { $_ => 1 } (@LANGUAGES, @DDTP_LANGUAGES); - my @all_langs = sort keys %all_langs; - my $http_lang = $acc->accepts( $input->http("Accept-Language"), - \@all_langs ) || 'en'; - debug( "LANGUAGES=@all_langs header=". + my %PO_LANGUAGES = map { $_ => 1 } @LANGUAGES; + my %DDTP_LANGUAGES = map { $_ => 1 } @DDTP_LANGUAGES; + my $acc = I18N::AcceptLanguage->new(defaultLanguage => 'en'); + my $ddtp_lang = $acc->accepts( $input->http("Accept-Language"), + \@DDTP_LANGUAGES ); + my $po_lang = $acc->accepts( $input->http("Accept-Language"), + \@LANGUAGES ); + debug( "LANGS=@LANGUAGES DDTP_LANGS=@DDTP_LANGUAGES header=". ($input->http("Accept-Language")||''). - " http_lang=$http_lang", 1 ) if DEBUG; + " po_lang=$po_lang ddtp_lang=$ddtp_lang", 1 ) if DEBUG; # backwards compatibility stuff debug( "SCRIPT_URL=$ENV{SCRIPT_URL} SCRIPT_URI=$ENV{SCRIPT_URI}" ) if DEBUG; @@ -141,7 +143,7 @@ sub do_dispatch { push @components, 'index' if @components && $path =~ m,/$,; - my %LANGUAGES = map { $_ => 1 } @all_langs; + my %LANGUAGES = map { $_ => 1 } (@LANGUAGES, @DDTP_LANGUAGES); if (@components > 1 and $LANGUAGES{$components[0]} and !$input->param('lang')) { $input->param( 'lang', shift(@components) ); @@ -247,7 +249,7 @@ sub do_dispatch { replace => { all => \@ARCHIVES, default => \@ARCHIVES} }, exact => { default => 0, match => '^(\w+)$', }, - lang => { default => $http_lang, match => '^([\w-]+)$', }, + lang => { default => undef, match => '^([\w-]+)$', }, source => { default => 0, match => '^(\d+)$', }, debug => { default => 0, match => '^(\d+)$', }, searchon => { default => 'names', match => '^(\w+)$', }, @@ -272,9 +274,16 @@ sub do_dispatch { my %params = Packages::CGI::parse_params( $input, \%params_def, \%opts ); Packages::CGI::init_url( $input, \%params, \%opts ); + if (defined($opts{lang})) { + $opts{po_lang} = $PO_LANGUAGES{$opts{lang}} ? $opts{lang} : 'en'; + $opts{ddtp_lang} = $DDTP_LANGUAGES{$opts{lang}} ? $opts{lang} : 'en'; + } else { + $opts{po_lang} = $po_lang; + $opts{ddtp_lang} = $ddtp_lang; + } my $charset = "UTF-8"; - my $cat = Packages::I18N::Locale->get_handle( $opts{lang}, "en" ) - or die "get_handle failed for $opts{lang}"; + my $cat = Packages::I18N::Locale->get_handle( $opts{po_lang}, 'en' ) + or die "get_handle failed for $opts{po_lang}"; $opts{cat} = $cat; $opts{h_suites} = { map { $_ => 1 } @suites }; @@ -299,8 +308,8 @@ sub do_dispatch { debug( "Parameter evaluation took ".timestr($petd) ) if DEBUG; my $template = new Packages::Template( $TEMPLATEDIR, $opts{format}, - { lang => $opts{lang}, charset => $charset, - cat => $cat, + { po_lang => $opts{po_lang}, ddtp_lang => $opts{ddtp_lang}, + charset => $charset, cat => $cat, debug => ( DEBUG ? $opts{debug} : 0 ) }, ( $CACHEDIR ? { COMPILE_DIR => $CACHEDIR } : {} ) ); diff --git a/lib/Packages/DoIndex.pm b/lib/Packages/DoIndex.pm index a0cae2b..3129b0b 100644 --- a/lib/Packages/DoIndex.pm +++ b/lib/Packages/DoIndex.pm @@ -46,12 +46,7 @@ sub send_file { $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1; $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}}; $path .= "$opts->{priority}[0]/" if @{$opts->{priority}}; - - #FIXME: ugly hack - if ($opts->{lang} ne 'en' and !-f "$wwwdir/$path$file.$opts->{lang}.$opts->{format}") { - $opts->{lang} = 'en'; - } - $path .= "$file.$opts->{lang}.$opts->{format}"; + $path .= "$file.$opts->{po_lang}.$opts->{format}"; unless (@Packages::CGI::fatal_errors) { my $buffer; diff --git a/lib/Packages/Template.pm b/lib/Packages/Template.pm index a3268a3..c2919f1 100644 --- a/lib/Packages/Template.pm +++ b/lib/Packages/Template.pm @@ -85,8 +85,10 @@ sub page { 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', + $page_content->{langs} = languages( $page_content->{po_lang} + || $self->{vars}{po_lang} || 'en', + $page_content->{ddtp_lang} + || $self->{vars}{ddtp_lang} || 'en', @{$page_content->{used_langs}} ); my $txt; @@ -114,17 +116,17 @@ sub error_page { } sub languages { - my ( $lang, @used_langs ) = @_; - my $cat = Packages::I18N::Locale->get_handle($lang) - || Packages::I18N::Locale->get_handle('en'); + my ( $po_lang, $ddtp_lang, @used_langs ) = @_; + my $cat = Packages::I18N::Locale->get_handle($po_lang, 'en'); my @langs; + my $skip_lang = ($po_lang eq $ddtp_lang) ? $po_lang : ''; if (@used_langs) { my @printed_langs = (); foreach (@used_langs) { - next if $_ eq $lang; # Never print the current language + next if $_ eq $skip_lang; # Don't print the current language unless (get_selfname($_)) { warn "missing language $_"; next } #DEBUG push @printed_langs, $_; } diff --git a/templates/config.tmpl b/templates/config.tmpl index 1fee16b..c99694e 100644 --- a/templates/config.tmpl +++ b/templates/config.tmpl @@ -1,6 +1,7 @@ [%- DEFAULT charset = 'UTF-8' - lang = 'en' + po_lang = 'en' + ddtp_lang = 'en' organisation = 'Debian' homepage = 'http://www.debian.org/' diff --git a/templates/html/head.tmpl b/templates/html/head.tmpl index 362a32e..866641c 100644 --- a/templates/html/head.tmpl +++ b/templates/html/head.tmpl @@ -1,5 +1,5 @@ - + [% organisation %] -- [% title_tag %] diff --git a/templates/html/index.tmpl b/templates/html/index.tmpl index cc20983..cac305c 100644 --- a/templates/html/index.tmpl +++ b/templates/html/index.tmpl @@ -33,8 +33,10 @@ [% PROCESS marker text=p.section IF p.section != main_section %] [% PROCESS marker text=p.archive IF p.archive != main_archive %] [% END %] - [%- IF p.trans_desc.$lang; - sdesc = p.trans_desc.$lang; + [%- desclang = 'en'; + IF p.trans_desc.$ddtp_lang; + sdesc = p.trans_desc.$ddtp_lang; + desclang = $ddtp_lang; ELSE; sdesc = p.desc; END -%] @@ -45,11 +47,11 @@ [%- ', ' UNLESS loop.last %][% END %] [% IF p.versions.length %]
[% p.name %] ([% p.versions %])[% PROCESS markers %]
-
[% sdesc | html %]
+
[% sdesc | html %]
[% END %] [% ELSE %]
[% p.name %] ([% p.versions %])[% PROCESS markers %]
-
[% sdesc | html %]
+
[% sdesc | html %]
[% END %] [% '' IF loop.last %] diff --git a/templates/html/search.tmpl b/templates/html/search.tmpl index 452e80b..41ca369 100644 --- a/templates/html/search.tmpl +++ b/templates/html/search.tmpl @@ -27,6 +27,7 @@ } navigation = [ { name => g('Package Search Results') } ] -%] +[%- PROCESS 'html/util.inc' -%]
[% UNLESS results %] @@ -119,7 +120,9 @@ [% FOREACH s IN suites; suite = s.suite %]
  • [% suite %] - [%- ' (' _ suite_aliases.$suite _ ')' IF suite_aliases.$suite %][% ' (' _ s.subsection _ ')' IF s.subsection %]: [% IF s.trans_desc.$lang; s.trans_desc.$lang | html; ELSE; s.desc | html; END %] [%- IF s.section && s.section != main_section %] [[% s.section %]][% END %] + [%- ' (' _ suite_aliases.$suite _ ')' IF suite_aliases.$suite %][% ' (' _ s.subsection _ ')' IF s.subsection %]: + [% PROCESS desc_i18n trans_desc=s.trans_desc desc=s.desc %] + [%- PROCESS marker text=s.section IF s.section && s.section != main_section %] [% FOREACH s.versions %]
    [% version %] [%- IF archive != main_archive %] [[% archive %]][% END %]: [% architectures.join(' ') %] [% END %] @@ -139,8 +142,7 @@ [% origin = (archive == main_archive) ? suite : "$suite/$archive"; js_id = string2id("$pkg$suite$archive") %]
  • [% origin %] ([% subsection %]): [% version %] - [%- IF section %] [[% section %]][% END %] - [%- IF real_archive %] [[% real_archive %]][% END %] + [%- PROCESS marker text=section IF section %] [%- PROCESS marker text=real_archive IF real_archive %]
    [% g('Binary packages:') %] [% FOREACH binary IN binaries.sort %][% binary %][% ', ' UNLESS loop.last %][% END %] [% IF binaries.size > 10 %] diff --git a/templates/html/show.tmpl b/templates/html/show.tmpl index ff589b9..048b7d0 100644 --- a/templates/html/show.tmpl +++ b/templates/html/show.tmpl @@ -16,7 +16,8 @@ nav_arr.push( { prefix=>g('Section:'), title=>g('All packages in this section'), url=>make_url("$subsection/"), name=>subsection } ); nav_arr.push( { prefix=>g('Package:'), name=>pkg } ); -%] [% desclang = 'en'; - SET desclang = lang IF desc.$lang.long %] + SET desclang = po_lang IF desc.$po_lang.long; + SET desclang = ddtp_lang IF desc.$ddtp_lang.long %] [%- PROCESS 'html/head.tmpl' title_tag = is_source ? g('Details of source package %s in %s', pkg, suite) : g('Details of package %s in %s', pkg, suite) @@ -166,13 +167,14 @@ [% IF desc %]
    -
    [% UNLESS is_virtual %] +
    [% IF desc.$desclang.short %]

    [% desc.$desclang.short %]

    [% desc.$desclang.long %] [% END %] [% ELSE %] +

    [% g('This is a virtual package. See the Debian policy for a definition of virtual packages.', policy_url, policy_url) %]

    [% END %] @@ -183,10 +185,10 @@

    [% g('Tags') %]: [%- END %] - [% facet = tag.0; lfacet = "$facet-$lang"; + [% facet = tag.0; lfacet = "$facet-$po_lang"; facet_name = debtags_voc.$lfacet; SET facet_name = debtags_voc.$facet UNLESS facet_name; - tag_id = "$tag.0::$tag.1"; ltag = "$tag_id-$lang"; + tag_id = "$tag.0::$tag.1"; ltag = "$tag_id-$po_lang"; tag_name = debtags_voc.$ltag; SET tag_name = debtags_voc.$tag_id UNLESS tag_name; %] @@ -206,7 +208,7 @@ [% FOREACH p IN providers %] [% IF loop.first %]

    [% g('Packages providing %s', pkg) %]

    [% END %]
    [% IF p.available %][% p.name %][% ELSE; p.name; END %]
    -
    [% IF p.trans_desc.$lang; p.trans_desc.$lang | html; ELSE; p.desc | html; END %]
    + [% PROCESS desc_i18n_dd trans_desc=p.trans_desc desc=p.desc %] [% '
    ' IF loop.last %] [% END %]
    @@ -215,7 +217,7 @@ [% FOREACH b IN binaries %] [% IF loop.first %]
    [% g('The following binary packages are built from this source package:') %]
    [% END %]
    [% IF b.available %][% b.name %][% ELSE; b.name; END %]
    -
    [% IF b.trans_desc.$lang; b.trans_desc.$lang | html; ELSE; b.desc | html; END %]
    + [% PROCESS desc_i18n_dd trans_desc=b.trans_desc desc=b.desc %] [% '
    ' IF loop.last %] [% END %] @@ -246,7 +248,7 @@ [% ' (' _ version _ ')' IF version %] [% ' [' _ arch_str _ ']' IF arch_str %] [%- IF !is_old_pkgs -%] -
    [% IF trans_desc.$lang; trans_desc.$lang | html; ELSE; desc | html; END -%] + [% PROCESS desc_i18n_dd no_end_tag=1 trans_desc=trans_desc desc=desc -%] [%- IF providers.pkgs.size > 0 -%] [% IF providers.also; '
    ' _ g('also a virtual package provided by'); diff --git a/templates/html/util.inc b/templates/html/util.inc index aa9c43d..731b8ae 100644 --- a/templates/html/util.inc +++ b/templates/html/util.inc @@ -8,3 +8,25 @@  ] [%- END -%] [% BLOCK marker %] [[% text %]] [%- END %] +[%- BLOCK desc_i18n; + IF trans_desc.$ddtp_lang; + trans_desc.$ddtp_lang | html; + ELSIF trans_desc.$po_lang; + trans_desc.$po_lang | html; + ELSE; + desc | html; + END; +END -%] +[%- BLOCK desc_i18n_dd; + IF trans_desc.$ddtp_lang; + '
    '; + trans_desc.$ddtp_lang | html; + ELSIF trans_desc.$po_lang; + '
    '; + trans_desc.$po_lang | html; + ELSE; + '
    '; + desc | html; + END; + '
    ' UNLESS no_end_tag; +END -%] diff --git a/templates/rss/newpkg.tmpl b/templates/rss/newpkg.tmpl index c95ee53..378cca3 100644 --- a/templates/rss/newpkg.tmpl +++ b/templates/rss/newpkg.tmpl @@ -24,7 +24,7 @@ suite, organisation); END; -%] -[% lang %] +[% po_lang %] [% g('Copyright ©') %] [% timestamp.year %], [% copyright.name %] [% rss_timestamp %] [% contact.mail %]