How to go about creating location selector: a languages like "countries" global variable? 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:

https://www.drupal.org/project/domain

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.