How should I localize content in an ASP.NET MVC application? -
To set the language and culture setting of our website in relation to the settings we can take from the user coming to this site The question is.
Let's assume our website supports 2 languages, English (N) and German (D). Suppose we want to ignore the locale (at least on the server side, so we only know that we support "N" and "D", so we have application code, config file or other Places are specified). So we do not care that the user Or comes from the UK.
What we're doing matches "N" or "D" for possible matches in the languages / cultures defined in the user's browser.
The issue I am coming to is that if I do this I
/ * languages / browsers from the ILIT < String & gt; Browser language = filterContext.RequestContext.httpContext. Request .User;
We get all kinds of results.
We can obtain lists such as
-
en (for example Firefox
-
N-US, - N- UK.
-
N, - D, - IT.
-
D, - N-US, - N.
What do I want to ask here:
-
Is it OK to compare strings here (checking that "n" sub-objects
-
Do we have to keep this order in mind or will you ignore it?
< Li>
Is this overcomplicating me more? However, the problem is that IE and Firefox (and others) have different strings for regional settings (for example, "sl" in Firefox and "SL-SI" in IE8 ")
I just want to direct all the visitors, for which English and everyone else is not present in their proper language (neglect their location), then you Think about this, that we have the support of Portuguese (PT) Thanan and our visitors come from Portugal and Brazil, we will send them back to the Portuguese version of the site, even if the match is not 100% accurate (we will redirect them to the Portuguese version from the Portuguese version).
Try asking me to answer questions ...
Is it OK to compare strings here (checking that "N" exists as sub-base)?
You can do something like this, note that I am providing only one method which does not use strings, however, I think the above approach is also its simplest After work will happen. CultureInfo enCulture = New CultureInfo ("en"); // Use "de" var langPref = Request.UserLanguages [0]; Var usercultural = cultureinfo. GatecultureInfo (langPref); Var baseCulture = CultureInfo.GetCultureInfo (cult.TwoLetterISOLanguageName); // Basic culture is achieved equal = foundation. Ekles (enclosure);
What is the use of headers ["accept-language"]
RFC 2616? There may be a little more work to use in this, but by hand it seems that it can keep more important information.
Do we have to keep this order in mind or do you just ignore it?
User Languages
array is ordered by priority (). After saying this, I would think that the language string of each browser (I am standing under improvement) is my typical way, but I think the FF4 user-agent is considering deleting this part of the string) . You can check each language and decide where to find the right language when using the above mentioned approach.
< P> Localization is difficult for me. I recommend reading through and.Am I fulfilling this? Although the problem is that IE and Firefox (and others) have different wires for regional settings (for example, "SL" in Firefox and "SL-SI" in IE8)
I hope it helps.
Comments
Post a Comment