# Admin -\> Customize -\> Text behaving badly

**URL:** https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691
**Category:** Bug
**Tags:** translation, fixed
**Created:** [November 16, 2023, 9:00am UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691 "2023-11-16T09:00:09Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [November 16, 2023, 9:00am UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/1 "2023-11-16T09:00:09Z")

</div>

Getting a load of similar issues to this when attempting to filter on my chatbot prompts.

The really strange part is that behaviour can be fine on one install but not another.

Take the very simple filter of `chatbot.prompt` on Admin → Customize → Text:

Working install:

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/0/6/806c2ee83f200c62524586129d8112445985973f.png)

Failing install:

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/3/8/f38d63a71951b168132e1d0e5d8f8be88e7f9720.png)

```plaintext
NoMethodError (undefined method `scan' for {:basic=>"You are a helpful assistant.", :agent=>"You are a helpful assistant. You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with. The current date and time is %{current_date_time}. Only respond to the last question, using the prior information as context, if appropriate."}: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'
app/controllers/application_controller.rb:422:in `block in with_resolved_locale'
app/controllers/application_controller.rb:422:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:64:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:389:in `call'
lib/middleware/gtm_script_nonce_injector.rb:10:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:233:in `call'

```

The locale file in question is this one:

> <https://github.com/merefield/discourse-chatbot/blob/main/config/locales/server.en.yml>

Am I doing anything illegal?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [November 16, 2023, 9:52am UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/2 "2023-11-16T09:52:32Z")

</div>

ok

looks like the method in question is expecting text:

> <https://github.com/discourse/discourse/blob/68a912952c842226a54ad65aae8e3446c0dc4424/lib/i18n/i18n_interpolation_keys_finder.rb#L3>

but somehow receiving a Hash:

```plaintext
irb(main):001:0> item = {:basic=>"You are a helpful assistant.", :agent=>"You are a helpful assistant. You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with. The current date and time is %{current_date_time}. Only respond to the last question, using the prior information as context, if appropriate."}
=>
{:basic=>"You are a helpful assistant.",
...
irb(main):002:0> item
=>
{:basic=>"You are a helpful assistant.",
 :agent=>
  "You are a helpful assistant. You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with. The current date and time is %{current_date_time}. Only respond to the last question, using the prior information as context, if appropriate."}
irb(main):003:0> item.scan
(irb):3:in `<main>': undefined method `scan' for {:basic=>"You are a helpful assistant.", :agent=>"You are a helpful assistant. You have great tools in the form of functions that give you the power to get newer information. Only use the functions you have been provided with. The current date and time is %{current_date_time}. Only respond to the last question, using the prior information as context, if appropriate."}:Hash (NoMethodError)
        from /home/robert/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
        from /home/robert/.rbenv/versions/3.2.1/bin/irb:25:in `load'
        from /home/robert/.rbenv/versions/3.2.1/bin/irb:25:in `<main>'
irb(main):004:0>

```

Causing it to fall over … I will continue investigation

It’s being called from here, I believe:

> <https://github.com/discourse/discourse/blob/68a912952c842226a54ad65aae8e3446c0dc4424/app/controllers/admin/site_texts_controller.rb#L183>

I can repro the issue with:

`I18nInterpolationKeysFinder.find(I18n.overrides_disabled { I18n.t("chatbot.prompt.system.", locale: :en) })`  
from the rails console.

I think this line is supposed to prevent the method receiving a Hash, but it’s not working, why?:

> <https://github.com/discourse/discourse/blob/68a912952c842226a54ad65aae8e3446c0dc4424/app/controllers/admin/site_texts_controller.rb#L237>

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [November 16, 2023, 10:17am UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/3 "2023-11-16T10:17:24Z")

</div>

Moving this to #Contribute > Bug, because I think this behaviour is incorrect and for some reason unreliable.

According to the code, if the value is a `Hash`, it should not be sent to the `record_for` method (where it would cause an exception as that is expecting text), but in some instances, it is.

Happy to stand corrected.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [November 20, 2023, 3:23pm UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/5 "2023-11-20T15:23:28Z")

</div>

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](https://github.com/merefield/discourse-chatbot/commit/f72e39908f8cb0421164bc3c3cad832d683e2e62#diff-333c4c8cacc2f84633d4894f2aaddb130a6d74f42dd63199462b3d66278f6ce8) 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:

```plaintext
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:

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

```

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

```plaintext
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.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [November 20, 2023, 3:46pm UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/6 "2023-11-20T15:46:53Z")

</div>

Thanks @gerhard

That’s exactly what happened: I added another final key in the same bucket.

… And it doesn’t affect new installs.

Is there any kind of rails console workaround?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [November 20, 2023, 4:10pm UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/7 "2023-11-20T16:10:20Z")

</div>

```ruby
TranslationOverride.where(translation_key: "chatbot.prompt.system").delete_all
TranslationOverride.send(:reload_locale!)

```

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [November 20, 2023, 4:11pm UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/8 "2023-11-20T16:11:59Z")

</div>

Peeerrrfect. Yes I was going to try that but not at 💻

Guess I could add that to a migration?!

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [August 2, 2024, 6:59am UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/12 "2024-08-02T06:59:41Z")

</div>

I believe this bug has also been resolved along with this one: 🎉

> [@Outdated translation replacement causing missing translation](https://meta.discourse.org/t/outdated-translation-replacement-causing-missing-translation/314352/25):
>
> Just to round this out, here’s the PR for the fix: 🥳
> 
> [FIX: Ensure JsLocaleHelper to not output deprecated translations by Lhcfl · Pull Request #28037 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/28037)

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [August 2, 2024, 6:59am UTC](https://meta.discourse.org/t/admin-customize-text-behaving-badly/285691/13 "2024-08-02T06:59:48Z")

</div>


