2
votes

I have to build a multilingual website where you have to select your continent.

So you can choose America while your are in English but also America in Spanish. Europe in French, but also in English etc.

I have set language detection with path prefix on drupal 7. So my urls are like that domain.com/en/path-alias.

Some contents on my website will be hide for some continent but a lot of content will be the same so I dont want to do a multisite.

I wish to have urls like that domain.com/america/en/path-alias, domain.com/america/es/path-alias or domain.com/europe/fr/path-alias. I don't find any solution to do that.

The module domain access looks cool but is not exactly what i want cause it works with subdomains while i want path prefix.

EDIT : Ok i have found the solution of my problem in the drupal API.

This two hooks are exactly what i was looking for hook_url_inbound_alter, hook_url_outbound_alter

2

2 Answers

0
votes

You should use this 2 hooks because in hook_url_inbound_alter(&$path, $original_path, $path_language) you tell Drupal what path should it display, and determine from received path that comes in $original_path (ex: region/lang/path) path that Drupal understands as a valid path (ex: lang/path) and override $path with it.

Next we need links from our pages to contain our custom path format, so we'll use hook_url_outbound_alter(&$path, &$options, $original_path) to convert all system paths or aliases generated with url() in your custom path format (generated path for url('lang/path')) will be region/lang/path. In $options array we can modify path prefix, or path language.

0
votes

This worked for me but path alias dose not working now. This http://localhost/en/australia/node/376 should be http://localhost/en/australia/hotels-resorts

function mymodule_url_inbound_alter(&$path, $original_path, $path_language){    
  $cluster = 'australia';
  $path = str_replace($cluster.'/','',$path);       
} 

function mymodule_url_outbound_alter(&$path, &$options, $original_path){
  $cluster = 'australia';   
  $path = $cluster.'/'.($path); 
  $options['alias'] = true;     
}