Page 1 of 1

W3C validation error since last upgrade

PostPosted: Mon Jul 20, 2009 7:10 pm
by DJ NightLife
Hello,

I have the following W3C error on the home of my website (http://www.djnightlife.com):

line 433 column 40 - Erreur: ID "qtranslate-3" already defined
line 432 column 9 - Info: ID "qtranslate-3" first defined here

id defined twice... how may i fix it?

Re: W3C validation error since last upgrade

PostPosted: Tue Jul 21, 2009 10:36 pm
by DJ NightLife
Anyone?

Plus, is it possible to display "English" when site is in french and vice versa instead of always displaying both ?

Thanks !

Re: W3C validation error since last upgrade

PostPosted: Wed Jul 22, 2009 7:21 pm
by jstar198
DJ NightLife wrote:line 433 column 40 - Erreur: ID "qtranslate-3" already defined
line 432 column 9 - Info: ID "qtranslate-3" first defined here

Having exactly the same problem and posted in the forum but no one seemed to care... validation is important!!
Anyway to fix it you need to edit the qtrans_generateLanguageSelectCode function in qtranslate_widget.php.

Re: W3C validation error since last upgrade

PostPosted: Fri Jul 24, 2009 8:33 am
by extremecarver
jstar198 wrote:
DJ NightLife wrote:line 433 column 40 - Erreur: ID "qtranslate-3" already defined
line 432 column 9 - Info: ID "qtranslate-3" first defined here

Having exactly the same problem and posted in the forum but no one seemed to care... validation is important!!
Anyway to fix it you need to edit the qtrans_generateLanguageSelectCode function in qtranslate_widget.php.

So would you care to explain what to edit?

Re: W3C validation error since last upgrade

PostPosted: Sat Jul 25, 2009 8:20 am
by DJ NightLife
Just noticed another plugin in my sidebar cause the same error, maybe it is not related...

http://www.djnightlife.com/ Check the validation console.

Re: W3C validation error since last upgrade

PostPosted: Sat Jul 25, 2009 6:49 pm
by coldjippie
Hey!

You can fix this bug if you add a string after the id="[...]" declaration. Just like this: id="[...]x"

I've updated my qtranslate_widget.php in the /wp-content/plugins/qtranslate folder:

Code: Select all
<?php // encoding: utf-8

/*  Copyright 2008  Qian Qin  (email : mail@qianqin.de)

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/* qTranslate Widget */

class qTranslateWidget extends WP_Widget {
   function qTranslateWidget() {
      $widget_ops = array('classname' => 'widget_qtranslate', 'description' => __('Allows your visitors to choose a Language.','qtranslate') );
      $this->WP_Widget('qtranslate', __('qTranslate Language Chooser','qtranslate'), $widget_ops);
   }
   
   function widget($args, $instance) {
      extract($args);
      
      echo $before_widget;
      $title = empty($instance['title']) ? __('Language', 'qtranslate') : apply_filters('widget_title', $instance['title']);
      $hide_title = empty($instance['hide-title']) ? false : 'on';
      $type = $instance['type'];
      if($type!='text'&&$type!='image'&&$type!='both'&&$type!='dropdown') $type='text';

      if($hide_title!='on') { echo $before_title . $title . $after_title; };
      qtrans_generateLanguageSelectCode($type, $this->id);
      echo $after_widget;
   }
   
   function update($new_instance, $old_instance) {
      $instance = $old_instance;
      $instance['title'] = $new_instance['title'];
      $instance['hide-title'] = $new_instance['hide-title'];
      $instance['type'] = $new_instance['type'];

      return $instance;
   }
   
   function form($instance) {
      $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'hide-title' => false, 'type' => 'text' ) );
      $title = $instance['title'];
      $hide_title = $instance['hide-title'];
      $type = $instance['type'];
?>
      <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'qtranslate'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
      <p><label for="<?php echo $this->get_field_id('hide-title'); ?>"><?php _e('Hide Title:', 'qtranslate'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('hide-title'); ?>" name="<?php echo $this->get_field_name('hide-title'); ?>" <?php echo ($hide_title=='on')?'checked="checked"':''; ?>/></label></p>
      <p><?php _e('Display:', 'qtranslate'); ?></p>
      <p><label for="<?php echo $this->get_field_id('type'); ?>1"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>1" value="text"<?php echo ($type=='text')?' checked="checked"':'' ?>/> <?php _e('Text only', 'qtranslate'); ?></label></p>
      <p><label for="<?php echo $this->get_field_id('type'); ?>2"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>2" value="image"<?php echo ($type=='image')?' checked="checked"':'' ?>/> <?php _e('Image only', 'qtranslate'); ?></label></p>
      <p><label for="<?php echo $this->get_field_id('type'); ?>3"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>3" value="both"<?php echo ($type=='both')?' checked="checked"':'' ?>/> <?php _e('Text and Image', 'qtranslate'); ?></label></p>
      <p><label for="<?php echo $this->get_field_id('type'); ?>4"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>4" value="dropdown"<?php echo ($type=='dropdown')?' checked="checked"':'' ?>/> <?php _e('Dropdown Box', 'qtranslate'); ?></label></p>
<?php
   }
}

