Admin -> Customize -> Text behaving badly

This happens when there’s a translation override for a key that previously was a translatable string, but was converted into a Hash at a later time. That’s exactly what happened with chatbot.prompt.system.

This seems like a regression. I’m pretty sure this used to work in the past.

I can easily reproduce this with a locale file like this:

en:
  foo: "this is foo"

Go to Customize → Text and override “foo” with a different value.

Then, change the locale file to look like this:

en:
  foo:
    basic: "Basic Foo"
    advanced: "Advanced Foo"

Visit Customize → Text again and search for “foo”. Discourse will log the following error.

NoMethodError (undefined method `scan' for {:basic=>"Basic Foo", :advanced=>"Advanced Foo"}:Hash)
lib/i18n/i18n_interpolation_keys_finder.rb:6:in `find'
app/controllers/admin/site_texts_controller.rb:183:in `record_for'
app/controllers/admin/site_texts_controller.rb:249:in `block in find_translations'
app/controllers/admin/site_texts_controller.rb:234:in `each'
app/controllers/admin/site_texts_controller.rb:234:in `find_translations'
app/controllers/admin/site_texts_controller.rb:34:in `index'

Discourse shouldn’t load translation overrides if there’s no corresponding English string.

4 Likes