web: improve language selection

This commit is contained in:
David Anderson 2016-12-06 10:07:12 -08:00
parent b7b2f2e349
commit a025c425a9
3 changed files with 57 additions and 44 deletions

View File

@ -55,42 +55,39 @@ $language_names = array(
array("zh_TW", "繁體中文", "Chinese (Taiwan)"),
);
function language_select() {
function language_select($cur_lang_name) {
global $language_names;
echo "cur lang: $cur_lang_name";
$supported_languages = get_supported_languages();
$supported_languages[] = "en";
$bd = tra("Browser default");
$sel = $cur_lang_name?"":"selected";
echo "
<option value=auto selected=\"selected\">-- language --
<option value=auto>$bd
<option $sel value=auto> Browser default
";
if ($bd != "Browser default") echo " (Browser default)";
foreach ($language_names as $lang) {
if (!in_array($lang[0], $supported_languages)) continue;
$sel = ($cur_lang_name == $lang[0])?"selected":"";
if ($lang[0] == "en") {
echo "<option value=".$lang[0].">".$lang[1];
echo "<option $sel value=".$lang[0].">".$lang[1];
} else {
echo "<option value=".$lang[0].">".$lang[1]." (".$lang[2].")";
echo "<option $sel value=".$lang[0].">".$lang[1]." (".$lang[2].")";
}
}
}
// show a menu of supported languages
//
function language_form() {
echo "
<table><tr><td>
<form name=language method=get action=set_language.php>
<select class=\"selectbox form-control\" name=lang onchange=\"javascript: submit()\">
";
language_select();
echo "</select>
function language_form($cur_lang_name=null) {
echo '
<div class="col-sm-3">
<form name="language" method="get" action="set_language.php">
<select class="selectbox form-control" name="lang" onchange="javascript: submit()">
';
language_select($cur_lang_name);
echo '</select>
</form>
<script type=\"text/javascript\">
document.language.lang.selectedIndex=0;
</script>
</td></tr></table>
";
</div>
';
}
?>

View File

@ -19,8 +19,8 @@
require_once("../inc/util.inc");
require_once("../inc/translation.inc");
require_once("../inc/language_names.inc");
check_get_args(array("set_lang"));
$languages = get_supported_languages();
if (!is_array($languages)) {
@ -63,10 +63,11 @@ function language_name($code) {
}
if (count($languages_in_use)) {
$cur_lang_name = language_name($languages_in_use[0]);
$lang_code = $languages_in_use[0];
} else {
$cur_lang_name = language_name('en');
$lang_code = 'en';
}
$cur_lang_name = language_name($lang_code);
echo "<p>",
tra(
@ -86,31 +87,15 @@ echo "<p>",
"</ul>",
"<p>",
tra(
"Or you can select a language by clicking on one of the links. This will send your browser a cookie; make sure your browser accepts cookies from our domain."
"Or you can select a language from the following menu:"
),
"</p>"
;
start_table();
row1(tra("Language name (click to select)"));
row1("<a href=language_select.php?set_lang=auto>"
.tra("Use browser language setting")
."</a>",
1, "row1"
);
sort($languages);
$i = 0;
foreach ($languages as $language) {
$name = language_name($language);
row1(
"<a href=\"language_select.php?set_lang=$language\">$name</a>",
1, "row$i"
);
$i = 1-$i;
}
end_table();
echo "<p>",
tra("Translations are done by volunteers. If your native language is not here, %1you can provide a translation%2.",
language_form($lang_code);
echo "<br clear=all><p> </p>",
tra("Translations are done by volunteers. If your native language is missing or incomplete, %1you can help translate%2.",
'<a href="http://boinc.berkeley.edu/trac/wiki/TranslateIntro">', '</a>'),
"</p>"
;

View File

@ -0,0 +1,31 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2016 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/util.inc");
require_once("../inc/translation.inc");
$languages = get_supported_languages();
$lang = sanitize_tags(get_str("lang", true));
if (!in_array($lang, $languages) && $lang!="auto" && $lang!="en") {
echo "Language $lang is not supported";
} else {
send_cookie('lang', $lang, true);
header('Location: index.php');
}
?>