mirror of
https://github.com/webmin/webmin.git
synced 2026-02-03 06:03:28 +00:00
Add support to select locale in Change Language and Theme Webmin module
This commit is contained in:
@@ -88,6 +88,8 @@ while(my $l = <$fh>) {
|
||||
$user{'modules'} = $acl{$user[0]};
|
||||
$user{'lang'} = $gconfig{"lang_$user[0]"};
|
||||
$user{'langauto'} = $gconfig{"langauto_$user[0]"};
|
||||
$user{'locale'} = $gconfig{"locale_$user[0]"};
|
||||
$user{'dateformat'} = $gconfig{"dateformat_$user[0]"};
|
||||
$user{'notabs'} = $gconfig{"notabs_$user[0]"};
|
||||
$user{'rbacdeny'} = $gconfig{"rbacdeny_$user[0]"};
|
||||
if ($gconfig{"theme_$user[0]"}) {
|
||||
@@ -702,6 +704,10 @@ else {
|
||||
$gconfig{"lang_".$user->{'name'}} = $user->{'lang'} if ($user->{'lang'});
|
||||
delete($gconfig{"langauto_".$username});
|
||||
$gconfig{"langauto_".$user->{'name'}} = $user->{'langauto'} if (defined($user->{'langauto'}));
|
||||
delete($gconfig{"locale_".$username});
|
||||
$gconfig{"locale_".$user->{'name'}} = $user->{'locale'} if (defined($user->{'locale'}));
|
||||
delete($gconfig{"dateformat_".$username});
|
||||
$gconfig{"dateformat_".$user->{'name'}} = $user->{'dateformat'} if (defined($user->{'dateformat'}));
|
||||
delete($gconfig{"notabs_".$username});
|
||||
$gconfig{"notabs_".$user->{'name'}} = $user->{'notabs'}
|
||||
if ($user->{'notabs'});
|
||||
|
||||
@@ -14,6 +14,9 @@ my ($o) = @_;
|
||||
print &ui_table_row($text{'acl_lang'},
|
||||
&ui_yesno_radio("lang", $o->{'lang'}));
|
||||
|
||||
print &ui_table_row($text{'acl_locale'},
|
||||
&ui_yesno_radio("locale", $o->{'locale'}));
|
||||
|
||||
print &ui_table_row($text{'acl_theme'},
|
||||
&ui_yesno_radio("theme", $o->{'theme'}));
|
||||
|
||||
|
||||
@@ -42,6 +42,30 @@ if ($access{'lang'}) {
|
||||
}
|
||||
}
|
||||
|
||||
# Parse custom locale
|
||||
if ($access{'locale'}) {
|
||||
# Parse new locale
|
||||
if ($in{'locale_def'} ||
|
||||
$in{'locale'}) {
|
||||
if ($in{'locale_def'}) {
|
||||
$user->{'locale'} = undef;
|
||||
}
|
||||
else {
|
||||
$user->{'locale'} = $in{'locale'};
|
||||
}
|
||||
}
|
||||
# Parse old dateformat
|
||||
if ($in{'dateformat_def'} ||
|
||||
$in{'dateformat'}) {
|
||||
if ($in{'dateformat_def'}) {
|
||||
$user->{'dateformat'} = undef;
|
||||
}
|
||||
else {
|
||||
$user->{'dateformat'} = $in{'dateformat'};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Parse custom theme and possibly overlay
|
||||
my ($newoverlay, $newtheme);
|
||||
if ($access{'theme'}) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
lang=1
|
||||
locale=1
|
||||
theme=1
|
||||
pass=1
|
||||
|
||||
@@ -56,6 +56,37 @@ if ($access{'lang'}) {
|
||||
undef, [ "valign=top","valign=top" ]);
|
||||
}
|
||||
|
||||
# Old datetime format or a new locale
|
||||
if ($access{'locale'}) {
|
||||
my $locale;
|
||||
eval "use DateTime; use DateTime::Locale; use DateTime::TimeZone;";
|
||||
&foreign_require('webmin');
|
||||
if (!$@) {
|
||||
$locale++;
|
||||
my $locales = &webmin::list_locales();
|
||||
my %localesrev = reverse %{$locales};
|
||||
print &ui_table_row($text{'index_locale'},
|
||||
&ui_radio("locale_def", defined($user->{'locale'}) ? 0 : 1,
|
||||
[ [ 1, &text('index_localeglobal2', $locales->{$gconfig{'locale'}}, $gconfig{'locale'})."<br>" ],
|
||||
[ 0, $text{'index_localeset'} ] ])." ".
|
||||
&ui_select("locale", $user->{'locale'},
|
||||
[ map { [ $localesrev{$_}, $_ ] } sort values %{$locales} ] ),
|
||||
undef, [ "valign=top","valign=top" ]);
|
||||
}
|
||||
|
||||
if (!$locale) {
|
||||
my %wtext = &load_language('webmin');
|
||||
print &ui_table_row($text{'index_locale2'},
|
||||
&ui_radio("dateformat_def", defined($user->{'dateformat'}) ? 0 : 1,
|
||||
[ [ 1, &text('index_dateformatglobal2', $gconfig{'dateformat'} || "dd/mon/yyyy")."<br>" ],
|
||||
[ 0, $text{'index_dateformatset'} ] ])." ".
|
||||
&ui_select("dateformat", $user->{'dateformat'} || "dd/mon/yyyy",
|
||||
[ map { [ $_, $wtext{'lang_dateformat_'.$_} ] }
|
||||
@webmin::webmin_date_formats ] ),
|
||||
undef, [ "valign=top","valign=top" ]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($access{'theme'}) {
|
||||
# Show personal theme
|
||||
my $tname;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
lang=1
|
||||
locale=1
|
||||
theme=1
|
||||
pass=1
|
||||
|
||||
@@ -1990,7 +1990,7 @@ my ($secs, $only, $fmt) = @_;
|
||||
eval "use DateTime; use DateTime::Locale; use DateTime::TimeZone;";
|
||||
if (!$@) {
|
||||
my $opts = ref($only) ? $only : {};
|
||||
my $locale_name = $opts->{'locale'} || $gconfig{'locale'} || 'en-US';
|
||||
my $locale_name = $opts->{'locale'} || $gconfig{'locale_'.$remote_user} || $gconfig{'locale'} || 'en-US';
|
||||
my $tz = $opts->{'tz'} ||
|
||||
DateTime::TimeZone->new( name => 'local' )->name(); # Asia/Nicosia
|
||||
my $locale = DateTime::Locale->load($locale_name);
|
||||
@@ -2074,7 +2074,7 @@ else {
|
||||
my @tm = localtime($secs);
|
||||
my $date;
|
||||
if (!$fmt) {
|
||||
$fmt = $gconfig{'dateformat'} || 'dd/mon/yyyy';
|
||||
$fmt = $gconfig{'dateformat_'.$remote_user} || $gconfig{'dateformat'} || 'dd/mon/yyyy';
|
||||
}
|
||||
if ($fmt eq 'dd/mon/yyyy') {
|
||||
$date = sprintf "%2.2d/%s/%4.4d",
|
||||
|
||||
Reference in New Issue
Block a user