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:
parent
6e6c6fac5c
commit
e391be4086
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
<p><%= f.text_field :firstname, :required => true %></p>
|
||||
<p><%= f.text_field :lastname, :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>
|
||||
<% end %>
|
||||
|
||||
<% if Setting.openid? %>
|
||||
<p><%= f.text_field :identity_url %></p>
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
<p><%= f.text_field :firstname, :required => true %></p>
|
||||
<p><%= f.text_field :lastname, :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>
|
||||
<% end %>
|
||||
<% if Setting.openid? %>
|
||||
<p><%= f.text_field :identity_url %></p>
|
||||
<% end %>
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
|
||||
<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>
|
||||
<% 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>
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
<p><%= f.text_field :firstname, :required => true %></p>
|
||||
<p><%= f.text_field :lastname, :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>
|
||||
<% end %>
|
||||
<% if Setting.openid? %>
|
||||
<p><%= f.text_field :identity_url %></p>
|
||||
<% end %>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue