Localization - override the browser default the FIRST time
Posted on 2006-05-12
I have localization setup in a page and it's working great. I have 4 resx files for the languages I want, and a dropdown list that allows the user to change the language if they so desire. The default language of the browser is automatically detected and that language is displayed to the user.
However, I don't want this browser detection to take place, or rather, I want to override it. For each of my users, I have a language ID stored for them in the DB. When they come to the page, I want to display it in the language setting I have for them in the DB, independent of what their browser default is. (This is so that a Spanish speaking user in a coffee shop in China will see the page load in Spanish the FIRST time.)
Currently, I can't see any way to do this. The Spanish user in China would see the page load in Chinese FIRST, and then have to manually change a dropdownlist in order to see it in Spanish. This kind of makes the language settings I've stored in the DB useless, as they're always overriden by the browser.
The technical problem is that for localization code, you have to override the Page.InitializeCulture() method. This method happens so early in the page lifecycle that I don't yet know what user is viewing the page (encrypted query string data), and I have no way of setting the language accordingly.
Thanks for your insight.