mirror of https://github.com/abpframework/abp.git
5 changed files with 83 additions and 61 deletions
@ -0,0 +1,46 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Microsoft.AspNetCore.Mvc.ViewFeatures; |
|||
using Microsoft.Extensions.Localization; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.AspNetCore.Mvc.Localization; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers |
|||
{ |
|||
public class AbpTagHelperLocalizer : IAbpTagHelperLocalizer |
|||
{ |
|||
private readonly IStringLocalizerFactory _stringLocalizerFactory; |
|||
private readonly AbpMvcDataAnnotationsLocalizationOptions _options; |
|||
|
|||
public AbpTagHelperLocalizer(IOptions<AbpMvcDataAnnotationsLocalizationOptions> options, IStringLocalizerFactory stringLocalizerFactory) |
|||
{ |
|||
_stringLocalizerFactory = stringLocalizerFactory; |
|||
_options = options.Value; |
|||
} |
|||
|
|||
public string GetLocalizedText(string text, ModelExplorer explorer) |
|||
{ |
|||
var localizer = GetLocalizer(explorer); |
|||
|
|||
return localizer == null ? text : localizer[text].Value; |
|||
} |
|||
|
|||
public IStringLocalizer GetLocalizer(ModelExplorer explorer) |
|||
{ |
|||
return GetLocalizer(explorer); |
|||
} |
|||
|
|||
private IStringLocalizer GetStringLocalizer(ModelExplorer explorer) |
|||
{ |
|||
IStringLocalizer localizer = null; |
|||
var resourceType = _options.AssemblyResources.GetOrDefault(explorer.Container.ModelType.Assembly); |
|||
|
|||
if (resourceType != null) |
|||
{ |
|||
localizer = _stringLocalizerFactory.Create(resourceType); |
|||
} |
|||
|
|||
return localizer; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Microsoft.AspNetCore.Mvc.ViewFeatures; |
|||
using Microsoft.Extensions.Localization; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers |
|||
{ |
|||
public interface IAbpTagHelperLocalizer : ITransientDependency |
|||
{ |
|||
string GetLocalizedText(string text, ModelExplorer explorer); |
|||
|
|||
IStringLocalizer GetLocalizer(ModelExplorer explorer); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue