Open Closed

Language support for error messages originating from the abp infrastructure #10229


User avatar
0
user5.abpio created

How can we display an error message from the ABP infrastructure in the local language with language support? You can see an example as below.


2 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution
    • ABP localizes exception messages by mapping exception “code namespaces” to a localization resource. Configure this once and all infrastructure errors that have codes (like authorization/validation) will be shown in the current UI culture.
    • Add a resource for your app (Domain.Shared) and map the ABP namespaces that you want to localize.

    Example: Map authorization/validation/identity namespaces to your resource and provide translations.

    csharp // Domain.Shared module [DependsOn( typeof(AbpExceptionHandlingModule), typeof(AbpValidationModule), typeof(AbpAuthorizationModule), typeof(AbpIdentityDomainSharedModule) )] public class MyProjectDomainSharedModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { Configure<AbpLocalizationOptions>(options => { options.Resources .Add<MyProjectResource>("en") .AddVirtualJson("/Localization/MyProject"); });

        Configure&lt;AbpExceptionLocalizationOptions&gt;(options =>
        {
            // Map exception code namespaces to your resource
            options.MapCodeNamespace("Volo.Abp.Authorization", typeof(MyProjectResource));
            options.MapCodeNamespace("Volo.Abp.Validation", typeof(MyProjectResource));
            options.MapCodeNamespace("Volo.Abp.Identity", typeof(MyProjectResource));
            // add more if needed
        });
    }
    

    }

    • Create localization JSON files that contain the exception texts for the mapped namespaces.
      • Place under MyProject.Domain.Shared/Localization/MyProject/
      • Example en.json and tr.json (Turkish). Include keys used by ABP’s infrastructure. For “Forbidden” (authorization), ABP uses well-known codes and messages; provide localized texts.

    en.json { "culture": "en", "texts": { "Volo.Abp.Authorization:DefaultErrorMessage": "The user represented by the token is not allowed to perform the requested action.", "Volo.Abp.Authorization:Forbidden": "Forbidden" } }

    tr.json { "culture": "tr", "texts": { "Volo.Abp.Authorization:DefaultErrorMessage": "Belirteçle temsil edilen kullanıcı bu işlemi yapmaya yetkili değil.", "Volo.Abp.Authorization:Forbidden": "Yasak" } }

    Notes:

    • The exact keys used by ABP for authorization exceptions are tied to the exception code namespace Volo.Abp.Authorization. After mapping, any ABP-generated authorization error (like forbidden) is localized via your resource. If a specific key is missing, ABP falls back to the default message; add keys you need.
    • Ensure your MVC UI sets and switches CurrentUICulture (ABP does this via the language selector/cookie). Then the modal error message will automatically be shown in the current language.

    Optional: Customize the displayed title/text shape for MVC UI

    • ABP MVC shows RemoteServiceErrorInfo (ProblemDetails) in a modal. To override formatting, implement IExceptionToErrorInfoConverter or subscribe to AbpExceptionEvent to adjust message keys, but in most cases mapping and providing translations is sufficient.
    1. Sources
    • https://abp.io/docs/latest/framework/fundamentals/exception-handling
    • https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationErrorCodes.cs

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Which HTTP request gets this error message?

    Thanks.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on December 17, 2025, 07:08
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.