From 41b30bfab2d53c6af6f0621505fe1c026efec774 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Mon, 9 Nov 2020 09:27:52 -0500 Subject: [PATCH] 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. --- .../Modules/Controls/LocalizableComponent.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Oqtane.Client/Modules/Controls/LocalizableComponent.cs b/Oqtane.Client/Modules/Controls/LocalizableComponent.cs index 72b8b0a5..80222e66 100644 --- a/Oqtane.Client/Modules/Controls/LocalizableComponent.cs +++ b/Oqtane.Client/Modules/Controls/LocalizableComponent.cs @@ -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,12 +35,13 @@ 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 - using (var scope = ServiceActivator.GetScope()) + if (moduleType != null) { - var localizerFactory = scope.ServiceProvider.GetService(); - _localizer = localizerFactory.Create(moduleType); + using (var scope = ServiceActivator.GetScope()) + { + var localizerFactory = scope.ServiceProvider.GetService(); + _localizer = localizerFactory.Create(moduleType); + } } }