diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 228be479e..152dc3f18 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -201,7 +201,7 @@ class ApplicationController < ActionController::Base if User.current.logged? lang = find_language(User.current.language) end - if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE'] + if lang.nil? && !Setting.force_default_language_for_anonymous? && request.env['HTTP_ACCEPT_LANGUAGE'] accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first if !accept_lang.blank? accept_lang = accept_lang.downcase diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index a01e29a3a..8dcc1ecb6 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -79,7 +79,7 @@ module SettingsHelper def setting_label(setting, options={}) label = options.delete(:label) - label != false ? label_tag("settings_#{setting}", l(label || "setting_#{setting}")).html_safe : '' + label != false ? label_tag("settings_#{setting}", l(label || "setting_#{setting}"), options[:label_options]).html_safe : '' end # Renders a notification field for a Redmine::Notifiable option diff --git a/app/models/user.rb b/app/models/user.rb index d04369277..7aac01235 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -314,6 +314,18 @@ class User < Principal @time_zone ||= (self.pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[self.pref.time_zone]) end + def force_default_language? + Setting.force_default_language_for_loggedin? + end + + def language + if force_default_language? + Setting.default_language + else + super + end + end + def wants_comments_in_reverse_order? self.pref[:comments_sorting] == 'desc' end diff --git a/app/views/account/register.html.erb b/app/views/account/register.html.erb index e8e8098fe..f655514a3 100644 --- a/app/views/account/register.html.erb +++ b/app/views/account/register.html.erb @@ -16,7 +16,10 @@

<%= f.text_field :firstname, :required => true %>

<%= f.text_field :lastname, :required => true %>

<%= f.text_field :mail, :required => true %>

+ +<% unless @user.force_default_language? %>

<%= f.select :language, lang_options_for_select %>

+<% end %> <% if Setting.openid? %>

<%= f.text_field :identity_url %>

diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index 8ec3a8dc9..0ce223b0a 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -16,7 +16,9 @@

<%= f.text_field :firstname, :required => true %>

<%= f.text_field :lastname, :required => true %>

<%= f.text_field :mail, :required => true %>

+ <% unless @user.force_default_language? %>

<%= f.select :language, lang_options_for_select %>

+ <% end %> <% if Setting.openid? %>

<%= f.text_field :identity_url %>

<% end %> diff --git a/app/views/settings/_display.html.erb b/app/views/settings/_display.html.erb index 1ae5a351a..ab1ce9b9b 100644 --- a/app/views/settings/_display.html.erb +++ b/app/views/settings/_display.html.erb @@ -5,6 +5,10 @@

<%= setting_select :default_language, lang_options_for_select(false) %>

+

<%= setting_check_box :force_default_language_for_anonymous %>

+ +

<%= setting_check_box :force_default_language_for_loggedin %>

+

<%= setting_select :start_of_week, [[day_name(1),'1'], [day_name(6),'6'], [day_name(7),'7']], :blank => :label_language_based %>

<% locale = User.current.language.blank? ? ::I18n.locale : User.current.language %>

<%= setting_select :date_format, Setting::DATE_FORMATS.collect {|f| [::I18n.l(Date.today, :locale => locale, :format => f), f]}, :blank => :label_language_based %>

diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index e90095827..413e3550b 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -9,7 +9,9 @@

<%= f.text_field :firstname, :required => true %>

<%= f.text_field :lastname, :required => true %>

<%= f.text_field :mail, :required => true %>

+ <% unless @user.force_default_language? %>

<%= f.select :language, lang_options_for_select %>

+ <% end %> <% if Setting.openid? %>

<%= f.text_field :identity_url %>

<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index f9b459577..c9256ae40 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -408,6 +408,8 @@ en: setting_jsonp_enabled: Enable JSONP support setting_default_projects_tracker_ids: Default trackers for new projects setting_mail_handler_excluded_filenames: Exclude attachments by name + setting_force_default_language_for_anonymous: Force default language for anonymous users + setting_force_default_language_for_loggedin: Force default language for logged-in users permission_add_project: Create project permission_add_subprojects: Create subprojects diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 29bb08428..2eff8fcd3 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -405,6 +405,8 @@ fr: setting_jsonp_enabled: Activer le support JSONP setting_default_projects_tracker_ids: Trackers par défaut pour les nouveaux projets setting_mail_handler_excluded_filenames: Exclure les fichiers attachés par leur nom + setting_force_default_language_for_anonymous: Forcer la langue par défault pour les utilisateurs anonymes + setting_force_default_language_for_loggedin: Forcer la langue par défault pour les utilisateurs identifiés permission_add_project: Créer un projet permission_add_subprojects: Créer des sous-projets diff --git a/config/settings.yml b/config/settings.yml index 66c67bd01..832f68501 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -69,6 +69,10 @@ wiki_compression: default: "" default_language: default: en +force_default_language_for_anonymous: + default: 0 +force_default_language_for_loggedin: + default: 0 host_name: default: localhost:3000 protocol: diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index ba59b2828..6ebb91d3c 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -502,7 +502,7 @@ html>body .tabular p {overflow:hidden;} text-align: left; float: none; display: block; - width: auto; + width: auto !important; } .tabular label.inline{ diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index 7e9677051..aaa4e8c0d 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -82,6 +82,20 @@ class MyControllerTest < ActionController::TestCase assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} end + def test_my_account_should_show_language_select + get :account + assert_response :success + assert_select 'select[name=?]', 'user[language]' + end + + def test_my_account_should_not_show_language_select_with_force_default_language_for_loggedin + with_settings :force_default_language_for_loggedin => '1' do + get :account + assert_response :success + assert_select 'select[name=?]', 'user[language]', 0 + end + end + def test_update_account post :account, :user => { diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb index aafc36159..6a9107844 100644 --- a/test/functional/welcome_controller_test.rb +++ b/test/functional/welcome_controller_test.rb @@ -54,6 +54,35 @@ class WelcomeControllerTest < ActionController::TestCase assert_equal :fr, @controller.current_language end + def test_browser_language_should_be_ignored_with_force_default_language_for_anonymous + Setting.default_language = 'en' + @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' + with_settings :force_default_language_for_anonymous => '1' do + get :index + assert_equal :en, @controller.current_language + end + end + + def test_user_language_should_be_used + Setting.default_language = 'fi' + user = User.find(2).update_attribute :language, 'it' + @request.session[:user_id] = 2 + @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' + get :index + assert_equal :it, @controller.current_language + end + + def test_user_language_should_be_ignored_if_force_default_language_for_loggedin + Setting.default_language = 'fi' + user = User.find(2).update_attribute :language, 'it' + @request.session[:user_id] = 2 + @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' + with_settings :force_default_language_for_loggedin => '1' do + get :index + assert_equal :fi, @controller.current_language + end + end + def test_robots get :robots assert_response :success