Removed comment and added defensive logic in the eent that the moduletype is not valid. Also changed default behavior to display the name if the key is missing. Will need an option in the future to enable the display of missing keys.
This commit is contained in:
parent
a77aa5fe18
commit
41b30bfab2
@ -17,14 +17,15 @@ namespace Oqtane.Modules.Controls
|
||||
|
||||
protected string Localize(string name)
|
||||
{
|
||||
var key = $"{ResourceKey}.{name}";
|
||||
|
||||
// TODO: we should have a ShowMissingResourceKeys option which developers/translators can enable to find missing translations which would display the key rather than the name
|
||||
if (!IsLocalizable)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
var key = $"{ResourceKey}.{name}";
|
||||
|
||||
return _localizer?[key] ?? key;
|
||||
return _localizer?[key] ?? name;
|
||||
}
|
||||
|
||||
protected override void OnParametersSet()
|
||||
@ -34,14 +35,15 @@ namespace Oqtane.Modules.Controls
|
||||
if (ModuleState?.ModuleType != null)
|
||||
{
|
||||
var moduleType = Type.GetType(ModuleState.ModuleType);
|
||||
|
||||
// HACK: Use ServiceActivator instead of injecting IHttpContextAccessor, because HttpContext throws NRE in WebAssembly runtime
|
||||
if (moduleType != null)
|
||||
{
|
||||
using (var scope = ServiceActivator.GetScope())
|
||||
{
|
||||
var localizerFactory = scope.ServiceProvider.GetService<IStringLocalizerFactory>();
|
||||
_localizer = localizerFactory.Create(moduleType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IsLocalizable = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user