Theming language selector in Drupal

Unfortunately Drupal (as in version 6.5) doesn’t allow easy theming for language selector. However it’s still possible with theme function overriding. Look at the code.

function yourtheme_links($links, $attributes = array('class' => 'links')) {
	list(,$first_link) = each($links);
	if (($first_link['attributes']['class'] == 'language-link')) {
		global $language;
		$new_links = array();
		$num_links = count($links);
		$i = 0;
		foreach ($links as $link) {
			$i ++;
			$link['title'] = '<span class="bg">' . $link['title'] . '</span>';
			$link['html']	= true;
			if ($link['language']->language == $language->language)
				$link['attributes']['class'] = 'selected';
			$new_links[] = $link;
			if ($i < $num_links)
				$new_links[] = array(
					'title'	=> '|',
					'attributes'	=> array('class'	=> 'separator')
				);
		}
		$links = $new_links;
	}
	return theme_links($links, $attributes);
}

It adds ‘selected’ class to the current language (which I think logical) and adds separator element between language links. You can customize them as you wish.

Tags: ,

AddThis Social Bookmark Button

Leave a Reply