My understanding is that when you set CurrentThread.CurrentUICulture to for instance “da-DK” it will look for resource files in “da-DK”, then “da”, then fall back to the invariant culture. This works well for Desktop applications, because operating systems are not typically multi-lingual. For websites however this is not necessarily the case.
Let say I have a visitor whose browser insists the user wants “da_DK”, “de_DE” and “en_GB”, that is Danish if it exists, then German, then British English as a fallback.
Is there any way to accommodate this preference using the .Net 4 localization framework?
And no, this is not a thought experiment. 🙂
EDIT
Just to be clear, the problem is not getting the localization headers from the web request. The problem is setting the CurrentThread.CurrentUICulture in such a way that it will check resource files in order, rather than just checking for one.
Alternatively a way to check whether the CurrentUICulture has matching resx files.
I think this is what you are after :
HttpRequest.UserLanguages()
This returns the array of user languages in preference order. Probably a good idea to allow them to change whatever localization you apply against this information, however, in case their browser configuration does not accurately reflect what they really want.
Update :
To check if the resources exist use :
ResourceManager.GetResourceSet
Here you can set
tryParentsto false. The method will returnnullif no resources exist. You can then proceed to try the next preferred culture returned in the header.