WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Gengo] Select Language Hack (1 post)

  1. timtak
    Member
    Posted 4 years ago #

    If you have more than one language on your blog then it is possible to display all the languages as it seems sensible to do, to new visitors.

    Alas however, the "gengo_display_languages" tag in gengo_template_functions.php only displays a link to select a language if the language is not already selected. It should display links if the language is not *UNIQUELY* selected

    E.g. let us say you have 100 English posts and 10 French Posts on your blog and a French person comes to the splash page which is set to display blogs in both languages. "Quoi?" He says, because he is faced with a blog *mainly* in English, and he goes to select French ONLY but he can not, because French is already one of the languages selected.

    In addition to "is_set_language" I guess there should be another function "is_uniquely_set_language" since it is only when this is true that we do not want links.

    Anyway, I hacked gengo to always display the link to select language (even if uniqulely selected) by changing this code

    function gengo_list_languages($arguments = '') {
    	global $gengo, $wp_rewrite;
    
    	$default_args = array('pre' => '<li>', 'post' => '</li>', 'show_count' => 'true', 'show_current' => 'true', 'show_unreadable' => 'true', 'snippet' => '', 'content_type' => 'post');
      parse_str($arguments, $args);
      $args = array_merge($default_args, $args);
    
    	if (!$gengo->languages) {
    		echo $args['pre'] . __('No Languages Defined', GENGO_DOMAIN) . $args['post'];
    	} else {
    		$titles = ($args['snippet']) ? $gengo->get_synblocks($args['snippet']) : array();
    		$home = trailingslashit($gengo->site_home);
    		if ($wp_rewrite->using_index_permalinks()) $home .= $wp_rewrite->index;
    		$totals = $gengo->get_totals($args['content_type']);
    		asort($gengo->languages);
    		foreach ($gengo->languages as $language_id => $entry) {
    			if ($post_count = $totals[$language_id]) {
    			  if ('false' != $args['show_count']) $count_string = " ($post_count)";
    			  $gengo->forced_append = true;
    				if (('false' != $args['show_unreadable']) || (false !== strpos($gengo->viewable_code_string, $entry->code))) {
    	  			$title = $titles[$language_id] ? $titles[$language_id] : $entry->language;
    					if (false === $gengo->is_set_language($language_id)) {
    						echo "$args[pre]<a class=\"gengo_lang_$entry->code\" href=\"" . $gengo->append_link_language($home, $entry->code) . "\" hreflang=\"" . $entry->code . "\">$title</a>$count_string$args[post]";
    					} else {
    					  if ('false' != $args['show_current']) {
    							echo "$args[pre]<span class=\"gengo_lang_$entry->code\">$title$count_string</span>$args[post]";
    						}
    		 			}
    				}
    			}
    		}
    	}
    }

    to this code

    function gengo_list_languages($arguments = '') {
    	global $gengo, $wp_rewrite;
    
    	$default_args = array('pre' => '<li>', 'post' => '</li>', 'show_count' => 'true', 'show_current' => 'true', 'show_unreadable' => 'true', 'snippet' => '', 'content_type' => 'post');
      parse_str($arguments, $args);
      $args = array_merge($default_args, $args);
    
    	if (!$gengo->languages) {
    		echo $args['pre'] . __('No Languages Defined', GENGO_DOMAIN) . $args['post'];
    	} else {
    		$titles = ($args['snippet']) ? $gengo->get_synblocks($args['snippet']) : array();
    		$home = trailingslashit($gengo->site_home);
    		if ($wp_rewrite->using_index_permalinks()) $home .= $wp_rewrite->index;
    		$totals = $gengo->get_totals($args['content_type']);
    		asort($gengo->languages);
    		foreach ($gengo->languages as $language_id => $entry) {
    			if ($post_count = $totals[$language_id]) {
    			  if ('false' != $args['show_count']) $count_string = " ($post_count)";
    			  $gengo->forced_append = true;
    				if (('false' != $args['show_unreadable']) || (false !== strpos($gengo->viewable_code_string, $entry->code))) {
    	  			$title = $titles[$language_id] ? $titles[$language_id] : $entry->language;
    	  			//timtak this is incorrect, since it only displays the links if the
    	  			//language is completely unset, even if it is one of several languages.
    				//	if (false === $gengo->is_set_language($language_id)) {
    						echo "$args[pre]<a class=\"gengo_lang_$entry->code\" href=\"" . $gengo->append_link_language($home, $entry->code) . "\" hreflang=\"" . $entry->code . "\">$title</a>$count_string$args[post]";
    				//	} else {
    				//	  if ('false' != $args['show_current']) {
    				//			echo "$args[pre]<span class=\"gengo_lang_$entry->code\">$title$count_string</span>$args[post]";
    				//		}
    		 		//	}
    				}
    			}
    		}
    	}
    }

    http://wordpress.org/extend/plugins/gengo/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags