]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 365378 รข\80\93 The 'languages' parameter is not necessary.
authorwurblzap%gmail.com <>
Wed, 22 Aug 2007 01:47:51 +0000 (01:47 +0000)
committerwurblzap%gmail.com <>
Wed, 22 Aug 2007 01:47:51 +0000 (01:47 +0000)
Patch by Marc Schumann <wurblzap@gmail.com>;
r=LpSolit; a=LpSolit

Bugzilla.pm
Bugzilla/Config/Common.pm
Bugzilla/Install.pm
Bugzilla/Install/DB.pm
Bugzilla/Template.pm
Bugzilla/Template/Plugin/Hook.pm
Bugzilla/User/Setting/Lang.pm [new file with mode: 0755]
docs/xml/customization.xml
editparams.cgi

index e4947fbe13bc6a901206b28611c53af09743a545..47cf256ffe262ce2fd1e0b882f4cb0c372dce795 100644 (file)
@@ -40,6 +40,7 @@ use Bugzilla::Util;
 use Bugzilla::Field;
 
 use File::Basename;
+use File::Spec::Functions;
 use Safe;
 
 # This creates the request cache for non-mod_perl installations.
@@ -308,6 +309,24 @@ sub dbh {
     return request_cache()->{dbh};
 }
 
+sub languages {
+    return request_cache()->{languages} if request_cache()->{languages};
+
+    my @files = glob(catdir(bz_locations->{'templatedir'}, '*'));
+    my @languages;
+    foreach my $dir_entry (@files) {
+        # It's a language directory only if it contains "default" or
+        # "custom". This auto-excludes CVS directories as well.
+        next unless (-d catdir($dir_entry, 'default')
+                  || -d catdir($dir_entry, 'custom'));
+        $dir_entry = basename($dir_entry);
+        # Check for language tag format conforming to RFC 1766.
+        next unless $dir_entry =~ /^[a-zA-Z]{1,8}(-[a-zA-Z]{1,8})?$/;
+        push(@languages, $dir_entry);
+    }
+    return request_cache()->{languages} = \@languages;
+}
+
 sub error_mode {
     my $class = shift;
     my $newval = shift;
@@ -627,6 +646,11 @@ used to automatically answer or skip prompts.
 
 The current database handle. See L<DBI>.
 
+=item C<languages>
+
+Currently installed languages.
+Returns a reference to a list of RFC 1766 language tags of installed languages.
+
 =item C<switch_to_shadow_db>
 
 Switch from using the main database to using the shadow database.
index 8435b20a1ae15ad7a4225e6cc8cd352cc64309c7..2e5e7d15d4d5a72fbf97af31e7183ae176ebaa60 100644 (file)
@@ -49,8 +49,8 @@ use base qw(Exporter);
        check_sslbase check_priority check_severity check_platform
        check_opsys check_shadowdb check_urlbase check_webdotbase
        check_netmask check_user_verify_class check_image_converter
-       check_languages check_mail_delivery_method check_notification
-       check_timezone check_utf8 check_bug_status
+       check_mail_delivery_method check_notification check_timezone check_utf8
+       check_bug_status
 );
 
 # Checking functions for the various values
@@ -304,27 +304,6 @@ sub check_image_converter {
     return "";
 }
 