// Language Select Code for non-Widget users
function qtrans_generateLanguageSelectCode($style='', $id='qtrans_language_chooser') {
   global $q_config;
   if($style=='') $style='text';
   if(is_bool($style)&&$style) $style='image';
   switch($style) {
      case 'image':
      case 'text':
      case 'dropdown':
         echo '<ul class="qtrans_language_chooser" id="'.$id.'x">';
         foreach(qtrans_getSortedLanguages() as $language) {
            echo '<li';
            if($language == $q_config['language'])
               echo ' class="active"';
            echo '><a href="'.qtrans_convertURL('', $language).'"';
            // set hreflang
            echo ' hreflang="'.$language.'"';
            if($style=='image')
               echo ' class="qtrans_flag qtrans_flag_'.$language.'"';
            echo '><span';
            if($style=='image')
               echo ' style="display:none"';
            echo '>'.$q_config['language_name'][$language].'</span></a></li>';
         }
         echo "</ul><div class=\"qtrans_widget_end\"></div>";
         if($style=='dropdown') {
            echo "<script type=\"text/javascript\">\n// <![CDATA[\r\n";
            echo "var lc = document.getElementById('".$id."');\n";
            echo "var s = document.createElement('select');\n";
            echo "s.id = 'qtrans_select_".$id."';\n";
            echo "lc.parentNode.insertBefore(s,lc);";
            // create dropdown fields for each language
            foreach(qtrans_getSortedLanguages() as $language) {
               echo qtrans_insertDropDownElement($language, qtrans_convertURL('', $language), $id);
            }
            // hide html language chooser text
            echo "s.onchange = function() { document.location.href = this.value;}\n";
            echo "lc.style.display='none';\n";
            echo "// ]]>\n</script>\n";
         }
         break;
      case 'both':
         echo '<ul class="qtrans_language_chooser" id="'.$id.'x">';
         foreach(qtrans_getSortedLanguages() as $language) {
            echo '<li';
            if($language == $q_config['language'])
               echo ' class="active"';
            echo '><a href="'.qtrans_convertURL('', $language).'"';
            echo ' class="qtrans_flag_'.$language.' qtrans_flag_and_text"';
            echo '><span>'.$q_config['language_name'][$language].'</span></a></li>';
         }
         echo "</ul><div class=\"qtrans_widget_end\"></div>";
         break;
   }
}

function qtrans_widget_init() {
   register_widget('qTranslateWidget');
}

?>




Cheers,

coldjippie

Re: W3C validation error since last upgrade

PostPosted: Sun Aug 23, 2009 9:57 am
by jstar198
I wrote a small plugin to apply this patch automatically, refer here: http://johnjcamilleri.com/?p=82
Let me know if you use it & if you have any problems!

Re: W3C validation error since last upgrade

PostPosted: Sat Jul 31, 2010 9:13 am
by madmax
DJ NightLife wrote:Anyone?

Plus, is it possible to display "English" when site is in french and vice versa instead of always displaying both ?

Thanks !


Thisi is an old topic, but if someone is serching for this answer right now (like I did), here is my solution:
Code: Select all
<ul>
<?php foreach(qtrans_getSortedLanguages() as $language) :?>
   <?php if ($language != qtrans_getLanguage())://exclude current language?>
      <li id="contentlang-".$language>
         <a href="<?php echo qtrans_convertURL('',$language);?>">
            <img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $language ?>.png"/>
         </a>
      </li>
   <?php endif;?>
<?php endforeach;?>
</ul>

With the code above you have to create flag images with names like fr.png, en.png etc etc.