mainio/decidim-module-term_customizer

Term customizer crashes Decidim if using hierarchical keys

microstudi opened this issue · 0 comments

Term Customizer allows you to set translation keys of this type:

en.level1.level2 => "Some text"
en.level1.level2.string1=> "Another text"

However this does not matches a valid YAML file that would be:

Invalid YAML equivalence:

en:
  level1:
    level2: Some text
      string1: Another text

So, if a key have children, it shouldn't be allowed to create a translation in it. And reverse, if a translation exists and you try to create a children of it, should not be allowed either.

I think it should be a rule to enforce that keys do not define translations if they have "children". We had quite a headache finding this bug.

Another possible solution is to break the loop here in case current is already a string:

ie:

              current = final_hash
              keyparts.each do |key|
                current[key.to_sym] ||= {}
                current = current[key.to_sym]
                next unless current.is_a?(Hash)
              end

This might be easier to implement but it would allow invalid yamls to be created (maybe is not important though).

I can contribute if you let me know what you prefer