Группа :: Сети/WWW
Пакет: bugzilla
Главная Изменения Спек Патчи Загрузить Bugs and FR
Патч: bugzilla-add-lang-switch-2.16.8.patch
diff -uNrd bugzilla-2.16.8.orig/CGI.pl bugzilla-2.16.8/CGI.pl
--- bugzilla-2.16.8.orig/CGI.pl 2005-01-04 00:02:10 +0300
+++ bugzilla-2.16.8/CGI.pl 2005-01-26 16:33:38 +0300
@@ -52,7 +52,7 @@
require 'globals.pl';
-use vars qw($template $vars);
+use vars qw($template $vars $bugzilla_lang);
# If Bugzilla is shut down, do not go any further, just display a message
# to the user about the downtime. (do)editparams.cgi is exempted from
@@ -1094,6 +1094,11 @@
return(\@operations, $incomplete_data);
}
+sub setLanguageCookie {
+ return unless ($_[0]);
+ my $cookiepath = Param("cookiepath");
+ print "Set-Cookie: Bugzilla_language=$_[0]; path=$cookiepath; expires=+10y\n";
+}
############# Live code below here (that is, not subroutine defs) #############
@@ -1127,19 +1132,7 @@
}
}
-if (defined $ENV{"HTTP_COOKIE"}) {
- # Don't trust anything which came in as a cookie
- use re 'taint';
- foreach my $pair (split(/;/, $ENV{"HTTP_COOKIE"})) {
- $pair = trim($pair);
- if ($pair =~ /^([^=]*)=(.*)$/) {
- if (!exists($::COOKIE{$1})) {
- $::COOKIE{$1} = $2;
- }
- } else {
- $::COOKIE{$pair} = "";
- }
- }
-}
+setLanguageCookie($bugzilla_lang);
+mkCookieArray();
1;
diff -uNrd bugzilla-2.16.8.orig/checksetup.pl bugzilla-2.16.8/checksetup.pl
--- bugzilla-2.16.8.orig/checksetup.pl 2004-10-10 00:20:16 +0400
+++ bugzilla-2.16.8/checksetup.pl 2005-01-26 16:33:38 +0300
@@ -540,6 +540,12 @@
');
+unless (-e 'localization.list') {
+ print "Creating locale file ...\n";
+ open FD, ">localization.list";
+ print FD "\$localizations{\"en\"}=\"English\";\n";
+ close FD;
+}
if ($newstuff ne "") {
diff -uNrd bugzilla-2.16.8.orig/globals.pl bugzilla-2.16.8/globals.pl
--- bugzilla-2.16.8.orig/globals.pl 2005-01-15 07:50:03 +0300
+++ bugzilla-2.16.8/globals.pl 2005-01-26 16:33:38 +0300
@@ -1531,6 +1531,12 @@
# the user interface using templates in the "template/" subdirectory.
use Template;
+do 'localization.list';
+use vars qw( %localizations );
+
+do 'locale.pl';
+use vars qw( $INCLUDE_LOCALE_PATH @languageslist );
+
# Create the global template object that processes templates and specify
# configuration parameters that apply to all templates processed in this script.
@@ -1541,7 +1547,7 @@
$::template ||= Template->new(
{
# Colon-separated list of directories containing templates.
- INCLUDE_PATH => "template/en/custom:template/en/default" ,
+ INCLUDE_PATH => $INCLUDE_LOCALE_PATH ,
# Remove white-space before template directives (PRE_CHOMP) and at the
# beginning and end of templates and template blocks (TRIM) for better
@@ -1784,6 +1790,8 @@
# User Agent - useful for detecting in templates
'user_agent' => $ENV{'HTTP_USER_AGENT'} ,
+
+ 'languages_list' => \@languageslist,
};
1;
diff -uNrd bugzilla-2.16.8.orig/locale.cgi bugzilla-2.16.8/locale.cgi
--- bugzilla-2.16.8.orig/locale.cgi 1970-01-01 03:00:00 +0300
+++ bugzilla-2.16.8/locale.cgi 2005-01-26 16:36:55 +0300
@@ -0,0 +1,41 @@
+#!/usr/bonsaitools/bin/perl -wT
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Netscape Communications
+# Corporation. Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation. All
+# Rights Reserved.
+#
+# Contributor(s): Alexey Gladkov <legion@alttlinux.org>
+
+use diagnostics;
+use strict;
+
+use lib qw(.);
+
+require "CGI.pl";
+
+# Shut up misguided -w warnings about "used only once":
+use vars qw(
+%localizations
+%FORM
+);
+
+my $lang = $::FORM{'bugzillalang'};
+setLanguageCookie($lang) if($lang && defined $::localizations{$lang});
+
+print "Status: 301 Permanent Redirect\n";
+print "Location: $ENV{\"HTTP_REFERER\"}\n\n";
+exit;
diff -uNrd bugzilla-2.16.8.orig/locale.pl bugzilla-2.16.8/locale.pl
--- bugzilla-2.16.8.orig/locale.pl 1970-01-01 03:00:00 +0300
+++ bugzilla-2.16.8/locale.pl 2005-01-26 16:33:38 +0300
@@ -0,0 +1,106 @@
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Netscape Communications
+# Corporation. Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation. All
+# Rights Reserved.
+#
+# Contributor(s): Alexey Gladkov <legion@altlinux.org>
+
+our $INCLUDE_LOCALE_PATH = "";
+our $bugzilla_lang = "";
+
+my @SEARCH_PATH = ( "custom", "default" );
+
+sub sort_array {
+ return (sort { (values %{$b})[0] <=> (values %{$a})[0] } @{$_[0]});
+}
+
+sub parseAcceptLanguage {
+ my ($elem, @output);
+ foreach $elem ( split(',', $_[0]) ) {
+ my $tmp = {};
+ my @lang = split(';',$elem);
+ $tmp->{$lang[0]} = @lang > 1 ? ( split('=',$lang[1]) )[1] : 1;
+ push(@output, $tmp);
+ }
+ return sort_array(\@output);
+}
+
+sub getLanguage {
+ return "" unless $_[0];
+ foreach my $hsh ($_[0]) {
+ while (my ($lang, $quality) = each %{$hsh} ) {
+ my @arr = split('-',$lang);
+ if (@arr > 1) {
+ return $arr[0] if ($::localizations{$arr[0]});
+ return $arr[1] if ($::localizations{$arr[1]});
+ }
+ return $lang if ($::localizations{$lang});
+ }
+ }
+ return ( sort( keys %::localizations ) )[0];
+}
+
+sub mkCookieArray {
+ return if defined %::COOKIE;
+ if (defined $ENV{"HTTP_COOKIE"}) {
+ # Don't trust anything which came in as a cookie
+ use re 'taint';
+ foreach my $pair (split(/;/, $ENV{"HTTP_COOKIE"})) {
+ $pair = trim($pair);
+ if ($pair =~ /^([^=]*)=(.*)$/) {
+ if (!exists($::COOKIE{$1})) {
+ $::COOKIE{$1} = $2;
+ }
+ } else {
+ $::COOKIE{$pair} = "";
+ }
+ }
+ }
+}
+
+sub debug_lang {
+ open FD, ">>/tmp/xxx";
+ print FD "!!!".$_[0]."\n";
+ close FD;
+}
+
+if (defined %::localizations) {
+ mkCookieArray();
+ $bugzilla_lang = $::COOKIE{'Bugzilla_language'};
+ if (! $bugzilla_lang && $ENV{'HTTP_ACCEPT_LANGUAGE'}) {
+ $bugzilla_lang = getLanguage( parseAcceptLanguage($ENV{'HTTP_ACCEPT_LANGUAGE'}) );
+ } elsif ( $bugzilla_lang ) {
+ $bugzilla_lang = getLanguage( ( {$bugzilla_lang => 1} ) );
+ } else {
+ $bugzilla_lang = "en";
+ }
+
+ # Make list available languages
+ our @languageslist = ();
+ while ( my ($key, $value) = each %::localizations ) {
+ my $tmp = { value => $key, description => $value };
+ push (@languageslist, $tmp);
+ }
+
+ # Generate correct path for Template Toolkit
+ foreach my $dir (@SEARCH_PATH) {
+ $INCLUDE_LOCALE_PATH .= "template/$bugzilla_lang/$dir:";
+ }
+ chop ($INCLUDE_LOCALE_PATH);
+ $INCLUDE_LOCALE_PATH .= ":template/en/custom:template/en/default" unless $bugzilla_lang =~ /en/;
+} else {
+ $bugzilla_lang = "en";
+ $INCLUDE_LOCALE_PATH .= "template/en/custom:template/en/default";
+}
diff -uNrd bugzilla-2.16.8.orig/localization.list bugzilla-2.16.8/localization.list
--- bugzilla-2.16.8.orig/localization.list 1970-01-01 03:00:00 +0300
+++ bugzilla-2.16.8/localization.list 2005-01-26 16:33:38 +0300
@@ -0,0 +1 @@
+$localizations{"en"}="English";
diff -uNrd bugzilla-2.16.8.orig/template/en/default/global/locale.html.tmpl bugzilla-2.16.8/template/en/default/global/locale.html.tmpl
--- bugzilla-2.16.8.orig/template/en/default/global/locale.html.tmpl 1970-01-01 03:00:00 +0300
+++ bugzilla-2.16.8/template/en/default/global/locale.html.tmpl 2005-01-26 16:33:38 +0300
@@ -0,0 +1,40 @@
+<!-- 1.0@bugzilla.org -->
+[%# The contents of this file are subject to the Mozilla Public
+ # License Version 1.1 (the "License"); you may not use this file
+ # except in compliance with the License. You may obtain a copy of
+ # the License at http://www.mozilla.org/MPL/
+ #
+ # Software distributed under the License is distributed on an "AS
+ # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ # implied. See the License for the specific language governing
+ # rights and limitations under the License.
+ #
+ # The Original Code is the Bugzilla Bug Tracking System.
+ #
+ # The Initial Developer of the Original Code is Netscape Communications
+ # Corporation. Portions created by Netscape are
+ # Copyright (C) 1998 Netscape Communications Corporation. All
+ # Rights Reserved.
+ #
+ # Contributor(s): Alexey Gladkov <legion@altlinux.org>
+ #%]
+
+
+<form method="get" action="locale.cgi">
+ <table>
+ <tr>
+ <td align="right">
+ <b>Choose your language:</b>
+ </td>
+ <td>
+ <select name="bugzillalang">
+ [% FOREACH qv = languages_list %]
+ <option value="[% qv.value %]">[% qv.description %]</option>
+ [% END %]
+ </select>
+ <input type="submit" value="Choose">
+ </td>
+ </tr>
+ </table>
+</form>
+
diff -uNrd bugzilla-2.16.8.orig/template/en/default/index.html.tmpl bugzilla-2.16.8/template/en/default/index.html.tmpl
--- bugzilla-2.16.8.orig/template/en/default/index.html.tmpl 2002-06-23 21:36:05 +0400
+++ bugzilla-2.16.8/template/en/default/index.html.tmpl 2005-01-26 16:33:38 +0300
@@ -88,4 +88,5 @@
//-->
</script>
+[% PROCESS "global/locale.html.tmpl" %]
[% PROCESS global/footer.html.tmpl %]