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)
-
0
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>
-
0
I can inject LocalizationSource in my classes?
-
0
Hi,
You can inject ILocalizationManager and then get localizaion source like this LocalizationManager.GetSource(LocalizationSourceName).
-
0
Thanks!