-sub check_languages {
-    my ($lang) = @_;
-    my @languages = split(/[,\s]+/, trim($lang));
-    if(!scalar(@languages)) {
-       return "You need to specify a language tag."
-    }
-    my $templatedir = bz_locations()->{'templatedir'};
-    my %lang_seen;
-    my @validated_languages;
-    foreach my $language (@languages) {
-       if(   ! -d "$templatedir/$language/custom" 
-          && ! -d "$templatedir/$language/default") {
-          return "The template directory for $language does not exist";
-       }
-       push(@validated_languages, $language) unless $lang_seen{$language}++;
-    }
-    # Rebuild the list of language tags, avoiding duplicates.
-    $_[0] = join(', ', @validated_languages);
-    return "";
-}
-
 sub check_mail_delivery_method {
     my $check = check_multi(@_);
     return $check if $check;
index 7e3a97b7dcd4f8cca246214bf32f1c461fc2c3fd..f251e4d1c75740f634b628acf43a5c3366ebca05 100644 (file)
@@ -36,7 +36,6 @@ use Bugzilla::Util qw(get_text);
 use Bugzilla::Version;
 
 sub SETTINGS {
-    my @languages = split(/[\s,]+/, Bugzilla->params->{'languages'});
     return {
     # 2005-03-03 travis@sedsystems.ca -- Bug 41972
     display_quips      => { options => ["on", "off"], default => "on" },
@@ -59,10 +58,11 @@ sub SETTINGS {
     # 2006-08-04 wurblzap@gmail.com -- Bug 322693
     skin               => { subclass => 'Skin', default => 'Dusk' },
     # 2006-12-10 LpSolit@gmail.com -- Bug 297186
-    lang               => { options => \@languages,
-                            default => $languages[0] },
+    lang               => { subclass => 'Lang',
+                            default => ${Bugzilla->languages}[0] },
     # 2007-07-02 altlist@gmail.com -- Bug 225731
-    quote_replies      => { options => ['quoted_reply', 'simple_reply', 'off'], default => "quoted_reply" }
+    quote_replies      => { options => ['quoted_reply', 'simple_reply', 'off'],
+                            default => "quoted_reply" }
     }
 };
 
index d2abe9da62023373f5f7da37e66efa5790e85e6e..327487cd9549a1a22b83996d7122550de88148fc 100644 (file)
@@ -512,6 +512,9 @@ sub update_table_definitions {
     # 2007-08-08 LpSolit@gmail.com - Bug 332149
     $dbh->bz_add_column('groups', 'icon_url', {TYPE => 'TINYTEXT'});
 
+    # 2007-08-21 wurblzap@gmail.com - Bug 365378
+    _make_lang_setting_dynamic();
+
     ################################################################
     # New --TABLE-- changes should go *** A B O V E *** this point #
     ################################################################
@@ -2884,6 +2887,17 @@ sub _initialize_workflow {
     Bugzilla::Status::add_missing_bug_status_transitions();
 }
 
+sub _make_lang_setting_dynamic {
+    my $dbh = Bugzilla->dbh;
+    my $count = $dbh->selectrow_array(q{SELECT 1 FROM setting
+                                         WHERE name = 'lang'
+                                           AND subclass IS NULL});
+    if ($count) {
+        $dbh->do(q{UPDATE setting SET subclass = 'Lang' WHERE name = 'lang'});
+        $dbh->do(q{DELETE FROM setting_value WHERE name = 'lang'});
+    }
+}
+
 1;
 
 __END__
index 20fe8311256e778d6229679a18d44e2c075051f3..b0c185830a8609885e1165ba6317d169cdd242de 100644 (file)
@@ -87,7 +87,7 @@ sub getTemplateIncludePath {
     my $cache = Bugzilla->request_cache;
     my $lang  = $cache->{'language'} || "";
     $cache->{"template_include_path_$lang"} ||= template_include_path({
-        use_languages => [split(/[\s,]+/, Bugzilla->params->{'languages'})],
+        use_languages => Bugzilla->languages,
         only_language => $lang });
     return $cache->{"template_include_path_$lang"};
 }
@@ -767,9 +767,6 @@ sub precompile_templates {
         -d "$templatedir/$dir/default" || -d "$templatedir/$dir/custom" 
             || next;
         local $ENV{'HTTP_ACCEPT_LANGUAGE'} = $dir;
-        # We locally hack this parameter so that Bugzilla::Template
-        # accepts this language no matter what.
-        local Bugzilla->params->{'languages'} = "$dir,en";
         my $template = Bugzilla::Template->create(clean_cache => 1);
 
         # Precompile all the templates found in all the directories.
index b1f27990ef5512dbb7c09cdd4748797832bcf373..54ce02a672593c3494abfbd44c1c05c4553869d6 100644 (file)
@@ -107,7 +107,7 @@ sub process {
 # get a list of languages we accept so we can find the hook 
 # that corresponds to our desired languages:
 sub getLanguages() {
-    my $languages = trim(Bugzilla->params->{'languages'});
+    my $languages = join(',', @{Bugzilla->languages});
     if (not ($languages =~ /,/)) { # only one language
         return $languages;
     }
diff --git a/Bugzilla/User/Setting/Lang.pm b/Bugzilla/User/Setting/Lang.pm
new file mode 100755 (executable)
index 0000000..7937270
--- /dev/null
@@ -0,0 +1,60 @@
+# -*- 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 Marc Schumann.
+# Portions created by Marc Schumann are Copyright (c) 2007 Marc Schumann.
+# All rights reserved.
+#
+# Contributor(s): Marc Schumann <wurblzap@gmail.com>
+
+package Bugzilla::User::Setting::Lang;
+
+use strict;
+
+use base qw(Bugzilla::User::Setting);
+
+use Bugzilla::Constants;
+
+sub legal_values {
+    my ($self) = @_;
+
+    return $self->{'legal_values'} if defined $self->{'legal_values'};
+
+    return $self->{'legal_values'} = Bugzilla->languages;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Bugzilla::User::Setting::Lang - Object for a user preference setting for preferred language
+
+=head1 DESCRIPTION
+
+Lang.pm extends Bugzilla::User::Setting and implements a class specialized for
+setting the preferred language.
+
+=head1 METHODS
+
+=over
+
+=item C<legal_values()>
+
+Description: Returns all legal languages
+Params:      none
+Returns:     A reference to an array containing the names of all legal languages
+
+=back
index ce48ab940797a328f531cd13ddf16c7bba8fbd33..90d2d620854d14ef1d888b5a4c396904e7a86b21 100644 (file)
       url="http://www.bugzilla.org/download.html#localizations"/>. Instructions
       for submitting new languages are also available from that location.
       </para>
-
-      <para>After untarring the localizations (or creating your own) in the 
-      <filename class="directory">BUGZILLA_ROOT/template</filename> directory,
-      you must update the <option>languages</option> parameter to contain any
-      localizations you'd like to permit. You may also wish to re-order
-      the <option>languages</option> parameter so that <quote>en</quote> 
-      doesn't come first, if you don't want English to be the default language.
-      </para>
     </section>
       
   </section>
index 38d4866560691c9aabb0dcc329cdd6d759d108f2..819c8c64580ac2bcbd1f345cdd209d490335f1ea 100755 (executable)
@@ -75,7 +75,6 @@ if ($action eq 'save' && $current_module) {
     my @changes = ();
     my @module_param_list = "Bugzilla::Config::${current_module}"->get_param_list(1);
 
-    my $update_lang_user_pref = 0;
     foreach my $i (@module_param_list) {
         my $name = $i->{'name'};
         my $value = $cgi->param($name);
@@ -135,22 +134,11 @@ if ($action eq 'save' && $current_module) {
             if (($name eq "shutdownhtml") && ($value ne "")) {
                 $vars->{'shutdown_is_active'} = 1;
             }
-            if ($name eq 'languages') {
-                $update_lang_user_pref = 1;
-            }
             if ($name eq 'duplicate_or_move_bug_status') {
                 Bugzilla::Status::add_missing_bug_status_transitions($value);
             }
         }
     }
-    if ($update_lang_user_pref) {
-        # We have to update the list of languages users can choose.
-        # If some users have selected a language which is no longer available,
-        # then we delete it (the user pref is reset to the default one).
-        my @languages = split(/[\s,]+/, Bugzilla->params->{'languages'});
-        map {trick_taint($_)} @languages;
-        add_setting('lang', \@languages, $languages[0], undef, 1);
-    }
 
     $vars->{'message'} = 'parameters_updated';
     $vars->{'param_changed'} = \@changes;