Skip to content

Commit

Permalink
Merge pull request #68 from farend/support-auto-language
Browse files Browse the repository at this point in the history
Fix problem with reload not working correctly when auto is set for language
  • Loading branch information
ishikawa999 authored Sep 17, 2024
2 parents f1761f3 + f8d6844 commit 17faa39
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/message_customize/application_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def reload_customize_messages

private

# NOTE: ApplicationController#set_localization sets the appropriate language in I18n.locale
def current_user_language
User.current.language.presence || Setting.default_language
I18n.locale
end
end
end
Expand Down
22 changes: 21 additions & 1 deletion test/integration/application_controller_patch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Reload based on the browser language if the language in User.current is ''(auto)
User.find_by_login('admin').update(language: '')
log_user('admin', 'admin')
custom_message_setting = CustomMessageSetting.find_or_default

custom_message_setting.update_with_custom_messages({'label_home' => 'Changed home'}, 'ja')
assert_equal 'Home2', I18n.backend.send(:translations)[:ja][:label_home]
assert_equal '1640995200', I18n.backend.send(:translations)[:ja][:redmine_message_customize_timestamp]
with_settings :default_language => 'en' do
dummy_http_headers = @request.env
dummy_http_headers['HTTP_ACCEPT_LANGUAGE'] = 'ja'
ActionDispatch::Request.any_instance.stubs(:env).returns(dummy_http_headers)

get '/issues'
end
assert_equal 'Changed home', I18n.backend.send(:translations)[:ja][:label_home]
assert_equal custom_message_setting.updated_on.to_i.to_s, I18n.backend.send(:translations)[:ja][:redmine_message_customize_timestamp]
end

def test_reload_if_user_language_is_auto_and_default_language_messages_are_not_latest
# User.currentのlanguageが''(auto)でもSetting.default_languageを元に用語の最新化を行うこと
# Reload based on the default language if the language in User.current is ''(auto) and request.env['HTTP_ACCEPT_LANGUAGE'] is nil
User.find_by_login('admin').update(language: '')
log_user('admin', 'admin')
custom_message_setting = CustomMessageSetting.find_or_default
Expand Down

0 comments on commit 17faa39

Please sign in to comment.