diff --git a/Oqtane.Client/Modules/Controls/ActionDialog.razor b/Oqtane.Client/Modules/Controls/ActionDialog.razor index 4770729b..73723fa5 100644 --- a/Oqtane.Client/Modules/Controls/ActionDialog.razor +++ b/Oqtane.Client/Modules/Controls/ActionDialog.razor @@ -97,12 +97,9 @@ _iconSpan = $" "; } - if (IsLocalizable) - { - Text = Localize(nameof(Text), Text); - Header = Localize(nameof(Header), Header); - Message = Localize(nameof(Message), Message); - } + Text = Localize(nameof(Text), Text); + Header = Localize(nameof(Header), Header); + Message = Localize(nameof(Message), Message); _authorized = IsAuthorized(); } diff --git a/Oqtane.Client/Modules/Controls/ActionLink.razor b/Oqtane.Client/Modules/Controls/ActionLink.razor index eacc9813..1ba9ef12 100644 --- a/Oqtane.Client/Modules/Controls/ActionLink.razor +++ b/Oqtane.Client/Modules/Controls/ActionLink.razor @@ -95,11 +95,7 @@ } - if (IsLocalizable) - { - _text = Localize(nameof(Text), _text); - } - + _text = Localize(nameof(Text), _text); _url = EditUrl(Action, _parameters); _authorized = IsAuthorized(); } diff --git a/Oqtane.Client/Modules/Controls/Label.razor b/Oqtane.Client/Modules/Controls/Label.razor index 85e65d14..b67143cb 100644 --- a/Oqtane.Client/Modules/Controls/Label.razor +++ b/Oqtane.Client/Modules/Controls/Label.razor @@ -43,16 +43,12 @@ else _openLabel += ">"; - if (IsLocalizable) + var text = Localize("Text", String.Empty); + if (text != String.Empty) { - var value = Localize("Text"); - var key = $"{ResourceKey}.Text"; - if (!value.Equals(key)) - { - ChildContent =@@Localize("Text"); - } - - HelpText = Localize(nameof(HelpText), HelpText); + ChildContent =@@text; } + + HelpText = Localize(nameof(HelpText), HelpText); } } diff --git a/Oqtane.Client/Modules/Controls/LocalizableComponent.cs b/Oqtane.Client/Modules/Controls/LocalizableComponent.cs index 657494d7..773df857 100644 --- a/Oqtane.Client/Modules/Controls/LocalizableComponent.cs +++ b/Oqtane.Client/Modules/Controls/LocalizableComponent.cs @@ -15,56 +15,54 @@ namespace Oqtane.Modules.Controls protected bool IsLocalizable { get; private set; } - protected string Localize(string name) - { - var key = $"{ResourceKey}.{name}"; + protected string Localize(string name) => _localizer?[name] ?? 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 + protected string Localize(string propertyName, string propertyValue) + { if (!IsLocalizable) { - return name; + return propertyValue; } - return _localizer?[key] ?? name; - } - - protected string Localize(string name, string defaultValue) - { - var key = $"{ResourceKey}.{name}"; - var value = Localize(name); + var key = $"{ResourceKey}.{propertyName}"; + var value = Localize(key); if (value == key) { - return defaultValue; + // Returns default property value (English version) instead of ResourceKey.PropertyName + return propertyValue; } else { - return value; + if (value == String.Empty) + { + // Returns default property value (English version) + return propertyValue; + } + else + { + return value; + } } } protected override void OnParametersSet() { - if (!String.IsNullOrEmpty(ResourceKey)) + IsLocalizable = false; + + if (!String.IsNullOrEmpty(ResourceKey) && ModuleState?.ModuleType != null) { - if (ModuleState?.ModuleType != null) + var moduleType = Type.GetType(ModuleState.ModuleType); + if (moduleType != null) { - var moduleType = Type.GetType(ModuleState.ModuleType); - if (moduleType != null) + using (var scope = ServiceActivator.GetScope()) { - using (var scope = ServiceActivator.GetScope()) - { - var localizerFactory = scope.ServiceProvider.GetService(); - _localizer = localizerFactory.Create(moduleType); - } + var localizerFactory = scope.ServiceProvider.GetService(); + _localizer = localizerFactory.Create(moduleType); + + IsLocalizable = true; } } - - IsLocalizable = true; - } - else - { - IsLocalizable = false; } } } diff --git a/Oqtane.Client/Modules/Controls/Section.razor b/Oqtane.Client/Modules/Controls/Section.razor index fd8b9a52..027b0e85 100644 --- a/Oqtane.Client/Modules/Controls/Section.razor +++ b/Oqtane.Client/Modules/Controls/Section.razor @@ -46,11 +46,8 @@ { base.OnParametersSet(); - if (IsLocalizable) - { - _heading = !string.IsNullOrEmpty(Heading) - ? Localize(nameof(Heading), Heading) - : Localize(nameof(Name), Name); - } + _heading = !string.IsNullOrEmpty(Heading) + ? Localize(nameof(Heading), Heading) + : Localize(nameof(Name), Name); } } diff --git a/Oqtane.Client/Modules/Controls/TabPanel.razor b/Oqtane.Client/Modules/Controls/TabPanel.razor index 7c2eaa24..e618c896 100644 --- a/Oqtane.Client/Modules/Controls/TabPanel.razor +++ b/Oqtane.Client/Modules/Controls/TabPanel.razor @@ -40,16 +40,13 @@ else { base.OnParametersSet(); - if (IsLocalizable) + if (string.IsNullOrEmpty(Heading)) { - if (string.IsNullOrEmpty(Heading)) - { - Name = Localize(nameof(Name), Name); - } - else - { - Heading = Localize(nameof(Heading), Heading); - } + Name = Localize(nameof(Name), Name); + } + else + { + Heading = Localize(nameof(Heading), Heading); } }