To use a sub-domain to specify the locale rather than having it be part of the path. So instead of this:
we want this:
This makes it easier by being able to specify relative paths everywhere that don’t need to have the locale played with. Switching the locale for the site is also just a matter of changing the domain.
That said, r18n expects the locale to be placed in the ‘params’ array for Sinatra so a simple Rack middleware would do this well. So here it is:
Due to many peoples’ habit of putting ‘www’ at the start of the domain, this should account for en.example.com and www.en.example.com. It also allows for the locale to be specified in the query string. So en.example.com/foo?locale=th will set the locale to ‘th’.