DotVVM Request Localization Sample
This sample demonstrates using ASP.NET Core Request Localization with DotVVM.
This method only works in ASP.NET Core. If you use OWIN, you need to use Localizable Presenter or switch the culture manually.
- Make sure you have installed DotVVM for Visual Studio
How to run the sample
Open the GitHub repo in Visual Studio or
git clone https://github.com/riganti/dotvvm-samples-request-localization.git
RequestLocalizationSampleproject and select View > View in Browser
What you can learn in the sample
- How to use Globalization features in DotVVM
About the sample
Request Localization is a standard ASP.NET Core way of localizing web apps. It is extensible and works well with
Accept-Language header and cookies.
This sample shows the default settings - if the cookie with language is not present, the language is retrieved from the
Accept-Language header. If the cookie
.AspNetCore.Culture is set, the language from the cookie is used.
There is also a sample of
DotvvmRouteRequestCultureProvider that can determine the language from the
Lang route parameter. It is added as an initial provider, so the order of precedence is this:
- Route parameter
- Accept-Language header
You should not specify
DotvvmStartup to prevent DotVVM from tampering with the request culture.
Alternative way: LocalizablePresenter
DotVVM ships with a Localizable Presenter which allows to switch language based on route parameters or query string values.
This approach is universal and works on both ASP.NET Core and OWIN.