Hi,
something I'Ve come accross building multi-domain i18n Drupal 6.x websites, is the lack of domain (or site) specific language prefixing. Let me elaborate. Imagine
a multisite intall with English and French languages installed. Using the domain module (or multisite setup) we prepare a multisite with two domains, domain.ca (Canada) and domain.fr (France).
This is what you want to achieve:
- domain.ca -> default English
- domain.ca/fr -> French language for Canada, with /fr prefix
- domain.fr -> default French language without a prefix
Also, English should be fully disabled on domain.fr.
The idea is to re-use the French language for both sites - this reduces language maintenance. (You could of course install a custom language fr_CA for Canada, but that means you have 2 French language to maintain translations).
In Drupal 6 I did come up with my custom solution. A core hack. Yes, many kittens died. Pre-requisites: Domain Access module.
Hack goes into language.inc:
/**
* Choose a language for the page, based on language negotiation settings.
*/
function language_initialize() {
// START HACK: domain-specific language prefixes hack
global $user, $_domain, $conf;
// END HACK
// Configured presentation language mode.
$mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
// Get a list of enabled languages.
$languages = language_list('enabled');
$languages = $languages[1];
// START HACK
$domain_id = $_domain['domain_id'];
if ($conf['domain_prefixes'][$domain_id]) {
$available = array();
foreach ($conf['domain_prefixes'][$domain_id] as $key => $value) {
$available[] = $key;
// set the domain-specific language prefix
$languages[$key]->prefix = $value;
$languages[$key]->domain = ''; // leave empty
}
foreach($languages as $key => $object) {
if (!in_array($key, $available)) {
// prevent duplicate content / paths
unset($languages[$key]);
}
}
}
// END HACK
// the rest of language.inc
Then in settings.php, I maintain a custom $conf['domain_prefixes']:
$conf = array(
'domain_prefixes' => array(
'2' => array('nl' => ''), // Nederland
'3' => array('de' => ''), // Deutschland
'4' => array('fr' => ''), // France
'5' => array('es' => '', 'ca' => 'ca'), // España
'6' => array('it' => ''), // Italia
'7' => array('en' => ''), // United Kingdom
'8' => array('ja' => ''), // 日本
'9' => array('en' => '', 'fr' => 'fr'), // Canada
'10' => array('nl' => '', 'fr' => 'fr'), // België / Belgique
'11' => array('en' => '', 'hi' => 'hi'), // India
)
);
Language.inc will "feel" the domain and spit out the correct available languages. Three issues are solved:
1. domain-specific language prefixes
2. disable unwanted languages per domain
3. full compatibility, e.g. pathauto works, i18ntaxonomy works
I'm hoping this (or similar) could go into Drupal 7! Highly needed for enterprise level i18n sites.
P.S. In case you wonder why I don't simply use a custom module with a hook_boot() to alter the $languages? The answer is that does not work, because the Drupal path is checked for validity before the hook_boot alters anything. (So you can indeed change $langauges via hook_boot, set a custom prefix like '/custom', but it will hit 404 because Drupal thinks the path does not exist).
Comments
Comment #1
plachUnfortunately Drupal 7 went feature-frozen several months ago. However it ships a new language negotiation API that might allow you to solve the described issue without hacking core. You might want to check: http://drupal.org/update/modules/6/7#language_negotiation.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedOk, thanks. I'll check it out for D7 for a future project (once 7 is stable). I'll come back to this thread to post what solution I come up with.
Comment #3
Gábor HojtsyYes, you should be able to fully rely on the new negotiation API. I don't think this will ever be implemented in Drupal core given the specialty of it.