2
votes

ASP.NET Core 2.2.0

I'm looking for language-based urls in ASP.NET Core. Found a lot of examples online for .NET Core MVC, but can't get it working in Razor Pages.

What I want to achieve is:

  • domain.com/informatie -> link to the 'information' page in default language (Dutch for me)
  • domain.com/en/information -> link to same the same page in English

Therefor I need 2 features:

  1. Recognize the language in the url, or set default language when language-tag is not provided
  2. Translate the names of my Pagemodels

I will write a custom method for translating the content.

Best fitting example

I found 2 examples that do almost the same I want, but they are using MVC:

The second one looks great, I tried to rewrite it for Razor Pages, but got stuck on the LocalizationController.cs (since I'm not using a controller, but a Pagemodel) CultureActionLinkTagHelper.cs (I use the asp-page attribute).

Is there anybody who has fixed this in Razor Pages and who would like to share the code? Or anybody who can help me through?

1

1 Answers

2
votes

You need to build your application considering globalization/localization.

Here is the official documentation from Microsoft.

You may find this tutorial for Developing Multicultural Web Application helpful, it is for DotNetCore 2.1 Razor Pages, but it is valid for 2.2 as well.

Additionally, her is a sample project for localizing razor pages in GitHub