I'm interested how should I approach creating a language switcher like countries switcher?

The idea is that I wish to have country specific content and restrictions (just like with languages) but I want to allow all languages for every country.

Ideally I'd need to have the country value as a global variable and even in the cookies. A great bonus would be if I could assign it to the url like languages (../en/.. -> --/us/en/..) without ruining routing for core or path auto/url aliases etc..

But I don't know how and where to start and can't even find materials on people having done anything similar before.

My train of thought here would be the following:

  • Create custom module
    • Create a countries database/list
    • Set the country as a global variable somehow
    • Set the country as a cookie and fetch on every page load (or if possible to and from url)
    • Create the selector widget

Any ideas how to better understand what I'm facing and recommendations for tackling this? Also a lot of big corporations have location selectors with that locations languages which restrict content, how is this not possible with Drupal? (Couldn't even find anything for D7)


This is a typical use case for domain access:


This module includes a domain switcher, which would be the selector widget you asked for. There is only a dev version for D8. This is a heavy weight module and until now I did avoid using it in D8 and did some custom coding for the functionality I need. To get some ideas I would investigate this module.

  • Thank you for you input, however this is not exactly what I'm looking for. I'm looking for a "language switcher" only for countries, where I can use the country variable globally for determining what sort of data to display. Almost like having a country names taxonomy terms list and having one of them retrievable for the user either in cookie or url, that is globally accessible. I'd only be using 1 domain name and no sub domains. – Alari Truuts Jun 18 '16 at 16:47
  • Domain access contains all this functionality. You would only have another detection priority for the location. To set global variables or config options use settings.php. Then you have to code access to content with this options. You can see all this in domain access. – 4k4 Jun 18 '16 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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