I have the following two files in my MVC project:
I am setting the culture in my global.asax like so:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
I can see in the Immediate Window in Visual Studio that the value of Thread.CurrentThread.CurrentUICulture
is "de-DE" at the time of rendering the view.
Which brings me to my view:
@Html.Raw(CurrentUICultureContent.ce_landingPage_welcomeText)
The problem is, it only renders the text from CurrentUICultureContent.resx and not the text from CurrentUICultureContent.de.resx even though the CurrentUICulture is set to "de-DE."
Note: I have also tried changing the file name to CurrentUiCultureContent.de-DE.resx but that doesn't seem to work either.
Edit: I put a breakpoint in my view page and checked the value of the CurrentUICulture in the Immediate Window; but it still doesn't get the text from the "de-DE.resx" file:
System.Threading.Thread.CurrentThread.CurrentUICulture {de-DE}
Calendar: {System.Globalization.GregorianCalendar}
CompareInfo: {CompareInfo - de-DE}
CultureTypes: SpecificCultures | InstalledWin32Cultures | FrameworkCultures
DateTimeFormat: {System.Globalization.DateTimeFormatInfo}
DisplayName: "German (Germany)"
EnglishName: "German (Germany)"
IetfLanguageTag: "de-DE"
IsNeutralCulture: false
IsReadOnly: false
KeyboardLayoutId: 1031
LCID: 1031
Name: "de-DE"
NativeName: "Deutsch (Deutschland)"
NumberFormat: {System.Globalization.NumberFormatInfo}
OptionalCalendars: {System.Globalization.Calendar[1]}
Parent: {de}
TextInfo: {TextInfo - de-DE}
ThreeLetterISOLanguageName: "deu"
ThreeLetterWindowsLanguageName: "DEU"
TwoLetterISOLanguageName: "de"
UseUserOverride: true
Why is it returning English instead of the expected German resource file?
Is there something extra that I have to do to get this to work?
Sorry for this question - the problem here was just that we were manually loading the assemblies (shadow copying them) and the existing logic didn't put the resource.DLL in the correct folder. .NET expects for the resource.DLL to be placed in the corresponding culture folder; i.e.:
Once I updated the logic to create the shadow copy folder for the culture; .NET picked out the correct resource file.
Also, there was something wrong with the way I was specifying the culture. Apparently, it must be done like this: