Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

After upgrate to Net Core 2.0 Localization in View (Inject) is not Working

$
0
0

Hello,

After upgrate to Net Core 2.0 Localization in View is not Working, but In Controller works .

I tried to create a default project in Net Core 2.0 and is not working too .

ConfigureServices

-  services.AddLocalization(options => options.ResourcesPath = "Resources");

- services.AddMvc()
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();

- In Folder Resource I have SharedResource.fr-FR.resx

- Shared Resource Class :

namespace PL
{
    public class SharedResource
    {
    }
}

- @inject Microsoft.Extensions.Localization.IStringLocalizer<PL.SharedResource> SharedResource

-  @SharedLocalizer["Add"]

public IStringLocalizer<SharedResource> _SharedResource;

 public HomeController(IStringLocalizer<SharedResource> sharedResource)
        {
            CultureInfo uiCulture = new CultureInfo("fr-FR");
            CultureInfo.CurrentUICulture = uiCulture;
            CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
            _SharedResource = sharedResource;
        }

But I I test with a ViewData from controller is working

 ViewData["Message"] = _SharedResource["Add"];

Thank's


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>