1

I have a question regarding the domain name language negotiation.

I have 3 languages and the following domains:

  • de.domain.com
  • en.domain.com
  • fr.domain.com

When I set this as the domains for each language and use the domain name language negotiation everything works as expected.

My problem is that I have an adaptive mobile theme and I have to use following domains for that:

  • m.de.domain.com
  • m.en.domain.com
  • m.fr.domain.com

How can I achieve that those urls point to the correct language (de, en, fr). Now, all point to the default language (de).

Any help?

7
  • Just curious - why m prefix? Can't you detect from http headers if user is on mobile? Can't your theme hide things based on actual screen it gets displayed on?
    – Mołot
    Commented Aug 20, 2013 at 7:54
  • In my oppinion its not a good thing to have different content served from the same url. think about a caching in front of the web server (varnish for example). Commented Aug 20, 2013 at 8:14
  • That's some valid point all right. On the other hand current mobile devices can usually accept normal page and you can do the most of small-screen logic in CSS with media set to handheld.
    – Mołot
    Commented Aug 20, 2013 at 8:17
  • That's totally true. But the customer has preferred adaptive over responsive for this project. So i have to deal with that now. Responsive would make my live easier at all ;) Commented Aug 20, 2013 at 8:26
  • can you make it de.m. instead of m.de.? If it's technically impossible / not easy, it's a shame both mechanisms insist on using first part for detection.
    – Mołot
    Commented Aug 20, 2013 at 8:31

1 Answer 1

1

Take a look at the Language Negotiation API, specifically hook_language_negotiation_info_alter. With this hook, you can replace the default URL based language negotiation callback function with one that respects the m. prefix.

Something like this should get you started.

function mymodule_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'] = 'mymodule_from_url';
  $negotiation_info[LANGUAGE_NEGOTIATION_URL]['file'] = drupal_get_path('module', 'mymodule') . '/mymodule.module';
}

function mymodule_from_url($languages) {
    // Your version of locale_language_from_url() that ignores the m. prefix.
}

For reference, the core function that handles language negotiation based on URL is locale_language_from_url.

1
  • Thank you zroger. I think this way i can achieve my goal :) Commented Aug 21, 2013 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.