Skip to content

Supporting multiple languages

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

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

  1. Register the .NET localization service in your ASP.NET Core.
  2. Register the AuthP localization service in your Program class.
  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 which links to apps that have .NET localization set up, 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. You have to translate the English Value to the language(s) you want to support.

This is a tedious job, but having the the complete set of Name / Value will make the process easier, and you can be sure you have covered all the messages.

???? EXTRA BIT FROM ARTICAL

Add localization to your own code.

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

Articles / Videos

Concepts

Setup

Usage

Admin

SupportCode

Clone this wiki locally