Multilingual Support and Localisation in ASP.NET Core Web Application with Razor Pages

preview_player
Показать описание


Multilingual support - Globalization and localization in ASP.NET Core. How to add multiple languages to ASP.NET web application with Razor Pages. A multilingual website allows a website to reach a wider audience. ASP.NET Core provides services and middleware for localizing into different languages and cultures.

Source code in the first comment .

***********************************

🔥 *Complete Udemy Courses* :

⬇️ *Free Document Proofreading* ⬇️
Рекомендации по теме
Комментарии
Автор

Program.cs:
using

var builder =

=> options.ResourcesPath = "Resources");

// Add services to the container.




var app = builder.Build();

var supportedCultures = new[] { "en", "fr" };
var localizationOptions = new





// Configure the HTTP request pipeline.
if
{

}
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

app.Run();



Lang.cshtml.cs

public class LangModel : PageModel
{
public void OnGet()
{
string? culture = Request.Query["culture"];
Console.WriteLine("new selected language: " + culture);
if (culture != null)
{
Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
RequestCulture(culture)),
new CookieOptions { Expires = }
);
}


string returnUrl = ?? "/";

}
}


_ViewImports.chstml
@using WebApplication4
@namespace WebApplication4.Pages
@addTagHelper *,

@using
@inject IViewLocalizer Localizer

BoostMyTool
Автор

Nice one ! But does it require to add to each Html tag the Localizer? That will be a huge effort for a large project. is there any other way, to add languages?

attilaguba
Автор

hai 8.38 min after role="button" i cant see

弘雄-fe
Автор

@BoostMyTool can you add _layout code?

wojciechmagnus
Автор

Thank you but i have a problem with this : <a class="dropdown-item" the href don't work for me, any idea ? thank you

marj