Support » Plugins » Gengo: Using different domains for different languages

  • On my website I needed to use different domains for the two different languages. This may well also help with SEO, too. I didn’t want to edit Gengo core code, so created a plugin which does the job. If you use it, you’ll need to change the language codes and URLs throughout the plugin. It will only work with two-character language codes.

    Plugin Name: EMW WordPress Hacks
    Version: 0.2
    Plugin URI:
    Description: Various hacks to make the bi-lingual site work with two domains.
    Author: Mark Barnes
    Author URI:
    //Returns the language requested in the URL
    function emw_get_language() {
    	if ($_GET['lang'])
    		return $_GET['lang'];
    	else {
    		$uri = $_SERVER['REQUEST_URI'];
    		$query = $_SERVER['QUERY_STRING'];
    		if (substr($uri, -strlen($query)) == $query)
    			$uri = substr($uri, 0, -strlen($query)-1);
    		return substr(trailingslashit($uri), -3, 2);
    //Updates the WordPress address
    function emw_retain_uri($content) {
    	$code = emw_get_language();
    	if ($code == "en")
    		return "";
    	elseif ($code == "cy")
    		return "";
    		return "http://".$_SERVER['SERVER_NAME'];
    //Redirects the page if wrong domain is used
    function emw_redirect () {
    	$code = emw_get_language();
    	$host = $_SERVER['HTTP_HOST'];
    	if ($code=="en" && $host != "") {
    		header('HTTP/1.1 301 Moved Permanently');
    	elseif ($code=="cy" && $host != "") {
    		header('HTTP/1.1 301 Moved Permanently');
    //Ensures list_pages and similar functions return correct domain name
    // This function requires Gengo to append language links automatically.
    function emw_rewrite_link ($link) {
    	$code = substr($link, -3, -1);
    	if ($code=="en")
    		return str_replace ("", "", $link);
    	elseif ($code=="cy")
    		return str_replace ("", "", $link);
    		return $link;
    //Adds translation widget
    function emw_translation_links($args) {
    	if(function_exists("the_translations")) {
    		echo $before_widget;
    		echo $before_title.$after_title;
    		echo '<div id="change-language">';
    		echo '</div>';
    		echo $after_widget;
    //Registers all custom widgets
    function emw_widget_init() {
    	register_sidebar_widget('Translation Links', 'emw_translation_links');
    add_action('template_redirect', 'emw_redirect');
    add_filter('option_home', 'emw_retain_uri', 1);
    add_filter('option_siteurl', 'emw_retain_uri', 1);
    add_filter('page_link', 'emw_rewrite_link', 101);
    add_filter('post_link', 'emw_rewrite_link', 101);
    add_filter('category_link', 'emw_rewrite_link', 101);
    add_filter('category_feed_link', 'emw_rewrite_link', 101);
    add_action('widgets_init', 'emw_widget_init');

Viewing 1 replies (of 1 total)
  • That’s really nice. I havent’ tested it but sounds good. I’ve posted it in the gengo-hackers mailing list, some people probably is going to test it.

    By the way, I’m actually trying to restart Gengo development after some time. If you have suggestion or ideas (or maybe even code) gengo-related feel free to join us in the list, you’re welcome!

Viewing 1 replies (of 1 total)
  • The topic ‘Gengo: Using different domains for different languages’ is closed to new replies.