A platform for community discussion. Free, open, simple.
FIX: Theme components should work with empty locale files (#18167)
Gerhard Schlagerfd6109a6e1ce
diff --git a/app/models/theme.rb b/app/models/theme.rbindex 31ef65abf10..4ec449ab4ae 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -6,7 +6,7 @@ require 'json_schemer'class Theme < ActiveRecord::Baseinclude GlobalPath- BASE_COMPILER_VERSION = 61+ BASE_COMPILER_VERSION = 62attr_accessor :child_componentsdiff --git a/lib/theme_translation_parser.rb b/lib/theme_translation_parser.rbindex b1daaf4a626..76941fbca5e 100644--- a/lib/theme_translation_parser.rb+++ b/lib/theme_translation_parser.rb@@ -10,7 +10,7 @@ class ThemeTranslationParserenddef self.check_contains_hashes(hash)- hash.all? { |key, value| value.is_a?(String) || (value.is_a?(Hash) && self.check_contains_hashes(value)) }+ hash.all? { |_key, value| value.is_a?(String) || (value.is_a?(Hash) && self.check_contains_hashes(value)) }enddef load@@ -21,13 +21,18 @@ class ThemeTranslationParserrescue Psych::SyntaxError, Psych::DisallowedClass => eraise InvalidYaml.new(e.message)end- raise InvalidYaml.new(I18n.t("themes.locale_errors.invalid_yaml")) unless parsed.is_a?(Hash) && ThemeTranslationParser.check_contains_hashes(parsed)- raise InvalidYaml.new(I18n.t("themes.locale_errors.top_level_locale")) unless parsed.keys.length == 1 && parsed.keys[0] == @setting_field.name+ raise InvalidYaml.new(I18n.t("themes.locale_errors.invalid_yaml")) if !parsed.is_a?(Hash)+ raise InvalidYaml.new(I18n.t("themes.locale_errors.top_level_locale")) if parsed.keys.length != 1 || parsed.keys.first != @setting_field.name++ key = @setting_field.name.to_symparsed.deep_symbolize_keys!+ parsed[key] ||= {}++ raise InvalidYaml.new(I18n.t("themes.locale_errors.invalid_yaml")) if !ThemeTranslationParser.check_contains_hashes(parsed)- parsed[@setting_field.name.to_sym].slice!(*INTERNAL_KEYS) if @internal- parsed[@setting_field.name.to_sym].except!(*INTERNAL_KEYS) if !@internal+ parsed[key].slice!(*INTERNAL_KEYS) if @internal+ parsed[key].except!(*INTERNAL_KEYS) if !@internalparsedenddiff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rbindex 6146f2c8018..3e31fdac8a5 100644--- a/spec/models/theme_field_spec.rb+++ b/spec/models/theme_field_spec.rb@@ -342,6 +342,14 @@ HTMLfr1.update(value: "fr: 'valuewithoutclosequote")expect { fr1.raw_translation_data }.to raise_error(ThemeTranslationParser::InvalidYaml)end++ it "works when locale file doesn't contain translations" do+ fr1.update(value: "fr:")+ expect(fr1.translation_data).to eq(+ fr: {},+ en: { somestring1: "helloworld", group: { key1: "enval1" } }+ )+ endenddescribe "#translation_data" do