This is a question about setting our website's Language and Culture settings with regards to the settings we read from the user visiting the site.
Let's assume our website supports 2 languages, English (en) and German (de). Let's also assume we want to disregard locale (region) (at least on the server side, so we only know that we support "en" and "de", so we have that specified either in application code, config file or somewhere elese). So we don't care if a user comes from US or UK.
What we are doing is matching "en" or "de" to possible matches in user's browser defined languages/cultures.
The issue I am having is that if I do this
/* Gets Languages from Browser */
IList<string> BrowserLanguages = filterContext.RequestContext
.HttpContext
.Request
.UserLanguages;
we get all sorts of results.
We might receive lists like
en, (for instance Firefox has this), - en-US, - en-UK.
en-US, - en-UK.
en, - de, - it-IT.
de, - en-US, - en.
What I would like to ask here is:
Is it ok to use compare strings here (checking whether "en" exists as a substring)? See sample list 2
Do we have to take the order into account or would you just disregard it?
Am I overcomplicating this? The problem is though that IE and Firefox (and others) have different strings for regional settings (for instance, "sl" in Firefox and "sl-SI" in IE8)
I just want to direct all visitors for which language does not exist to English and all others to their appropriate language (disregarding their location), you might think of it like if we support Portugese (pt) and our visitors come from Portugal and Brazil we will redirect them to Portugese version of the site even if the match is not 100% perfect (we would rather redirect them to Portugese version than English version).