Starts in:
2 DAYS
8 HRS
48 MIN
28 SEC
Starts in:
2 D
8 H
48 M
28 S
Open Closed

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


User avatar
0
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 حرف على الأقل.

I also tried the following solution but I got: System.NullReferenceException: Object reference not set to an instance of an object. link

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;
}

Please note that I have posted this question to another link but it was closed without being able to reply


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I also tried the following solution but I got: System.NullReferenceException: Object reference not set to an instance of an object

    Can you share the error logs? thanks.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer
    > public IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; }
    

    Did you inject the IExceptionToErrorInfoConverter service in the constructor?

    public IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; }
    
    public MyClassName(IExceptionToErrorInfoConverter exceptionToErrorInfoConverter)
    {
       ExceptionToErrorInfoConverter  = exceptionToErrorInfoConverter;
    }
    
  • User Avatar
    0
    bqabani created

    Thank you!

    It worked!, I will do some tests and confirm if there is no issues

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06