I’ve been using the WPML plugin on a few sites recently to turn WordPress into a very powerful multilingual CMS, with great success. I really have to applaud these guys for building a very useful plugin. On the to-do list is integrating their plug-in with WordPress’ built-in widgets. A few people have mentioned getting stuck when trying to use the Links feature of WordPress, which does not currently work with WPML.

To fix this issue, I’ve thrown together a quick widget that acts as a wrapper for WordPress’ built-in widget, but lets you set a different link category for each language you have setup using WPML. I hope you find this useful.

To install, copy and paste this into your theme’s function.php file or insert code into a file in the plugins directory.

* NOTE – This code may be out of date. Please try commenter Loic’s solution here if the code below does not work properly.

* NOTE – Commenter Uli has also improved this plugin and extended it in a similar way to translate RSS Feeds. Visit barcelonabudget.es for more info.

add_action('widgets_init',  array('LinkTranslationWidget','register_widget'));
 
class LinkTranslationWidget extends WP_Widget
{
 
	function LinkTranslationWidget() {
 
		/* Widget settings. */
		$widget_ops = array( 'classname' => 'LinkTranslationWidget', 'description' => __('This widget allows you to set different link categories to display based on a language setting.', $this->plugin_name) );
 
		/* Widget control settings. */
 
		/* Create the widget. */
		$this->WP_Widget( 'LinkTranslationWidget', __('WPML Links'), $widget_ops );
 
	}
 
	function register_widget()
	{
		register_widget('LinkTranslationWidget');
	}
 
	function widget( $args, $instance ) {
 
		global $sitepress;
 
		if(class_exists('WP_Widget_Links')) {
 
			$link_widget = new WP_Widget_Links();
 
			if(isset($sitepress))
			{
 
				$lang = $sitepress->get_current_language();
				$instance['category'] = $instance[$lang.'_category'];
				$link_widget->widget($args, $instance);
 
			}
 
		}
 
	}
 
	function update($new_instance, $old_instance) {
 
		$new_instance = (array) $new_instance;
		$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
		foreach ( $instance as $field => $val ) {
			if ( isset($new_instance[$field]) )
				$instance[$field] = 1;
		}
 
		$langs = $this->GetLangs();
		foreach($langs as $lang=>$lang_id)
		{
			$instance[$lang.'_category'] = intval($new_instance[$lang.'_category']);
		}
 
		return $instance;
 
	}
 
	function form($instance) {
 
		$settings = $this->GetSettings();
		$langs = $this->GetLangs();
 
		$instance = wp_parse_args( (array) $instance, $settings );
 
		$link_cats = get_terms( 'link_category');
 
		foreach($langs as $lang=>$lang_id)
		{
			echo '
 
<label for="'. $this-&gt;get_field_id($lang.'_category').'">'. __('Select Link Category') . ' (' .$lang.'): </label>';
			echo '
<select id="'. $this-&gt;get_field_id($lang.'_category').'" name="'. $this-&gt;get_field_name($lang.'_category').'">';
			foreach ( $link_cats as $link_cat ) {
 
				echo '
<option value="' . intval($link_cat-&gt;term_id) . '">term_id == $instance[$lang.'_category'] ? ' selected="selected"' : '' )
				. '&gt;' . $link_cat-&gt;name . "</option>
 
\n";
			}
			echo '</select>
 
';
 
		}
		?&gt;
<input class="checkbox" type="checkbox" /> id="<!--?php echo $this--->get_field_id('images'); ?&gt;" name="<!--?php echo $this--->get_field_name('images'); ?&gt;" /&gt;
		<label for="&lt;?php echo $this-&gt;get_field_id('images'); ?&gt;"><!--?php _e('Show Link Image'); ?--></label>
<input class="checkbox" type="checkbox" /> id="<!--?php echo $this--->get_field_id('name'); ?&gt;" name="<!--?php echo $this--->get_field_name('name'); ?&gt;" /&gt;
		<label for="&lt;?php echo $this-&gt;get_field_id('name'); ?&gt;"><!--?php _e('Show Link Name'); ?--></label>
<input class="checkbox" type="checkbox" /> id="<!--?php echo $this--->get_field_id('description'); ?&gt;" name="<!--?php echo $this--->get_field_name('description'); ?&gt;" /&gt;
		<label for="&lt;?php echo $this-&gt;get_field_id('description'); ?&gt;"><!--?php _e('Show Link Description'); ?--></label>
<input class="checkbox" type="checkbox" /> id="<!--?php echo $this--->get_field_id('rating'); ?&gt;" name="<!--?php echo $this--->get_field_name('rating'); ?&gt;" /&gt;
		<label for="&lt;?php echo $this-&gt;get_field_id('rating'); ?&gt;"><!--?php _e('Show Link Rating'); ?--></label>
 
		<!--?php 	} 	function GetLangs() 	{ 		global $sitepress_settings; 		$langs = $sitepress_settings['default_categories']; 		return $langs; 	} 	function GetSettings() 	{ 		$settings = array(); 		$settings['images'] = true; 		$settings['name'] = true; 		$settings['description'] = false; 		$settings['rating'] = false; 		$langs = $this--->GetLangs();
		foreach($langs as $lang=&gt;$lang_id)
		{
			$settings[$lang.'_category'] = '';
		}
		return $settings;
	}
 
}