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

ILocalizableString without using DomainService #2992


User avatar
0
bilalhaidar created

Hello, In one of the scenarios, I cannot inherit from the DomainService as I need to do case by case IoC by type. etc. However, in this case, I need to localize error messages.

So in the base class of a class, I add the following method:

protected ILocalizableString L(string name)
        {
            return new LocalizableString(name, OnlineSystemsConsts.LocalizationSourceName);
        }

The above method does return a localizable string.

Now 2 questions:

  • When it is time to send localized string to the client, I need to use UserFriendlyException. This exception requires a string. How to convert LocalizableString to string? With the above message, I can only call a Key without parameters. What if the localized string contains a placeholder {0}. How would be able to pass this value and get a localized string?

Thanks Bilal


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

    Hi,

    You can define your L method like this. <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp/AbpServiceBase.cs#L116">https://github.com/aspnetboilerplate/as ... se.cs#L116</a>

    If you want to use it with arguments you can also define another usage like this. <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp/AbpServiceBase.cs#L127">https://github.com/aspnetboilerplate/as ... se.cs#L127</a>

  • User Avatar
    0
    bilalhaidar created

    I can inject LocalizationSource in my classes?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can inject ILocalizationManager and then get localizaion source like this LocalizationManager.GetSource(LocalizationSourceName).

  • User Avatar
    0
    bilalhaidar created

    Thanks!