Reputation: 2370
I was trying to add some satellite resource files to display different language I followed these two posts in general
Localization of a Site in MVC5 Using Resource File
here's what I have done in nutshell (using visual studio 2017, .net framework 4.5)
I created a folder named it "Resources"
I right clicked this folder and created a file named it "Lang.resx", added a string pair (name: Welcome, value: Hello), then switch it to public and save
I right clicked this folder and created another file named it "Lang.es.resx", added a string pair (name: Welcome, value: Hola), then switch it to public and save
I opened up web.config and added following line to System.Web
<globalization enableClientBasedCulture="true" culture="auto" uiCulture="auto" />
I opened up a blank view, write the following to that view
@{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("es");
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("es");
}
<div>@MyProject.Resources.Lang.Welcome</div>
<div>@Thread.CurrentThread.CurrentCulture.DisplayName</div>
<div>@Thread.CurrentThread.CurrentUICulture.DisplayName</div>
The output is as following:
Hello Spanish Spanish
As you can see, the culture is changed but somehow the Lang.es.resx is not read, I have created multiple new project in different hosting VPS, the result is always the same. So there must be something I've done incorrectly, or some steps missing
Upvotes: 0
Views: 1797
Reputation: 51
In the file properties in Visual Studio, set:
Copy to output directory: Copy always
If you want for multiple files within a folder, you can always edit your .csproj file
<Content Include="parent directory\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Upvotes: 0
Reputation: 2370
ok, after a whole day debugging, I've found out the cause
I think this is it, hopefully this can help anyone facing the same problem
Upvotes: 1