ahmedsafan86
ahmedsafan86

Reputation: 1794

.net mvc application load wrong language resource file

Hello everyone I'm writing a small asp.net mvc application and i want to make it localized and support more than one language I've found many useful articles

I added routing for languages I used a custom actionfilter attribute to choose current culture of current thread depending on the language code in url like "site.com/en/controller/action" for english or "site.com/ar/controller/action" for arabic.

i created "Resources\Views\Shared\Layout.resex" for english language and "Resources\Views\Shared\Layout.ar.resex" for arabic language.

the problem that it is stuck with arabic localization only and i set the current thread culture manually to english and removed actionfilter attribute but it still display arabic content!! what is the problem this is crazr

Upvotes: 1

Views: 2373

Answers (1)

Clafou
Clafou

Reputation: 15410

It's hard to tell without more detail or code, but one easy thing to miss is your web.config file's configuration. If you have something like <globalization uiCulture="auto" culture="auto" /> in <system.web> (with "auto" instead of culture identifiers) then ASP.NET will use the accept-language header, which is determined by your browser's language settings, to automatically choose your thread's cultures. So what you are seeing could be partially explained by having this configuration and having Arabic ahead of English in your browser's language list.

Edit: The issue was that the code needs to use of Thread.CurrentThread.CurrentUICulture to control what localized resources are used (Thread.CurrentThread.CurrentCulture is a different thing, doesn't affect localization but locale-dependent formatting/parsing such as dates).

Upvotes: 4

Related Questions