mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
using System;
|
|
using JetBrains.Annotations;
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
namespace Volo.Abp.Localization;
|
|
|
|
public static class HasNameWithLocalizableDisplayNameExtensions
|
|
{
|
|
[NotNull]
|
|
public static string GetLocalizedDisplayName(
|
|
[NotNull] this IHasNameWithLocalizableDisplayName source,
|
|
[NotNull] IStringLocalizerFactory stringLocalizerFactory,
|
|
[CanBeNull] string localizationNamePrefix = "DisplayName:")
|
|
{
|
|
if (source.DisplayName != null)
|
|
{
|
|
return source.DisplayName.Localize(stringLocalizerFactory);
|
|
}
|
|
|
|
var defaultStringLocalizer = stringLocalizerFactory.CreateDefaultOrNull();
|
|
if (defaultStringLocalizer == null)
|
|
{
|
|
return source.Name;
|
|
}
|
|
|
|
var localizedString = defaultStringLocalizer[$"{localizationNamePrefix}{source.Name}"];
|
|
if (!localizedString.ResourceNotFound ||
|
|
localizationNamePrefix.IsNullOrEmpty())
|
|
{
|
|
return localizedString;
|
|
}
|
|
|
|
return defaultStringLocalizer[source.Name];
|
|
}
|
|
}
|
|
|