Commit c56f5e3c authored by wurblzap%gmail.com's avatar wurblzap%gmail.com

Bug 365378 – The 'languages' parameter is not necessary.

Patch by Marc Schumann <wurblzap@gmail.com>; r=LpSolit; a=LpSolit
parent 5a1fdacb
......@@ -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.
......
......@@ -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;
......
......@@ -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" }
}
};
......
......@@ -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__
......
......@@ -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.
......
......@@ -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;
}
......
# -*- 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
......@@ -434,14 +434,6 @@
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>
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment