I am looking to create a Spanish translation for ~300 page drupal site. I'd like to use the i18n module, but don't want to change the urls of my English pages for SEO reasons. My urls are currently domain.com/products/overview and I don't want to have the domain.com/en/products/overview alias as part of the site. [i18n seems to automatically assign the en/ prefix to everything]

For the translated site I would like to either use domain.es/products/overview (preffered) or domain.com/es/products/overview

Does anyone know how to kill the en/ for the English version or seen it done elsewhere?

Thanks!

Comments

vm’s picture

may have to use the path.module and create url alias to by pass the/en/ or the pathauto.module

josesanmartin’s picture

I faced a similar issue recently when I wanted to use the code "br" in a URL instead of "pt-br".

I have patched a few lines in i18n.module that allowed me to create a custom language prefix for URLs only, while using the regular language prefix everywhere else, such as in the HTML headers. I don't know if it's going to work with you, since you want a blank custom prefix, which may cause a few problems. You should try, anyway.

The patch for i18n.module's i18n_get_lang_prefix function is:


//Patch here:
function i18n_get_lang_prefix(&$path, $trim = FALSE) {
  $exploded_path = explode('/', $path);
  $path_tail = array_shift($exploded_path);
  if (function_exists('custom_language_url_prefix')) {
    $maybelang = custom_language_url_prefix('dealias', $path_tail);
  } else {
    $maybelang = $path_tail;
  }
  $languages = i18n_languages();
  if (array_key_exists($maybelang, $languages)){
    if ($trim) {
      $path = trim(substr($path, strlen($path_tail)),'/');
    }
    return $maybelang;
  }
}

and for i18n.module's custom_url_rewrite function:


//patch here:
if(!function_exists('custom_url_rewrite')) {
  function custom_url_rewrite($type, $path, $original) {
    $return = i18n_url_rewrite($type, $path, $original);

    if (function_exists('custom_language_url_prefix')) {
      $return = custom_language_url_prefix('alias', $return);
    }

    return $return;
  }
}

Now, all you have to do is to create a function in your settings.php called custom_language_url_prefix. The function below changes "pt-br" into "br" in urls:


//$op may have two values: "alias" and "dealias"
function custom_language_url_prefix($op, $language) {
  if ($op == 'dealias') {
    if ($language == 'br') {
      return 'pt-br';
    } else {
      return $language;
    }
  }

  if ($op == 'alias') {
    if (preg_match('|^pt-br(/.*)|', $language, $matches)) {
      return 'br' . $matches[1];
    } else {
      return $language;
    }
  }
}

To use it in your website, replace "pt-br" with "en" and "br" with blank and tell me later if it works with you.

Regards,

José San Martin
http://www.gare7.org/

José San Martin
http://www.chuva-inc.com/

walden’s picture

I'll give it a shot, thanks