Created
March 9, 2015 16:48
-
-
Save fburatti/794a37c4d1983041b68a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function qtranxf_custom_language_chooser($style='', $id='') { | |
global $q_config; | |
if($style=='') $style='text'; | |
if(is_bool($style)&&$style) $style='image'; | |
if(is_404()) $url = get_option('home'); else $url = ''; | |
if($id=='') $id = 'qtranslate'; | |
$id .= '-chooser'; | |
$flag_location=qtranxf_flag_location(); | |
switch($style) { | |
case 'image': | |
case 'text': | |
case 'dropdown': | |
echo PHP_EOL.'<ul class="qtranxs_language_chooser" id="'.$id.'">'.PHP_EOL; | |
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).'"'; | |
//echo '<li'; if($language == $q_config['language']) echo ' class="active"'; | |
//echo '><a href="'.qtranxf_convertURL($url, $language, false, true).'"'; | |
// set hreflang | |
echo ' hreflang="'.$language.'"'; | |
echo ' title="'.$q_config['language_name'][$language].'"'; | |
if($style=='image') | |
echo ' class="qtranxs_image qtranxs_image_'.$language.'"'; | |
// echo ' class="qtranxs_flag qtranxs_flag_'.$language.'"'; | |
elseif($style=='text') | |
echo ' class="qtranxs_text qtranxs_text_'.$language.'"'; | |
echo '>'; | |
if($style=='image') echo '<img src="'.$flag_location.$q_config['flag'][$language].'"/>'; | |
echo '<span'; | |
if($style=='image') echo ' style="display:none"'; | |
echo '>'.$language.'</span>'; | |
echo '</a></li>'.PHP_EOL; | |
} | |
echo '</ul><div class="qtranxs_widget_end"></div>'.PHP_EOL; | |
if($style=='dropdown') { | |
echo '<script type="text/javascript">'.PHP_EOL.'// <![CDATA['.PHP_EOL; | |
echo "var lc = document.getElementById('".$id."');".PHP_EOL; | |
echo "var s = document.createElement('select');".PHP_EOL; | |
echo "s.id = 'qtranxs_select_".$id."';".PHP_EOL; | |
echo "lc.parentNode.insertBefore(s,lc);".PHP_EOL; | |
// create dropdown fields for each language | |
foreach(qtranxf_getSortedLanguages() as $language) { | |
echo qtranxf_insertDropDownElement($language, qtranxf_convertURL($url, $language, false, true), $id); | |
} | |
// hide html language chooser text | |
echo "s.onchange = function() { document.location.href = this.value;}".PHP_EOL; | |
echo "lc.style.display='none';".PHP_EOL; | |
echo '// ]]>'.PHP_EOL.'</script>'.PHP_EOL; | |
} | |
break; | |
case 'both': | |
echo PHP_EOL.'<ul class="qtranxs_language_chooser" id="'.$id.'">'.PHP_EOL; | |
foreach(qtranxf_getSortedLanguages() as $language) { | |
echo '<li'; | |
if($language == $q_config['language']) | |
echo ' class="active"'; | |
echo '><a href="'.qtranxf_convertURL($url, $language, false, true).'"'; | |
echo ' class="qtranxs_flag_'.$language.' qtranxs_flag_and_text" title="'.$q_config['language_name'][$language].'">'; | |
//echo '<img src="'.$flag_location.$q_config['flag'][$language].'"></img>'; | |
echo '<span>'.$language.'</span></a></li>'.PHP_EOL; | |
} | |
echo '</ul><div class="qtranxs_widget_end"></div>'.PHP_EOL; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment