Check Language Filter system plugin, you'll see how they manipulate the url to add language prefix to links. You could use the same method to add location prefix based on cookie value.
Here is what I did, but bear in mind that I had a tricky request, I had to make it work together with language filter plugin AND make the country appear before the language code. Different countries can show the same item and languages are shared accros countries. It works in pair with a custom country extra field plugin for K2, but it's irrelevant for this. What I did is possible only from Joomla 3.4 and higher
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
class PlgSystemCountryFilter extends JPlugin
{
protected $app;
public $countries = array('austria', 'belgium', 'czech-republic', 'poland', 'slovakia', 'ukraine');
public $country;
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
$this->app = JFactory::getApplication();
}
public function onAfterInitialise()
{
if ($this->app->isSite())
{
// country/fr/menus
$path = str_replace(JUri::root(), '', JUri::current());
$parts = explode('/', $path);
if(!empty($parts[0]) && in_array($parts[0], $this->countries)) {
$this->country = $parts[0];
$router = $this->app->getRouter();
$router->attachBuildRule(array($this, 'buildRule'), JRouter::PROCESS_BEFORE);
$router->attachBuildRule(array($this, 'postprocessSEFBuildRule'), JRouter::PROCESS_AFTER);
$router->attachParseRule(array($this, 'parseRule'), JRouter::PROCESS_BEFORE);
}
}
}
public function buildRule(&$router, &$uri)
{
if(!empty($this->country)) {
$parts = explode('/', $uri->getPath());
$lang = array_shift($parts);
$uri->setPath(implode('/', $parts) . '/' . $this->country . '/' . $lang . '/');
}
}
public function postprocessSEFBuildRule(&$router, &$uri)
{
$uri->delVar('sitecountry');
}
public function parseRule(&$router, &$uri)
{
$path = $uri->getPath();
$parts = explode('/', $path);
if(!empty($parts[0]) && in_array($parts[0], $this->countries)) {
$country = $parts[0];
}
$array = array();
if(!empty($country)) {
array_shift($parts);
// if we are supposed to be on the root page /fr, then make it be like /fr/country so that per country homepage can be displayed
// for this to work hidden menu with aliases /country must be created
if(count($parts) == 1) {
$parts[] = $country;
}
$uri->setPath(implode('/', $parts));
$this->app->input->set('sitecountry', $country);
$array = array('sitecountry' => $country);
}
return $array;
}
}