-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix problem with reload not working correctly when auto is set for language #68
Conversation
return if custom_message_setting.latest_messages_applied?(current_user_language) | ||
# NOTE: ApplicationController#set_localization sets the appropriate language in I18n.locale | ||
return if custom_message_setting.latest_messages_applied?(I18n.locale) | ||
|
||
MessageCustomize::Locale.reload!([current_user_language]) | ||
end | ||
|
||
private | ||
|
||
def current_user_language | ||
User.current.language.presence || Setting.default_language |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is still being used in the following locations.
params[:lang].presence || @setting.custom_messages.keys.first || current_user_language |
As a result, when no message customization settings are registered, visiting the message customization settings screen (/custom_message_settings/edit
) causes the following error:
NameError (undefined local variable or method `current_user_language' for an instance of CustomMessageSettingsController):
plugins/redmine_message_customize/app/controllers/custom_message_settings_controller.rb:57:in `set_lang'
How about fixing it like this?
diff --git a/lib/message_customize/application_controller_patch.rb b/lib/message_customize/application_controller_patch.rb
index 10b8abe..666210d 100644
--- a/lib/message_customize/application_controller_patch.rb
+++ b/lib/message_customize/application_controller_patch.rb
@@ -20,7 +20,7 @@ module MessageCustomize
private
def current_user_language
- User.current.language.presence || Setting.default_language
+ I18n.locale
end
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hidakatsuya
Thanks for the feedback.
How about fixing it like this?
...
You're right, that makes sense. I'll go with current_user_language as it's clearer and easier to maintain.
f8d6844 fixes this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -26,8 +26,28 @@ def test_reload_if_messages_are_not_latest | |||
assert_equal custom_message_setting.updated_on.to_i.to_s, I18n.backend.send(:translations)[:en][:redmine_message_customize_timestamp] | |||
end | |||
|
|||
def test_reload_if_user_language_is_auto_and_browser_language_messages_are_not_latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
Issue:
There is a problem where, if a user's language setting is set to auto and the browser's language differs from the default language, the customized settings are not loaded correctly.
Reproduction steps:
Fix:
Use
I18n.locale
instead ofUser.current.language.presence || Setting.default_language
.I18n.locale
has terms set with appropriate priority by ApplicationController#set_localication and others. https://github.com/redmica/redmica/blob/master/app/controllers/application_controller.rb#L247-L261