From 03363d03e830b9f7d48297a19732a72d643a25fb Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 31 May 2019 14:49:59 +0100 Subject: [PATCH] FEATURE: Load theme setting descriptions from theme locale files Previously theme setting descriptions were defined in the `settings.yml` file like this: ``` setting_name: default: "My Default Value" description: en: "English description" fr: "French description" ``` This commit allows developers to store the localised descriptions in the theme locale files instead: ``` en: theme_metadata: description: Theme Description settings: setting_name: "The localised description for setting_name" ``` --- app/models/theme.rb | 2 +- app/serializers/theme_settings_serializer.rb | 5 +++-- lib/theme_settings_manager.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/theme.rb b/app/models/theme.rb index 7daeb4b9393..9fd4b9ec726 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -367,7 +367,7 @@ class Theme < ActiveRecord::Base end def internal_translations - translations(internal: true) + @internal_translations ||= translations(internal: true) end def translations(internal: false) diff --git a/app/serializers/theme_settings_serializer.rb b/app/serializers/theme_settings_serializer.rb index 316a403f045..92f41cf6812 100644 --- a/app/serializers/theme_settings_serializer.rb +++ b/app/serializers/theme_settings_serializer.rb @@ -21,7 +21,8 @@ class ThemeSettingsSerializer < ApplicationSerializer end def description - object.description + locale_file_description = object.theme.internal_translations.find { |t| t.key == "theme_metadata.settings.#{setting}" } &.value + locale_file_description || object.description end def valid_values @@ -33,7 +34,7 @@ class ThemeSettingsSerializer < ApplicationSerializer end def include_description? - object.description.present? + description.present? end def list_type diff --git a/lib/theme_settings_manager.rb b/lib/theme_settings_manager.rb index ec19e42c9d0..cc69dee04e6 100644 --- a/lib/theme_settings_manager.rb +++ b/lib/theme_settings_manager.rb @@ -34,7 +34,7 @@ class ThemeSettingsManager end def description - @opts[:description] + @opts[:description] # Old method of specifying description. Is now overridden by locale file end def value=(new_value)