Skip to content

Instantly share code, notes, and snippets.

@sardbaba
Last active December 14, 2015 18:29
Show Gist options
  • Save sardbaba/5130115 to your computer and use it in GitHub Desktop.
Save sardbaba/5130115 to your computer and use it in GitHub Desktop.
qtrans_generate_language_list() is a better version of the qtrans_generateLanguageSelectCode() function from qTranslate's Wordpress plugin, originally used to print the languages as an HTML select. This function receive an optional string for the separator that will be echoed and it is able to show your languages as spans followed by separators:…
/**
* Language list Code for non-Widget users
*
* @global array $q_config
* @param string $sep
*/
function qtrans_generate_language_list($sep = " | ") {
global $q_config;
$languages = qtrans_getSortedLanguages();
$num_langs = count($languages);
$id = 'qtranslate-chooser';
$url = is_404() ? get_option('home') : '';
echo '<div class="qtrans_language_chooser" id="' . $id . '">';
foreach ($languages as $language) {
$classes = array('lang-' . $language);
if ($language == $q_config['language'])
$classes[] = 'active';
echo '<span class="' . implode(' ', $classes) . '"><a href="' . qtrans_convertURL($url, $language) . '"';
echo ' hreflang="' . $language . '" title="' . $q_config['language_name'][$language] . '"';
echo '>' . $q_config['language_name'][$language] . '</a></span>';
if (--$num_langs > 0) {
echo '<span class="qtrans_separator">' . $sep . '</span>';
}
}
echo "</div>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment