| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using System.Globalization;
- using Abp.Configuration.Startup;
- using Abp.Extensions;
- using Abp.Logging;
- using Castle.Core.Logging;
- namespace Abp.Localization
- {
- public static class LocalizationSourceHelper
- {
- public static string ReturnGivenNameOrThrowException(
- ILocalizationConfiguration configuration,
- string sourceName,
- string name,
- CultureInfo culture,
- ILogger logger = null)
- {
- var exceptionMessage = $"Can not find '{name}' in localization source '{sourceName}'!";
- if (!configuration.ReturnGivenTextIfNotFound)
- {
- throw new AbpException(exceptionMessage);
- }
- if (configuration.LogWarnMessageIfNotFound)
- {
- (logger ?? LogHelper.Logger).Warn(exceptionMessage);
- }
- var notFoundText = configuration.HumanizeTextIfNotFound
- ? name.ToSentenceCase(culture)
- : name;
- return configuration.WrapGivenTextIfNotFound
- ? $"[{notFoundText}]"
- : notFoundText;
- }
- }
- }
|