Improve support for the user's language preferences.

I implemented what I suggested in bug 647796: Respecting the user's preferences during the first pass through the matching. Only manipulate the language tags (e.g. by chopping off subtags) if they didn't match the first time around.

I've also consolidated some of the code that was doing the same thing 3 different ways, so that it all only gets done once. (I didn't attempt to solve the code duplication between devmo and sumo, but someone probably should in the future.)

I haven't actually tested these changes because of the hassle of setting up a kuma instance, but I did update and add tests related to the functionality, so it should be immediately clear if things go wrong.