I am using the Drupal i18n module for content translation. Although it sometimes isn't as straight forward in usability as it should be, mostly there's a workaround for a specific problem.
I couldn't find one myself for a certain problem I was having with Drupal clean urls. So I decided to write a simple module for it myself.
On a typical site, you have pages like '/contact', '/help', '/faq', ... that you all want to share the same path for each language (like '/fr/contact', 'en/contact', 'nl/contact', ...). You also want to have a single access point like '/contact' that points to the right translation of that page depending on the current user language.
By default, this is not possible using the i18n module. At least, there's no great solution that I know off.
My workaround is the following. For each language I add the language prefix to the clean url. So when creating my page (or whatever other node type instance), I specify 'fr/contact' and 'en/contact' instead of '/contact'.
This works great for all language specific clean urls; 'fr/contact' points to the french version etc.
But I also want the language independent url, '/contact', to point to the translation of the page in the current language. For this, I had to write a simple module, from which the code is listed below.
This content checks all your clean urls and looks for urls that are prefixed with a language. Those urls get a menu item in the menu hook. This menu item triggers a callback which redirects the user to the page with the right translation. Problem solved!
The disadvantage of this solution is that the user isn't taken straight forward to the requested page, but is rather redirected to it. So the url changes ('/contact' becomes for example '/fr/contact'). Not a big problem for me though ;)
/**
* Implementation of hook_menu().
*/
function multilingual_path_menu($may_cache) {
$items = array();
if (!$may_cache) {
$sql = "SELECT DISTINCT SUBSTR(dst,4) as dst FROM {url_alias} WHERE ";
$languages = i18n_supported_languages();
foreach($languages as $key => $name) {
$subsql[] = "dst LIKE '".$key."/%'";
}
$sql = $sql . implode(' OR ', $subsql);
$result = db_query($sql);
while($path = db_fetch_object($result)) {
if(!drupal_lookup_path('source',$path->dst)) {
$items[] = array(
'path' => $path->dst,
'title' => '',
'callback' => 'multilingual_path_get_path',
'access' => TRUE,
'type' => MENU_CALLBACK
);
}
}
}
return $items;
}
function multilingual_path_get_path() {
drupal_goto($_GET['q']);
}