Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to localize UserFriendlyException? #4180


User avatar
0
manojreddy created

We have support for localized string only on the client side, But If I want to send some exception to the client side, there is no support for localization. Do You have any approach for this?


4 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    You can override abp.message.error:

    var error = abp && abp.message && abp.message.error;
    if (error) {
        abp.message.error = function (message, title) {
            message = localize(message);
            title = localize(title);
            return error(message, title);
        };
    }
    
    function localize(name) {
        return "[" + name + "]";
    }
    
  • User Avatar
    0
    manojreddy created

    Where should I add the code mentioned by you?

    this._testService.createTest(this.test)
    	.subscribe(() => {
    		this.notify.info(this.l('SavedSuccessfully'));
    		this.modalSave.emit(this.test);
    		this.router.navigate(['/app/tests']);
    	});
    
    public async Task CreateTest(TestInput input)
    	{
    		
    		throw new UserFriendlyException("Test Code Already Exist");
    						
    }
    

    I want to localize "Test Code Already Exist" message.

  • User Avatar
    0
    aaron created
    Support Team

    Why not localize on server side?

    throw new UserFriendlyException(L("Test Code Already Exist"));
    
  • User Avatar
    0
    manojreddy created

    Thanks ,

    My bad, I missed it.