mainio / decidim-module-term_customizer

Decidim module that allows customizing the localization terms in the system for specific contexts.
GNU Affero General Public License v3.0
16 stars 21 forks source link

Term customizer crashes Decidim if using hierarchical keys #116

Open microstudi opened 9 months ago

microstudi commented 9 months ago

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: https://github.com/mainio/decidim-module-term_customizer/blob/03e6c98e85a00fe47f8db2726f1a1a98e808efda/lib/decidim/term_customizer/loader.rb#L51

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