Skip to content

Commit

Permalink
FEATURE: Load theme setting descriptions from theme locale files
Browse files Browse the repository at this point in the history
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"
```
  • Loading branch information
davidtaylorhq committed May 31, 2019
1 parent a0a2823 commit 03363d0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/theme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def add_child_theme!(theme)
end

def internal_translations
translations(internal: true)
@internal_translations ||= translations(internal: true)
end

def translations(internal: false)
Expand Down
5 changes: 3 additions & 2 deletions app/serializers/theme_settings_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def value
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
Expand All @@ -33,7 +34,7 @@ def include_valid_values?
end

def include_description?
object.description.present?
description.present?
end

def list_type
Expand Down
2 changes: 1 addition & 1 deletion lib/theme_settings_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def type
end

def description
@opts[:description]
@opts[:description] # Old method of specifying description. Is now overridden by locale file
end

def value=(new_value)
Expand Down

0 comments on commit 03363d0

Please sign in to comment.