Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 949519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:24:54+00:00 2026-05-15T23:24:54+00:00

This is a question about setting our website’s Language and Culture settings with regards

  • 0

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:

  1. Is it ok to use compare strings here (checking whether “en” exists as a substring)? See sample list 2

  2. Do we have to take the order into account or would you just disregard it?

  3. 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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:24:55+00:00Added an answer on May 15, 2026 at 11:24 pm

    Interesting question. Let me try to answer…

    Is it ok to use compare strings here (checking whether “en” exists as a substring)?

    You could something like this. Note, I am just providing a way that does not use strings, however, I think that in this case substring approach will also work since its simpler.

    CultureInfo enCulture = new CultureInfo("en"); // use "de"
    var langPref = Request.UserLanguages[0];
    var userCulture = CultureInfo.GetCultureInfo(langPref);
    var baseCulture = CultureInfo.GetCultureInfo(cult.TwoLetterISOLanguageName); // get the base culture
    var isSame = baseCulture.Equals(enCulture);
    

    What about using the Headers["Accept-Language"]. Section 14.4 Accept-Language of RFC 2616. There may be a bit more work involved using this, but off hand it seems that that it can hold more valuable information.

    Do we have to take the order into account or would you just disregard it?

    The UserLanguages array is sorted by preference (MSDN). Having said that, I would assume that each browser has its own specific way to create the Language String (I stand under correction, but I think that FF4 is considering removal of this part of the user-agent string). You could check each language and decide when the correct language is found using the approach described above.

    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)

    To me localisation is tricky. I would suggest having read through RFC 1766 and RFC 2616 (HTTP Protocol, Section 3.10.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is about removing sequences from an array, not duplicates in the strict
This question is a follow up to my previous question about getting the HTML
I was reading this question about how to parse URLs out of web pages
I just came across this question about initializing local variables. Many of the answers
I have a question about this question . I posted a reply there but
As kind of a follow up to this question about prefixes , I agree
This question is about organizing the actual CSS directives themselves within a .css file.
This question is about App domains and Sessions. Is it possible to have IIS
This question is about using getter methods of a singleton object in worker threads.
This question is about a Java JTree or a Window .Net Tree (Winforms) or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.