Commit 1d505b29 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 425288: checksetup.pl displays messages using the first language available,…

Bug 425288: checksetup.pl displays messages using the first language available, alphabetically, rather than falling back to english if the desired language is not found - Patch by Fré©ric Buclin <LpSolit@gmail.com> r=wurblzap a=mkanat
parent 1d08cb2f
...@@ -29,7 +29,7 @@ use strict; ...@@ -29,7 +29,7 @@ use strict;
use Bugzilla::Constants; use Bugzilla::Constants;
use File::Basename; use File::Basename;
use POSIX (); use POSIX qw(setlocale LC_CTYPE);
use Safe; use Safe;
use base qw(Exporter); use base qw(Exporter);
...@@ -40,6 +40,7 @@ our @EXPORT_OK = qw( ...@@ -40,6 +40,7 @@ our @EXPORT_OK = qw(
install_string install_string
template_include_path template_include_path
vers_cmp vers_cmp
get_console_locale
); );
sub bin_loc { sub bin_loc {
...@@ -165,17 +166,6 @@ sub template_include_path { ...@@ -165,17 +166,6 @@ sub template_include_path {
} }
} }
# If we didn't want *any* of the languages we support, just use all
# of the languages we said we support, in the order they were specified.
# This is only done when you ask for a certain set of languages, because
# otherwise @supported just came off the disk in alphabetical order,
# and it could give you de (German) when you speak English.
# (If @supported came off the disk, we fall back on English if no language
# is available--that happens below.)
if (!@usedlanguages && $params->{use_languages}) {
@usedlanguages = @supported;
}
# We always include English at the bottom if it's not there, even if # We always include English at the bottom if it's not there, even if
# somebody removed it from use_languages. # somebody removed it from use_languages.
if (!grep($_ eq 'en', @usedlanguages)) { if (!grep($_ eq 'en', @usedlanguages)) {
...@@ -304,6 +294,21 @@ sub _sort_accept_language { ...@@ -304,6 +294,21 @@ sub _sort_accept_language {
return map($_->{'language'}, (sort sortQvalue @qlanguages)); return map($_->{'language'}, (sort sortQvalue @qlanguages));
} }
sub get_console_locale {
my $locale = setlocale(LC_CTYPE);
# Some distros set e.g. LC_CTYPE = fr_CH.UTF-8. We clean it up.
if ($locale =~ /^([^\.]+)/) {
$locale = $1;
}
$locale =~ s/_/-/;
# It's pretty sure that there is no language pack of the form fr-CH
# installed, so we also include fr as a wanted language.
if ($locale =~ /^(\S+)\-/) {
$locale .= ",$1";
}
return $locale;
}
# This is like request_cache, but it's used only by installation code # This is like request_cache, but it's used only by installation code
# for setup.cgi and things like that. # for setup.cgi and things like that.
...@@ -366,6 +371,11 @@ binary, if the binary is in the C<PATH>. ...@@ -366,6 +371,11 @@ binary, if the binary is in the C<PATH>.
Returns a hash containing information about what version of Bugzilla we're Returns a hash containing information about what version of Bugzilla we're
running, what perl version we're using, and what OS we're running on. running, what perl version we're using, and what OS we're running on.
=item C<get_console_locale>
Returns the language to use based on the LC_CTYPE value returned by the OS.
If LC_CTYPE is of the form fr-CH, then fr is appended to the list.
=item C<indicate_progress> =item C<indicate_progress>
=over =over
......
...@@ -47,14 +47,13 @@ use 5.008001; ...@@ -47,14 +47,13 @@ use 5.008001;
use File::Basename; use File::Basename;
use Getopt::Long qw(:config bundling); use Getopt::Long qw(:config bundling);
use Pod::Usage; use Pod::Usage;
use POSIX qw(setlocale LC_CTYPE);
use Safe; use Safe;
BEGIN { chdir dirname($0); } BEGIN { chdir dirname($0); }
use lib qw(. lib); use lib qw(. lib);
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Install::Requirements; use Bugzilla::Install::Requirements;
use Bugzilla::Install::Util qw(install_string get_version_and_os); use Bugzilla::Install::Util qw(install_string get_version_and_os get_console_locale);
###################################################################### ######################################################################
# Live Code # Live Code
...@@ -62,7 +61,7 @@ use Bugzilla::Install::Util qw(install_string get_version_and_os); ...@@ -62,7 +61,7 @@ use Bugzilla::Install::Util qw(install_string get_version_and_os);
# When we're running at the command line, we need to pick the right # When we're running at the command line, we need to pick the right
# language before ever displaying any string. # language before ever displaying any string.
$ENV{'HTTP_ACCEPT_LANGUAGE'} ||= setlocale(LC_CTYPE); $ENV{'HTTP_ACCEPT_LANGUAGE'} ||= get_console_locale();
my %switch; my %switch;
GetOptions(\%switch, 'help|h|?', 'check-modules', 'no-templates|t', GetOptions(\%switch, 'help|h|?', 'check-modules', 'no-templates|t',
......
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