-
Notifications
You must be signed in to change notification settings - Fork 162
Supporting multiple languages
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:
- Register the .NET localization service.
- Register the AuthP localization service.
- Create resource file(s) for the AuthP messages for other languages.
- Add localization to your own code.
I have covered this in my Net.LocalizeMessagesAndErrors documentation, so please use that to set up the .NET 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.
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.
??????????????????????
- Intro to multi-tenants (ASP.NET video)
- Articles in date order:
- 0. Improved Roles/Permissions
- 1. Setting up the database
- 2. Admin: adding users and tenants
- 3. Versioning your app
- 4. Hierarchical multi-tenant
- 5. Advanced technique with claims
- 6. Sharding multi-tenant setup
- 7. Three ways to add new users
- 8. The design of the sharding data
- 9. Down for maintenance article
- 10: Three ways to refresh claims
- 11. Features of Multilingual service
- 12. Custom databases - Part1
- Videos (old)
- Authentication explained
- Permissions explained
- Roles explained
- AuthUser explained
- Multi tenant explained
- Sharding explained
- How AuthP handles sharding
- How AuthP handles errors
- Languages & cultures explained
- JWT Token refresh explained
- Setup Permissions
- Setup Authentication
- Startup code
- Setup the custom database feature
- JWT Token configuration
- Multi tenant configuration
- Using Permissions
- Using JWT Tokens
- Creating a multi-tenant app
- Supporting multiple languages
- Unit Test your AuthP app