This is my custom function:
function qtranxf_generatecustomLanguageSelectCode($style='') {
global $q_config;
if($style=='') $style='text';
$flag_location=qtranxf_flag_location();
if(is_404()) $url = get_option('home'); else $url = '';
echo '<ul class="nav navbar-nav navbar-right qtranxs_language_chooser">';
foreach(qtranxf_getSortedLanguages() as $language) {
$classes = array('lang-'.$language);
if($language == $q_config['language']) $classes[] = 'active';
echo '<li class="'. implode(' ', $classes) .'"><a href="'.qtranxf_convertURL($url, $language, false, true).'"';
// set hreflang
echo ' hreflang="'.$language.'"';
echo ' title="'.$q_config['language_name'][$language].'"';
if($style=='image' || $style=='both' ) echo '<img src="'.$flag_location.$q_config['flag'][$language].'"/>';
echo '<span';
if($style=='image') echo ' style="display:none"';
echo '>'.$language.'</span>';
echo '</a></li>';
}
echo '</ul>';
}
Remember, inside the function “qtrans_generateLanguageSelectCode()”:
$q_config['language_name'][$language]
-> language text (example english)
$language
-> language code (example en)