Skip to content

Supporting multiple languages

Jon P Smith edited this page Jan 2, 2023 · 9 revisions

The 4.1.0 (or higher) AuthP library has a built-in localization system using my Net.LocalizeMessagesAndErrors library. By default it is turned off so you can try things without having to set up the .NET localization service with the resource files for the different languages you want to support. To turn on localization in your code that uses the AuthP library you need to:

  1. Register the .NET localization service.
  2. Register the AuthP localization service.
  3. Create resource file(s) for the AuthP messages for other languages.
  4. Add localization to your own code.

1. Register the .NET localization service.

I have covered this in my Net.LocalizeMessagesAndErrors documentation, so please use that to set up the .NET localization service.

2. Register the AuthP localization service.

You add the SetupAuthPLocalization<TResource> extension method within the registering of the AuthP library. The code below, taken from the Program class in Example1, that sets up the AuthP localization of its backend code.

builder.Services.RegisterAuthPermissions<Example1Permissions>()
    .SetupAuthPLocalization<AuthPLocalizeResource>(supportedCultures)
    // other AuthP's registering left out 

The AuthPLocalizeResource class in the Example1 ASP.NET Core's project is there to define part of the resource file(s) name that will hold the AuthP messages in the extra languages you want to support (see next section about this). You can have a class with a different or location, but it must be in the ASP.NET Core's project.

The supportedCulture parameter should be set to an array of culture names your app supports, e.g new[] { "en", "fr" }. This list can usually come from your code to register the .NET localization service.

NOTE: See a more detailed list of the possible supportedCulture settings in the Startup code -> SetupAuthPLocalization section.

3. Create resource file(s) for the AuthP messages for other languages.

The AuthP library has >100 messages (mostly error messages) which you need changed into the non-English languages. For this you need a resource file for every language, other than English.

To help you to set up each resource file there is a file called AuthPermissions - list of localizable keys & messages - english which contains the Name and Value of each AuthP possible messages, but the Value is in English. This will save you a lot of time and you can be more sure you have got every entry you need to change.

Add localization to your own code.

??????????????????????

Articles / Videos

Concepts

Setup

Usage

Admin

SupportCode

Clone this wiki locally