Add country store and language detection

RESOLVED FIXED in 2012-07-12


6 years ago
6 years ago


(Reporter: clouserw, Assigned: cvan)




(Whiteboard: [fat])



6 years ago
Questions we need to be able to determine for each user include (1) What country store should they be visiting? and (2) What language should the pages be in? We allow people to choose their own country stores if they would like but we should have appropriate defaults for the 99.x% of people who don't need to visit another store. I've written pseudocode to help make it more clear:

> # What store are you in?
> if cookies[store] and store_is_valid(cookies[store]):
>     store = cookies[store]
> else
>     store = geolocate_user()
>     cookies[store] = store
> if cookies[language] and language_is_valid(cookies[language]):
>     language = cookies[language]
> else:
>     for i in pull_languages_from_accept_headers():
>         if language_is_valid(i):
>             language = i
>             break
>     if not language:
>         language = store['default_language']

I think everything in the above code is self explanatory except for geolocate_user(). That's a little bonus that glosses over a bit of logic. :)

Our geolocation solution is a binary database file. You should put a constant in our settings file to point to a file on disk so we don't have to check it in to the repo. You can get a free demo file here ( We also own (purchased) the full file and once we deploy we'll flip to using that. Anyway, MaxMind has a library for python ( which sounds like a pain in the ass, but they also link to which sounds way friendlier for deployment (pure python). Please use that library and hook it up to the geo-database file.[1]

Once you have a response from the geo-ip db check if the store exists on marketplace, otherwise they are sent to the generic store.

[1] Alright, so you're all excited to get going and you found out the full geoip db is a few hundred MB. Yeah, I'm not excited about opening that file for every visitor to the store either but metrics says that it is very fast lookups. The MMAP_CACHE flag when opening it will let us not load the whole thing into memory which I think will work fine for us. If not, we can experiment but this is a place to start.



6 years ago
Priority: -- → P1


6 years ago
Assignee: nobody → cvan
Target Milestone: --- → 2012-07-12

Comment 1

6 years ago

* Removed /<locale>/ prefixed URLs and associated redirects.
* Added cookie-based locale detection (via `Accept-Language` or user choice).
* Added cookie-based region store detection (via `Accept-Language` or user choice).

* Do IP-based geolocation. (Scared!)
I reverted b/c this removes `request.APP`, which breaks lots of templates and template helpers. The dev hub and reviewers were throwing 500 errors.


6 years ago
Target Milestone: 2012-07-12 → 2012-07-19

Comment 4

6 years ago
Geolocation is now bug 774746

Comment 5

6 years ago
Closed. Do IP-based geolocation lookups in bug 774746.
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: 2012-07-19 → 2012-07-12
You need to log in before you can comment on or make changes to this bug.