Hello,

My aim is to show a Dutch site when someone goes to www.example.nl and to show an English site when one goes to www.example.com. But after a lot of trial and error I have not managed to do this.

I am using Drupal 7. I have translated my site via entity translation.

I have added www.example.nl and www.example.com to my hosts file.

And this to my apache2.conf (Linux MInt):

DocumentRoot /var/www/html/drupal-7.33
ServerName example.com


DocumentRoot /var/www/html/drupal-7.33
ServerName example.nl

When I go to languages --> detection and selection, URL and set it to domain then I get the following error:

Notice: Undefined property: stdClass::$domain in locale_language_url_rewrite_url() (line 437 of /var/www/html/drupal-7.33/includes/locale.inc).

I can open example.nl, but then I get the English default version. How can I change this?

Thanks,
Mariska.

Comments

iliphil’s picture

I think the domain and url detection methods are are look for prefixes nl.example.com and en.example.com. But a simple module should work to ovverride what drupal does: (I haven't tested this)


/*
how to make a module
https://www.drupal.org/node/1074362
call this module customlangneg
and put this in it
*/

function customlangneg_language_negotiation_info_alter(&$negotiation_info) {
  // Replace the core function with our own function.
  module_load_include('language', 'inc', 'language.negotiation');
  $negotiation_info[LANGUAGE_NEGOTIATION_URL]['callbacks']['language'] = 'customlangneg_from_url';
  $negotiation_info[LANGUAGE_NEGOTIATION_URL]['file'] = drupal_get_path('module', 'customlangneg') . '/customlangneg.module';
}

function customlangneg_from_url($languages) {
  // you should Use the core URL language negotiation provider to get a valid language code,
  // but this code doesn't do that. It does the load though because who knows what might happen without it..
  module_load_include('language', 'inc', 'language.negotiation');
  // $langcode = language_from_url($languages);
// do a simple host compare instead
    if((PHP_URL_HOST == 'www.example.nl') || (PHP_URL_HOST == 'example.nl')) $langcode = 'nl';
    else $langcode = 'en';
 
  return $langcode;
}
MariskaTh’s picture

I just saw your reply. Thanks for your effort. I didn't work, not sure whenther it was the code or me that caused the error. I got the following error (and the language didn't change). But I liked turning your code in a module. I didn't do something like that before :-)

'Notice: Use of undefined constant LANGUAGE_NEGOTIATION_URL - assumed 'LANGUAGE_NEGOTIATION_URL' in customlangneg_language_negotiation_info_alter() (line 14 of /var/www/html/drupal-7.33/sites/all/modules/customlangneg/customlangneg.module).
Notice: Use of undefined constant LANGUAGE_NEGOTIATION_URL - assumed 'LANGUAGE_NEGOTIATION_URL' in customlangneg_language_negotiation_info_alter() (line 15 of /var/www/html/drupal-7.33/sites/all/modules/customlangneg/customlangneg.module).
Notice: Use of undefined constant LANGUAGE_NEGOTIATION_URL - assumed 'LANGUAGE_NEGOTIATION_URL' in customlangneg_language_negotiation_info_alter() (line 14 of /var/www/html/drupal-7.33/sites/all/modules/customlangneg/customlangneg.module).
Notice: Use of undefined constant LANGUAGE_NEGOTIATION_URL - assumed 'LANGUAGE_NEGOTIATION_URL' in customlangneg_language_negotiation_info_alter() (line 15 of /var/www/html/drupal-7.33/sites/all/modules/customlangneg/customlangneg.module).

However, at the moment I don't care so much about one language for one domain aymore. But I would do think it is important that www.example.nl at least starts on a Dutch page. I think the only solution is to have Dutch as the default language for example.nl and English for example.com. But I already have many pages in Dutch, can I still change the default language?

If someone has any suggestions for me, I would love hearing them.

Beste regards,
Mariska.

MariskaTh’s picture

I found a solution, although I don know whether it is good.

- I enabled Domain Access and Domain Variables again.
- I set Dutch as the default language for example.nl
- I made a domain switcher with views

So when one presses on the Dutch flag, the website goes to www.example.nl. Which is fully Dutch.
When one presses on the English flag, the website goes to www.example.com. Here it is possible to get the Dutch language too when one tries www.example.com/nl But by pressing the English flag one goes back to www.example.com.

I hope there are no major satbacks to this...

The opnly problem I see is that when one changes languages one has to start at the beginning of the website again. So when you enter at www.example.nl/webshop/sleutelhangers and want to switch to English, then you are redirected to www.example.com and not to www.example.com/webshop/key_chains

Is there is way to solve that?

Best regards,
Mariska.

pipicom’s picture

Hello Mariska,

How did you manage to do this???
My case is several domains and languages (8). I have installed Domain Access but not Domain Variables.
When I visit example.nl I can see the Dutch translation; I can even navigate between several translations. By clicking the language switcher (I use Language switcher dropdown for this reason), I can navigate between example.nl/node/1, example.de/node/1, example.co.uk/node/1 etc.

The problem is that I need 2 languages for the Belgian website, that is example.be/fr/node/1 and example.be/nl/node/1. I can have either of these 2 version but NOT both of them. It seems that the order of the languages @ admin/config/regional/language affects which of the 2 versions will be available. Also I used "Domain prefix" @ admin/config/regional/language/configure/url.

Could you please share the way you achieved the "www.example.com/nl" result??

Thank you in advance

filtermusic.net

Jaypan’s picture

Looks like the constant is supposed to be LOCALE_LANGUAGE_NEGOTIATION_URL

MariskaTh’s picture

Tried that too and I didn't get the errors anymore. But it didn't change anything either. But maybe I'm doing something wrong.