Im using Microsoft.AspNetCore.All 2.0.3
I've created a new MVC project from Visual Studio.
I've followed the guide here to setup localization: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization
I've added culture specific language files:
When I run the application, nothing gets localized.
However, if I add a resource file without the culture prefix, strings from the that file becomes "localized".
When debugging, I can see that the following SearchedLocation is used: Web.Resources.Controllers.HomeController
Shouldn't this path use cultureinfo or something and look like this: Web.Resources.Controllers.HomeController.en-US?
I've created a small application here that reproduces the behaviour im describing, just clone the repo and run it: https://github.com/joseftw/aspnetcore.localization
What am I missing? I followed a bunch of different tutorials that I've found online, none of them works, they all work when I add files without the culture prefix though...
http://localhost:63836/?culture=en-US (or just http://localhost:63836/)
Current Culture: en-US
Current UI Culture: en-US
Translated Heading(IStringLocalizer): Heading from resource file!
Translated Heading(IViewLocalizer): Heading from resource file!
Current Culture: en-US
Current UI Culture: en-US
Translated Heading(IStringLocalizer): Heading
Translated Heading(IViewLocalizer): Heading
http://localhost:63836/?culture=sv-SE
Current Culture: sv-SE
Current UI Culture: sv-SE
Translated Heading(IStringLocalizer): Rubrik fr氓n resourcefil!
Translated Heading(IViewLocalizer): Rubrik fr氓n resourcefil!
Current Culture: sv-SE
Current UI Culture: sv-SE
Translated Heading(IStringLocalizer): Heading
Translated Heading(IViewLocalizer): Heading
UPDATE: I found this issue on stackoverflow: https://stackoverflow.com/questions/39132868/localization-in-asp-net-core-mvc-not-working-unable-to-locate-resource-file
If I install that package, everything works as it should. But I don't think that's a nice solution since it's a third party package, surely it must be a missing step in the documentation or something?
@ryanbrandenburg, can you please look into this? Thanks!
I just tried this again by cloning my own repo, and now it works. It's really weird, only thing I've done is that I've rebooted my computer. I guess that you can close this issue if you can't reproduce it... :)
When I run your sample app I get all the expected results. I tried fiddling with a couple things to see if I could get it back into a failure state but no dice. Let us know if you run into this again, otherwise closing this one.
I had the exact same problem as @joseftw... I tried to fix it for some time and when reading here I finally realized.. "Clean -> Rebuild". I suspected that after reading that it started working again after a reboot.
@InfiRandia It works! You saved my day. I spent about 3hours for debugging
..
Most helpful comment
I had the exact same problem as @joseftw... I tried to fix it for some time and when reading here I finally realized.. "Clean -> Rebuild". I suspected that after reading that it started working again after a reboot.