Check needed if the component is localizable

This commit is contained in:
hishamco 2020-10-19 21:47:59 +03:00
parent fed56098a0
commit 79b584f268
2 changed files with 19 additions and 3 deletions

View File

@ -43,7 +43,10 @@ else
_openLabel += ">";
if (IsLocalizable)
{
ChildContent =@<text>@Localize("Text")</text>;
HelpText = Localize(nameof(HelpText));
}
}
}

View File

@ -12,8 +12,15 @@ namespace Oqtane.Modules.Controls
[Parameter]
public string ResourceKey { get; set; }
protected bool IsLocalizable { get; private set; }
protected string Localize(string name)
{
if (!IsLocalizable)
{
return null;
}
var key = $"{ResourceKey}.{name}";
return _localizer?[key] ?? key;
@ -35,6 +42,12 @@ namespace Oqtane.Modules.Controls
_localizer = (IStringLocalizer)scope.ServiceProvider.GetService(localizerType);
}
}
IsLocalizable = true;
}
else
{
IsLocalizable = false;
}
}
}