function languages_options() { // Initialization global $locale; $return = array(is_eng_array('Detect', 'language', ' - ') => 'Detect'); $languages = get_available_languages(); $languages_list = languages_list(); $languages_self_list = languages_self_list(); $is_en = substr($locale, 0, 2) == 'en'; foreach ($languages as $language) { $return[] = array(isset($languages_self_list[$language]) ? $languages_self_list[$language] : $languages_list[$language] => array((isset($languages_list[$language]) ? $languages_list[$language] : $language) . ($is_en ? '' : ' - ' . $language) => $language)); } if (!in_array('en', $languages) && !in_array('en_US', $languages) && !in_array('en_GB', $languages)) { $return[] = array('English' => array(is_eng_array('English', 'language', ' - ') => 'en_US')); } return $return; }
<div class="panel-body"> <div class="form-group"> <select name="language" class="form-control" onchange="set_language()"> <?php $languages = get_available_languages(); $langtext = '<option value="Detect"'; if (!isset($_SESSION['language']) || $_SESSION['language'] == 'Detect') { $langtext .= ' selected="selected"'; } $langtext .= '>' . _x('Select language', 'language'); if (substr($locale, 0, 2) != 'en') { $langtext .= ' - Languages'; } $langtext .= "</option>\n"; $languages_list = languages_list(); $languages_self_list = languages_self_list(); if (!in_array('en', $languages, true) && !in_array('en_US', $languages, true) && !in_array('en_GB', $languages, true)) { $langtext .= '<option value="en_US"'; if ($_SESSION['language'] == 'en_US') { $langtext .= ' selected="selected"'; } $langtext .= '>' . _x('English', 'language') . " - English</option>\n"; } foreach ($languages as $language) { $langtext .= "<option value=\"{$language}\""; if ($_SESSION['language'] == $language) { $langtext .= ' selected="selected"'; } $langtext .= '>' . (isset($languages_list[$language]) ? $languages_list[$language] : $language); $langtext .= " - " . (isset($languages_self_list[$language]) ? $languages_self_list[$language] : $languages_list[$language]) . "</option>\n"; }