Implement language selection using LanguageManager

Issue #11847

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2016-01-12 14:07:43 +01:00
parent 19f9e830eb
commit bd779eeaea
3 changed files with 20 additions and 25 deletions

View File

@ -86,6 +86,18 @@ class Language
return $this->code;
}
/**
* Compare function used for sorting
*
* @param Language $other Other object to compare
*
* @return int same as strcmp
*/
public function cmp($other)
{
return strcmp($this->name, $other->name);
}
/**
* Checks whether language is currently active.
*

View File

@ -568,7 +568,7 @@ class LanguageManager
$this->availableLanguages();
uasort($this->_available_languages, function($a, $b)
{
return strcmp($a->name, $b->name);
return $a->cmp($b);
}
);
return $this->_available_languages;

View File

@ -5,20 +5,7 @@
*
* @package PhpMyAdmin
*/
/**
* Compares the names of two languages.
* Used by uasort in PMA_getLanguageSelectorHtml()
*
* @param array $a The first language being compared
* @param array $b The second language being compared
*
* @return int the sorted array
*/
function PMA_languageCmp($a, $b)
{
return strcmp($a[1], $b[1]);
}
use PMA\libraries\LanguageManager;
/**
* Returns HTML code for the language selector
@ -32,13 +19,12 @@ function PMA_languageCmp($a, $b)
*/
function PMA_getLanguageSelectorHtml($use_fieldset = false, $show_doc = true)
{
global $lang;
$retval = '';
$available_languages = LanguageManager::getInstance()->sortedLanguages();
// Display language selection only if there
// is more than one language to choose from
if (count($GLOBALS['available_languages']) > 1) {
if (count($available_languages) > 1) {
$retval .= '<form method="get" action="index.php" class="disableAjax">';
$_form_params = array(
@ -66,18 +52,15 @@ function PMA_getLanguageSelectorHtml($use_fieldset = false, $show_doc = true)
$retval .= '<select name="lang" class="autosubmit" lang="en"'
. ' dir="ltr" id="sel-lang">';
uasort($GLOBALS['available_languages'], 'PMA_languageCmp');
foreach ($GLOBALS['available_languages'] as $id => $tmplang) {
$lang_name = PMA_languageName($tmplang);
foreach ($available_languages as $language) {
//Is current one active?
if ($lang == $id) {
if ($language->isActive()) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$retval .= '<option value="' . $id . '"' . $selected . '>';
$retval .= $lang_name;
$retval .= '<option value="' . $language->getCode() . '"' . $selected . '>';
$retval .= $language->getName();
$retval .= '</option>';
}