I have spent about one week trying to understand how Localization is going to work in ASP.NET Core 1.0. I have tested a lot of options, but I can't make it working.
I have read about the bug in Visual Studio, I have read all articles about how it's working right now (Article1, Article2, Article3) and I have check and tested all about the example in the Official GitHub Repository.
My Goal:
I just want to make it works like I did in ASP.NET MVC 5.
I have configured my Startup.cs like this:
Configure Section:
var requestLocalizationOptions = new RequestLocalizationOptions
{
// Set options here to change middleware behavior
SupportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("es-ES")
},
SupportedUICultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("es-ES")
}
};
app.UseRequestLocalization(requestLocalizationOptions, defaultRequestCulture: new RequestCulture("en-US"));
Configure Services Section:
// Add MVC services to the services container.
services
.AddMvc()
.AddViewLocalization(options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
In my folder Resources, I have my .resx files. I have copied it from the official example, but no way... No errors, just not working.
If I test the Localization example of the official Repo, it works. But I can't modified to adapt to MVC 6.
I have created a repository on GitHub for my code and test it. (https://github.com/chemitaxis/Localization.StackOverflow)
Can someone please help me? I think a lot of people is having these problems.
Thanks!!
App localization involves the following: Make the app's content localizable. Provide localized resources for the languages and cultures you support. Implement a strategy to select the language/culture for each request.
Localization is the process of adapting software to meet the requirements of local markets and different languages. You can change the messages that are displayed in the Telerik UI for ASP.NET MVC helpers by including an additional script file in the document.
Localization is the process of translating an application's resources into localized versions for each culture that the application will support.
Localization, on the other hand, is the process of customization to make our application behave as per the current culture and locale. These two things go together. To do globalization we need to use Resource Files.
Ok, I solved it... I will update my example on GitHub tomorrow.
I have created a _ViewImports, and add it:
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
@using System.Threading.Tasks
@using AspNet5Localization
@using AspNet5Localization.Resources
@using Microsoft.AspNet.Mvc.Localization
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<AmazingResource> SR
After, I have created a HomeController and Views/Home/Index.cshtml file.
Like I have injected in my Views in _ViewImports the IStringLocalizer SR I can use it in my Razor Views using just:
@SR["Name"]
I don't know if it the best way to do that, but it works. If someone can explain the best way to do that, please answer this question.
Complete solution working: https://github.com/chemitaxis/Localization.StackOverflow
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With