We have built and manage an existing multilingual site at www.debgroup.com/en but we are currently working on an update that will add in a few extra languages. This includes regionalised sites for Canada (French) and Belgium (Dutch). I proposed to use path prefixes 'ca-fr' and 'be-nl' but I have been asked to look in to the feasibility of using a "multipart prefix" like 'ca/fr' that contains a forward slash (like this Apple website: http://www.apple.com/ca/fr/).

It is possible to enter the prefix 'ca/fr' as a custom language in to the interface at /admin/settings/language/add but I get a page not found as soon as I switch to that language.

I looked at includes/language.inc and see that the root of the problem lies with the language_initialize() function that takes the URL and explodes it in to separate arguments on the forward slash - hence breaking up the prefix and not being able to find the right page.

Around line 35 of includes/language.inc:

    case LANGUAGE_NEGOTIATION_PATH:
      // $_GET['q'] might not be available at this time, because
      // path initialization runs after the language bootstrap phase.
      $args = isset($_GET['q']) ? explode('/', $_GET['q']) : array();
      $prefix = array_shift($args);
      // Search prefix within enabled languages.
      foreach ($languages as $language) {
        if (!empty($language->prefix) && $language->prefix == $prefix) {
          // Rebuild $GET['q'] with the language removed.
          $_GET['q'] = implode('/', $args);
          return $language;
        }
      }

Does any one have any experience with working with multilingual sites with prefixes like this? Any advice to offer?

Thanks
Paul

Comments

nsciacca’s picture

I need the same functionality as described above. Should this be moved to a support request in the core Drupal issue queue?

If you need a workaround and don't mind editing the core, this code can be utilized. It keeps the default behavior for non-slash languages but adds a second check to see if the first two arguments together match the language prefix.

language.inc - line 35

<?php
    case LANGUAGE_NEGOTIATION_PATH:
      // $_GET['q'] might not be available at this time, because
      // path initialization runs after the language bootstrap phase.
      $args = isset($_GET['q']) ? explode('/', $_GET['q']) : array();

	  // Fri Nov 12 14:48:22 EST 2010 NSciacca: our language prefix is the first two arguments
      $prefix1 = $args[0].'/'.$args[1];

	  $prefix = array_shift($args);
	
      // Search prefix within enabled languages.
      foreach ($languages as $language) {
        if (!empty($language->prefix) && $language->prefix == $prefix) {
          // Rebuild $GET['q'] with the language removed.
          $_GET['q'] = implode('/', $args);
          return $language;
        }
		// Fri Nov 12 14:50:53 EST 2010 NSciacca: add case for double prefix
		if (!empty($language->prefix) && $language->prefix == $prefix1) {
          // Rebuild $GET['q'] with the language removed.
          $prefix = array_shift($args);
          $_GET['q'] = implode('/', $args);
          return $language;
        }
      }
      if ($mode == LANGUAGE_NEGOTIATION_PATH_DEFAULT) {
        // If we did not found the language by prefix, choose the default.
        return language_default();
      }
      break;
?>

Without deviation from the norm, progress is not possible. - Frank Zappa