Cannot update text for js.composer.error.post_length

AI-generated summary

Users are troubleshooting an issue with updating the translation text for js.composer.error.post_length in Discourse, which displays [missing {{min}} value] despite the value being set. The error log reveals a NoMethodError due to scan being called on a Hash instead of a String, stemming from a pluralized translation format using %{count} (not %{min}) introduced in 2021 zcuric. gerhard advises reverting the customization via Customize → Text, then re-editing both plural forms. sam suggests improving error handling to fall back to English and log issues. zcuric reports that enabling Safe Mode resolved the JS error (get_attributes, null dialog) and automatically corrected the translation, allowing normal operation to resume after disabling Safe Mode. The issue appears tied to theme or JS conflicts, temporarily resolved by Safe Mode.

I’m trying to update text for js.composer.error.post_length. Experiencing this on 2.9 and 3.1.0.beta2, on production, staging and in my local environment.

On FE it shows [missing {{min}} value] although value has been set.

Error log says:

NoMethodError (undefined method `scan' for {:one=>"Post must be at least %{count} character", :other=>"Post must be at least %{count} characters"}:Hash keys = text.scan(pattern) ^^
Message

NoMethodError (undefined method `scan' for {:one=>"Post must be at least %{count} character", :other=>"Post must be at least %{count} characters"}:Hash

    keys = text.scan(pattern)
               ^^^^^)
lib/i18n/i18n_interpolation_keys_finder.rb:6:in `find'
app/models/translation_override.rb:123:in `check_interpolation_keys'
app/models/translation_override.rb:64:in `upsert!'
app/controllers/admin/site_texts_controller.rb:88:in `update'
app/controllers/application_controller.rb:414:in `block in with_resolved_locale'
app/controllers/application_controller.rb:414:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:74:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/missing_avatars.rb:22:in `call'
lib/middleware/turbo_dev.rb:31:in `call'

Backtrace

lib/i18n/i18n_interpolation_keys_finder.rb:6:in `find'
app/models/translation_override.rb:123:in `check_interpolation_keys'
activesupport (7.0.4) lib/active_support/callbacks.rb:400:in `block in make_lambda'
activesupport (7.0.4) lib/active_support/callbacks.rb:199:in `block (2 levels) in halting'
activesupport (7.0.4) lib/active_support/callbacks.rb:687:in `block (2 levels) in default_terminator'
activesupport (7.0.4) lib/active_support/callbacks.rb:686:in `catch'
activesupport (7.0.4) lib/active_support/callbacks.rb:686:in `block in default_terminator'
activesupport (7.0.4) lib/active_support/callbacks.rb:200:in `block in halting'
activesupport (7.0.4) lib/active_support/callbacks.rb:595:in `block in invoke_before'
activesupport (7.0.4) lib/active_support/callbacks.rb:595:in `each'

Env

HTTP HOSTS: 127.0.0.1:3000

That string was changed back in 2021. It uses %{count} instead of %{min} and has been converted into a pluralized string (one, other).

You can fix your customized string by going to Customize → Text:

  • Search for “js.composer.error.post_length”
  • click “edit”
  • click “revert changes” and confirm the question with “yes”
  • click “back to search”
  • Search for “js.composer.error.post_length”
  • You will see 2 results, customize both strings if you wish

I wonder, could we build error handling that falls back to English in these cases and logs something?

For some reason I couldn’t get this to work, the confirmation dialog was not opening because JS error ‘get_attributes’, the dialog element was null.

But then I turned the safe-mode, check if it was working and everything was updated automatically. I turned off safe-mode, went back to my theme and again, all was working as intended.

So safe-mode fixed it I guess. And there is no more JS error mentioned above. (Should have tried with safe-mode in the first place, smh).

Thanks for your help!