Adds settings for disabling browser language detection and language preference (#2691).

git-svn-id: http://svn.redmine.org/redmine/trunk@12691 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2014-01-24 10:28:12 +00:00
parent 6e6c6fac5c
commit e391be4086
13 changed files with 77 additions and 3 deletions

View File

@ -201,7 +201,7 @@ class ApplicationController < ActionController::Base
if User.current.logged? if User.current.logged?
lang = find_language(User.current.language) lang = find_language(User.current.language)
end 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 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
if !accept_lang.blank? if !accept_lang.blank?
accept_lang = accept_lang.downcase accept_lang = accept_lang.downcase

View File

@ -79,7 +79,7 @@ module SettingsHelper
def setting_label(setting, options={}) def setting_label(setting, options={})
label = options.delete(:label) 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 end
# Renders a notification field for a Redmine::Notifiable option # Renders a notification field for a Redmine::Notifiable option

View File

@ -314,6 +314,18 @@ class User < Principal
@time_zone ||= (self.pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[self.pref.time_zone]) @time_zone ||= (self.pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[self.pref.time_zone])
end 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? def wants_comments_in_reverse_order?
self.pref[:comments_sorting] == 'desc' self.pref[:comments_sorting] == 'desc'
end end

View File

@ -16,7 +16,10 @@
<p><%= f.text_field :firstname, :required => true %></p> <p><%= f.text_field :firstname, :required => true %></p>
<p><%= f.text_field :lastname, :required => true %></p> <p><%= f.text_field :lastname, :required => true %></p>
<p><%= f.text_field :mail, :required => true %></p> <p><%= f.text_field :mail, :required => true %></p>
<% unless @user.force_default_language? %>
<p><%= f.select :language, lang_options_for_select %></p> <p><%= f.select :language, lang_options_for_select %></p>
<% end %>
<% if Setting.openid? %> <% if Setting.openid? %>
<p><%= f.text_field :identity_url %></p> <p><%= f.text_field :identity_url %></p>

View File

@ -16,7 +16,9 @@
<p><%= f.text_field :firstname, :required => true %></p> <p><%= f.text_field :firstname, :required => true %></p>
<p><%= f.text_field :lastname, :required => true %></p> <p><%= f.text_field :lastname, :required => true %></p>
<p><%= f.text_field :mail, :required => true %></p> <p><%= f.text_field :mail, :required => true %></p>
<% unless @user.force_default_language? %>
<p><%= f.select :language, lang_options_for_select %></p> <p><%= f.select :language, lang_options_for_select %></p>
<% end %>
<% if Setting.openid? %> <% if Setting.openid? %>
<p><%= f.text_field :identity_url %></p> <p><%= f.text_field :identity_url %></p>
<% end %> <% end %>

View File

@ -5,6 +5,10 @@
<p><%= setting_select :default_language, lang_options_for_select(false) %></p> <p><%= setting_select :default_language, lang_options_for_select(false) %></p>
<p><%= setting_check_box :force_default_language_for_anonymous %></p>
<p><%= setting_check_box :force_default_language_for_loggedin %></p>
<p><%= setting_select :start_of_week, [[day_name(1),'1'], [day_name(6),'6'], [day_name(7),'7']], :blank => :label_language_based %></p> <p><%= setting_select :start_of_week, [[day_name(1),'1'], [day_name(6),'6'], [day_name(7),'7']], :blank => :label_language_based %></p>
<% locale = User.current.language.blank? ? ::I18n.locale : User.current.language %> <% locale = User.current.language.blank? ? ::I18n.locale : User.current.language %>
<p><%= setting_select :date_format, Setting::DATE_FORMATS.collect {|f| [::I18n.l(Date.today, :locale => locale, :format => f), f]}, :blank => :label_language_based %></p> <p><%= setting_select :date_format, Setting::DATE_FORMATS.collect {|f| [::I18n.l(Date.today, :locale => locale, :format => f), f]}, :blank => :label_language_based %></p>

View File

@ -9,7 +9,9 @@
<p><%= f.text_field :firstname, :required => true %></p> <p><%= f.text_field :firstname, :required => true %></p>
<p><%= f.text_field :lastname, :required => true %></p> <p><%= f.text_field :lastname, :required => true %></p>
<p><%= f.text_field :mail, :required => true %></p> <p><%= f.text_field :mail, :required => true %></p>
<% unless @user.force_default_language? %>
<p><%= f.select :language, lang_options_for_select %></p> <p><%= f.select :language, lang_options_for_select %></p>
<% end %>
<% if Setting.openid? %> <% if Setting.openid? %>
<p><%= f.text_field :identity_url %></p> <p><%= f.text_field :identity_url %></p>
<% end %> <% end %>

View File

@ -408,6 +408,8 @@ en:
setting_jsonp_enabled: Enable JSONP support setting_jsonp_enabled: Enable JSONP support
setting_default_projects_tracker_ids: Default trackers for new projects setting_default_projects_tracker_ids: Default trackers for new projects
setting_mail_handler_excluded_filenames: Exclude attachments by name 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_project: Create project
permission_add_subprojects: Create subprojects permission_add_subprojects: Create subprojects

View File

@ -405,6 +405,8 @@ fr:
setting_jsonp_enabled: Activer le support JSONP setting_jsonp_enabled: Activer le support JSONP
setting_default_projects_tracker_ids: Trackers par défaut pour les nouveaux projets 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_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_project: Créer un projet
permission_add_subprojects: Créer des sous-projets permission_add_subprojects: Créer des sous-projets

View File

@ -69,6 +69,10 @@ wiki_compression:
default: "" default: ""
default_language: default_language:
default: en default: en
force_default_language_for_anonymous:
default: 0
force_default_language_for_loggedin:
default: 0
host_name: host_name:
default: localhost:3000 default: localhost:3000
protocol: protocol:

View File

@ -502,7 +502,7 @@ html>body .tabular p {overflow:hidden;}
text-align: left; text-align: left;
float: none; float: none;
display: block; display: block;
width: auto; width: auto !important;
} }
.tabular label.inline{ .tabular label.inline{

View File

@ -82,6 +82,20 @@ class MyControllerTest < ActionController::TestCase
assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
end 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 def test_update_account
post :account, post :account,
:user => { :user => {

View File

@ -54,6 +54,35 @@ class WelcomeControllerTest < ActionController::TestCase
assert_equal :fr, @controller.current_language assert_equal :fr, @controller.current_language
end 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 def test_robots
get :robots get :robots
assert_response :success assert_response :success