AFAIK, you'd have to replicate the Widgets that you want with custom translation fields.
The following is an adaptation of the Search Widget, copied from /wp-includes/default-widgets.php
.
Note that you can optimize all FIELD_language
option values, doing a foreach
in all available languages.
add_action( 'widgets_init', 'qtrans_search_widget_so_14303711' );
function qtrans_search_widget_so_14303711()
{
unregister_widget( 'WP_Widget_Search' );
register_widget( 'QT_Widget_Search' );
}
class QT_Widget_Search extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
parent::__construct('search', __('Search'), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title_en = empty( $instance['title_en'] ) ? '' : $instance['title_en'] ;
$title_fr = empty( $instance['title_fr'] ) ? '' : $instance['title_fr'] ;
// THIS PART CAN BE GREATLY OPTIMIZED
$lingo = qtrans_getLanguage();
if ( 'en' == $lingo )
$title = $title_en;
else
$title = $title_fr;
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
// Use current theme search form if it exists
get_search_form();
echo $after_widget;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title_en' => '', 'title_fr' => '') );
$title_en = $instance['title_en'];
$title_fr = $instance['title_fr'];
?>
<p><label for="<?php echo $this->get_field_id('title_en'); ?>"><?php _e('Title English:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title_en'); ?>" name="<?php echo $this->get_field_name('title_en'); ?>" type="text" value="<?php echo esc_attr($title_en); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('title_fr'); ?>"><?php _e('Title Fran?ais:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title_fr'); ?>" name="<?php echo $this->get_field_name('title_fr'); ?>" type="text" value="<?php echo esc_attr($title_fr); ?>" /></label></p>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args((array) $new_instance, array( 'title_en' => '', 'title_fr' => ''));
$instance['title_en'] = strip_tags($new_instance['title_en']);
$instance['title_fr'] = strip_tags($new_instance['title_fr']);
return $instance;
}
}
It renders:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…