LocalizationSourceHelper.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Globalization;
  2. using Abp.Configuration.Startup;
  3. using Abp.Extensions;
  4. using Abp.Logging;
  5. using Castle.Core.Logging;
  6. namespace Abp.Localization
  7. {
  8. public static class LocalizationSourceHelper
  9. {
  10. public static string ReturnGivenNameOrThrowException(
  11. ILocalizationConfiguration configuration,
  12. string sourceName,
  13. string name,
  14. CultureInfo culture,
  15. ILogger logger = null)
  16. {
  17. var exceptionMessage = $"Can not find '{name}' in localization source '{sourceName}'!";
  18. if (!configuration.ReturnGivenTextIfNotFound)
  19. {
  20. throw new AbpException(exceptionMessage);
  21. }
  22. if (configuration.LogWarnMessageIfNotFound)
  23. {
  24. (logger ?? LogHelper.Logger).Warn(exceptionMessage);
  25. }
  26. var notFoundText = configuration.HumanizeTextIfNotFound
  27. ? name.ToSentenceCase(culture)
  28. : name;
  29. return configuration.WrapGivenTextIfNotFound
  30. ? $"[{notFoundText}]"
  31. : notFoundText;
  32. }
  33. }
  34. }