<p><%= setting_select :default_language, lang_options_for_select(false) %></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>
-<p><%= setting_select :date_format, Setting::DATE_FORMATS.collect {|f| [Date.today.strftime(f), f]}, :blank => :label_language_based %></p>
-
-<p><%= setting_select :time_format, Setting::TIME_FORMATS.collect {|f| [Time.now.strftime(f), f]}, :blank => :label_language_based %></p>
+<p><%= setting_select :time_format, Setting::TIME_FORMATS.collect {|f| [::I18n.l(Time.now, :locale => locale, :format => f), f]}, :blank => :label_language_based %></p>
<p><%= setting_select :user_format, @options[:user_format] %></p>
def format_date(date)
return nil unless date
- Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format)
+ options = {}
+ options[:format] = Setting.date_format unless Setting.date_format.blank?
+ options[:locale] = User.current.language unless User.current.language.blank?
+ ::I18n.l(date.to_date, options)
end
def format_time(time, include_date = true)
return nil unless time
+ options = {}
+ options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format)
+ options[:locale] = User.current.language unless User.current.language.blank?
time = time.to_time if time.is_a?(String)
zone = User.current.time_zone
local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
- (include_date ? "#{format_date(local)} " : "") +
- (Setting.time_format.blank? ? ::I18n.l(local, :format => :time) : local.strftime(Setting.time_format))
+ (include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options)
end
def day_name(day)
include ActionView::Helpers::NumberHelper
def setup
- @hook_module = Redmine::Hook
+ User.current.language = nil
end
def test_date_format_default
assert_equal today.strftime('%d %m %Y'), format_date(today)
end
+ def test_date_format_default_with_user_locale
+ set_language_if_valid 'es'
+ today = now = Time.parse('2011-02-20 14:00:00')
+ Setting.date_format = '%d %B %Y'
+ User.current.language = 'fr'
+ assert_equal "20 f\u00E9vrier 2011", format_date(today)
+ User.current.language = nil
+ assert_equal '20 Febrero 2011', format_date(today)
+ end
+
def test_date_and_time_for_each_language
Setting.date_format = ''
valid_languages.each do |lang|
end
end
+ def test_time_format_default_with_user_locale
+ set_language_if_valid 'en'
+ User.current.language = 'fr'
+ now = Time.parse('2011-02-20 15:45:22')
+ with_settings :time_format => '' do
+ with_settings :date_format => '' do
+ assert_equal '20/02/2011 15:45', format_time(now)
+ assert_equal '15:45', format_time(now, false)
+ end
+ with_settings :date_format => '%Y-%m-%d' do
+ assert_equal '2011-02-20 15:45', format_time(now)
+ assert_equal '15:45', format_time(now, false)
+ end
+ end
+ end
+
def test_time_format
set_language_if_valid 'en'
now = Time.now