diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ecb6749..bb103ab 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,31 +23,11 @@ # Sets FastGettext locale for every request made def set_gettext_locale - # If there is no locale set in the session and the current_user exists (meaning the user has just logged in) - if session[:locale].nil? && !current_user.nil? - if current_user.language.nil? - if current_user.org.language.nil? - # The User and Org do not have any language specifications so use the default locale - session[:locale] = FastGettext.default_locale - - else - # The User does not have a language specification but the Org does - session[:locale] = current_user.org.language - end - - else - # The User has a language specification - session[:locale] = current_user.language - end - - # This doesn't seem to do anything ... the locale never seems to change - FastGettext.locale = session[:locale] - end + FastGettext.locale = session[:locale] || FastGettext.default_locale end # PATCH /locale/:locale REST method def set_locale_session - if FastGettext.default_available_locales.include?(params[:locale]) session[:locale] = params[:locale] end diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 826023b..ca95384 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -23,7 +23,7 @@ end # ---------------------------------------------------------------- - test "a user's language specification is set in the session" do + test "a user's language specification gets picked up and set in the session" do if LANGUAGES.count > 1 @user.language = LANGUAGES.last @user.save! @@ -32,12 +32,12 @@ get root_path - assert_equal @user.language, session[:locale], "Expected the locale to have been set to the user's chosen language" + assert_equal @user.language.abbreviation, FastGettext.locale, "Expected the locale to have been set to the user's chosen language" end end # ---------------------------------------------------------------- - test "a user's org language specification is used if no locale is passed in the URL and the user has no language setting" do + test "a user's org language specification gets picked up and used if the user has no language setting" do if LANGUAGES.count > 1 @user.language = nil @user.org[:language_id] = LANGUAGES.last.id @@ -47,7 +47,7 @@ get root_path org_lang = Language.find(@user.org[:language_id]) - assert_equal org_lang, session[:locale], "Expected the locale to have been set to the org's chosen language" + assert_equal org_lang.abbreviation, FastGettext.locale, "Expected the locale to have been set to the org's chosen language" end end diff --git a/test/functional/registrations_controller_test.rb b/test/functional/registrations_controller_test.rb index d548ebe..0ceb110 100644 --- a/test/functional/registrations_controller_test.rb +++ b/test/functional/registrations_controller_test.rb @@ -61,7 +61,7 @@ post user_registration_path, {user: params} assert_response :redirect - assert_redirected_to "#{root_url}?locale=#{I18n.locale}" + assert_redirected_to root_url follow_redirect! assert_response :success diff --git a/test/test_helper.rb b/test/test_helper.rb index 5e6b305..46366a8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -101,7 +101,7 @@ follow_redirects assert_response :success - assert_select '.welcome-message h2', I18n.t('welcome_title') + assert_select '.welcome-message h2', _('Welcome.') end # ---------------------------------------------------------------------- @@ -113,7 +113,7 @@ follow_redirects assert_response :success - assert_select '.main_page_content h1', I18n.t("helpers.project.projects_title") + assert_select '.main_page_content h1', _('My plans') end # ----------------------------------------------------------------------