zulip / zulip-redmine-plugin

Redmine plugin for Zulip notifications on issue tracker changes
Apache License 2.0
12 stars 17 forks source link

FrozenError if Setting.default_language has no translation #23

Closed hi-ko closed 4 years ago

hi-ko commented 4 years ago

The code reads Setting.default_language but does not handle missing translations for the system default language in lib/redmine_zulip/issue_patch.rb e.g.

   def update_issue_subject
      locale = Setting.default_language
      message = I18n.t("zulip_notify_updated", {
        locale: locale,
        user: User.current.name,
        id: id,
        url: url,
        subject: subject_without_punctuation,
      })

To reproduce set redmine default language to de (german) which has no tranlsation yet in config/locales and you will get a http 500 on ticket updates and in the redmine log:

Started PATCH "/issues/7436" for 1.2.3.4 at 2019-10-15 07:15:58 +0000
Processing by IssuesController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"asdfasdfsadfX0a+gxcQ4jVnDkAezE0UUWBM+asdfasdfasdf/Rt1pmX1ZVfmUF5FPGg==", "form_update_triggered_by"=>"",        "issue"=>{"is_private"=>"0", "project_id"=>"132", "author_id"=>"3", "tracker_id"=>"3", "subject"=>"test", "description"=>"yet another test", "status_id"=>"1", "priority_id"       =>"4", "assigned_to_id"=>"", "parent_issue_id"=>"", "start_date"=>"2019-10-15", "due_date"=>"", "estimated_hours"=>"", "done_ratio"=>"0", "custom_field_values"=>{"12"=>""},        "tag_list"=>[""], "checklist_template_id"=>"", "notes"=>"", "private_notes"=>"0", "lock_version"=>"5"}, "was_default_status"=>"1", "time_entry"=>{"hours"=>"", "activity_id"=       >"", "comments"=>""}, "last_journal_id"=>"33486", "commit"=>"OK", "next_issue_id"=>"7062", "issue_position"=>"1", "issue_count"=>"3", "id"=>"7436"}
  Current user: testiser (id=3)
Completed 500 Internal Server Error in 65ms (ActiveRecord: 12.3ms)

FrozenError (can't modify frozen String):

plugins/redmine_zulip/lib/redmine_zulip/issue_patch.rb:280:in `update_issue_subject'
app/controllers/issues_controller.rb:552:in `save_issue_with_child_records'
app/controllers/issues_controller.rb:169:in `update'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
batistadasilva commented 4 years ago

@hi-ko thank you for the feedback, this is gonna be fixed

batistadasilva commented 4 years ago

hello @hi-ko, please try the new unreleased versions 2.1-alpha1 or 3.1-alpha1

thank you!

hi-ko commented 4 years ago

Yes, now the message is being send with "translation missing: de.zulip_notify_updated". I guess it is not possible to define en as fallback?

Thanks for fixing this!

batistadasilva commented 4 years ago

@hi-ko it is possible, but it depends on Redmine installation

please try running

RAILS_ENV=production rails console

..on Rails console, check the following:

I18n.default_locale

I got en as default locale on my installation and messages are translated into english as default

default_locale

hi-ko commented 4 years ago

same here:

irb(main):001:0> I18n.default_locale
=> :en

but the plugin returns ""translation missing: ..." since I testet with redmine application default language "de". What I meant was: nice to have would be a fall back to a (plugin defined) fall back locale: en to avoid these nasty warnings ;-)

Thanks for your excellent work!