Label should use LocalizableComponent
This commit is contained in:
parent
5bb7c63d44
commit
fd5d777d3a
|
@ -1,6 +1,5 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleControlBase
|
@inherits LocalizableComponent
|
||||||
@using Microsoft.Extensions.Localization
|
|
||||||
|
|
||||||
@if (!string.IsNullOrEmpty(HelpText))
|
@if (!string.IsNullOrEmpty(HelpText))
|
||||||
{
|
{
|
||||||
|
@ -27,11 +26,10 @@ else
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string HelpText { get; set; } // optional - tooltip for this label
|
public string HelpText { get; set; } // optional - tooltip for this label
|
||||||
|
|
||||||
[Parameter]
|
|
||||||
public string ResourceKey { get; set; }
|
|
||||||
|
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
|
base.OnParametersSet();
|
||||||
|
|
||||||
_openLabel = "<label";
|
_openLabel = "<label";
|
||||||
if (!string.IsNullOrEmpty(For))
|
if (!string.IsNullOrEmpty(For))
|
||||||
{
|
{
|
||||||
|
@ -47,21 +45,8 @@ else
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(ResourceKey))
|
if (!string.IsNullOrEmpty(ResourceKey))
|
||||||
{
|
{
|
||||||
if (ModuleState?.ModuleType != null)
|
ChildContent =@<text>@Localizer[$"{ResourceKey}.Text"]</text>;
|
||||||
{
|
HelpText = Localizer[$"{ResourceKey}.{nameof(HelpText)}"];
|
||||||
var moduleType = Type.GetType(ModuleState.ModuleType);
|
|
||||||
var localizerTypeName = $"Microsoft.Extensions.Localization.IStringLocalizer`1[[{moduleType.AssemblyQualifiedName}]], Microsoft.Extensions.Localization.Abstractions";
|
|
||||||
var localizerType = Type.GetType(localizerTypeName);
|
|
||||||
|
|
||||||
// HACK: Use ServiceActivator instead of injecting IHttpContextAccessor, because HttpContext throws NRE in WebAssembly runtime
|
|
||||||
using (var scope = ServiceActivator.GetScope())
|
|
||||||
{
|
|
||||||
var localizer = (IStringLocalizer)scope.ServiceProvider.GetService(localizerType);
|
|
||||||
|
|
||||||
ChildContent = @<text>@localizer[$"{ResourceKey}.Text"]</text>;
|
|
||||||
HelpText = localizer[$"{ResourceKey}.{nameof(HelpText)}"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user