mozilla/kitsune — pull request #2084 by mythmon (2014-08-23 02:20:07+00:00)
Title: [Bug 1052191] Add GeoIP based locale suggestion.

When any page loads, we will make a request to Mozilla GeoIP server (geo.mozilla.org). Then a script checks that country in combination with the current locale, and compares it against a list of "problem" locale/country pairs.

If the locale/country pair is deemed problematic, we suggest another locale for the user, in the form of an announcement at the top of the page. This announcement is translated into the suggest language, and also shown in the current language, with "Yes" and "No" button in each language. If there is no translation, only one set is shown. This choice is remembered if the user interacts with the UI.

This does the localization of those features on the server, via an extra AJAX request, because the client doesn't have the strings to localize the other language.

### FAQ:

> But won't this slow down our page loads?

A bit, but Geodude, the software running at geo.mozilla.org, is designed to be really fast, so hopefully it won't have a large impact.

> Won't this show up too late or too subtly for users to notice, and so not do anything?

Maybe! My thought is to deploy this, and see if it affects the bounce rate in the problem countries. This time, we have a clear goal in mind so we can see if it works or not.

> Woah, every sumo page view? Isn't that going to crush Geodude with so many requests?

Nope. Geodude is a rock type Pokemon, so is incredibly hard to crush. Additionally, geo.mozilla.org is used by Snippets, the default home page of Firefox. According to @Osmose and jakem in IRC, Geodude should be able to handle a few orders of magnitude more than the amount of traffic we are sending it's way, and even at that level, the load testers were what gave out, not Geodude.

### Testing.

I have a few bits of code in their that make things easier to test.

1. If you put `?country_name=Pirate` as a querystring, you can override the GeoIP detection, and test without traveling to a foreign country.
2. The Pirate locale is currently marked as language to suggest switching to, so we don't have to wait on localization to test.

We may want to remove these after review, or keep them in until we are sure this works, or forever. I don't know yet.

### To test

0. Checkout this branch.
1. `./scripts/test_locales.sh` to extract/merge/translate the new strings into Pirate, so testing is easier.
2. Go to any SUMO page in English, and observe that it looks normal.
3. Add `?country_name=Pirate` to the end of the URL. Observe the two shiny announcements at the top, inviting you to switch.
4. Try a few things
* Click the "Yes" buttons. They should make you go to Pirate. You should stay on Pirate as you browse around.
* click the "No" buttons and the close "X". The bar should go away, and never come back.
* NB: You can use `localStorage.setItem(localStorage.key(1), 'false')` in your console to make the bar come back.
5. Try it with `country_name=Indonesia` on a KB page that has been translated to Indonesian. May I suggest `/kb/get-started-firefox-overview-main-features`, since (at least in my DB) it has an Indonesian translation. It should switch you to the Indonesia version of both the UI and the article.

:factory: Woah. That's a lot of stuff. I think that's everything though.

r?