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

Regarding Implementing localization in ASP.NET Core

$
0
0

see the code i have read this article https://dotnetthoughts.net/implementing-localization-in-aspnet-core/ but do not understand many things.

public void Configure(IApplicationBuilder app)
{
    var supportedCultures = new List<CultureInfo>
    {
        new CultureInfo("en-US"),
        new CultureInfo("ml-IN"),
        new CultureInfo("hi-IN")
    };

    var options = new RequestLocalizationOptions
    {
        DefaultRequestCulture = new RequestCulture("en-US"),
        SupportedCultures = supportedCultures,
        SupportedUICultures = supportedCultures,
    };

    app.UseRequestLocalization(options);
    app.UseStaticFiles();

    app.UseMvcWithDefaultRoute();
}

1) in asp.net mvc 4 or 5 we used to assign culture to thread and threadUI....but see the above code they are not assigning any culture to thread and threadUI.

2) see the code

public class HomeController : Controller
{
    private readonly IStringLocalizer<HomeController> _stringLocalizer;
    public HomeController(IStringLocalizer<HomeController> stringLocalizer)
    {
        _stringLocalizer = stringLocalizer;
    }
    public IActionResult Index()
    {
        ViewData["Welcome"] = _stringLocalizer["Welcome"];
        return View();
    }
}

2) what is IStringLocalizer and we never use thisIStringLocalizer in old mvc4/5. whatIStringLocalizer does ?

3) in asp.net webform or asp.net mvc we can give any name to resource file but the above article link is saying we need to give resource file nameHomeController.en-US.resx and HomeController.en-UK.resx. if i give any name like myresource-.en-US.resx then it will not work ?

4) what is the meaning of app.UseStaticFiles(); ? when we need to say this app.UseStaticFiles(); only for resource file ?

5) what is the meaning of services.AddLocalization(options => options.ResourcesPath = "Resources"); ?resource is the name of the folder?

6) why we need to say services.AddMvc(); when we are working with asp.net mvc core then we need to mention add mvc?

please guide me and answer point wise. thanks


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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