Starts in:
2 DAYS
7 HRS
20 MIN
12 SEC
Starts in:
2 D
7 H
20 M
12 S
Open Closed

IdentityUserManager Localize Messages from Volo.Abp.Identity.Localization.IdentityResource #3937


User avatar
1
bqabani created
  • ABP Framework version: v4.2.1
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Steps to reproduce the issue:"

I added a new controller to the project: Volo.Abp.Account.Pro.Public.Web I created a new controller for a custom scenario, in the api I create a user using IdentityUserManager.CreateAsync , I always get the error messages in English regardless the current context, Please note that I pass to the api in the header: Accept-Language : ar so I expect to get it in Arabic resource not Arabic, or Accept-Language : tr for Turkish

Other localization resources working fine, only resources related to (Volo.Abp.Identity.Localization.IdentityResource) from Volo.Abp.Identity.Domain.Shared , does not work! I tried to add in the constructor: LocalizationResource = typeof(IdentityResource); but did not work, I added dependency to my module : [DependsOn(typeof(AbpIdentityDomainSharedModule))] did not work neither, I tried to inherit my controller from AbpController or from AccountControllerBase did not work neither,

Sample code:

var result = (await this.userManager.CreateAsync(user, input.Password));
    try
    {
        result.CheckErrors();
    }
    catch 
    {
        var msg = result.Errors.FirstOrDefault().Description;
    }

the msg is always : Passwords must be at least 6 characters. // it takes the English resource: Passwords must be at least {0} characters. The expected result must be by current language such as : Şifre en az 6 karakter uzunluğunda olmalı. or يجب أن تتكون كلمات المرور من 6 حرف على الأقل.


2 Answer(s)
  • User Avatar
    0
    bqabani created

    Any update?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Can you try this?

    
    public IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; }
    
    
    
    var result = (await this.userManager.CreateAsync(user, input.Password));
    try
    {
        result.CheckErrors();
    }
    catch(AbpIdentityResultException e)
    {   
        var msg = ExceptionToErrorInfoConverter.Convert(e, false).Message;
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06