@@ -6,10 +6,10 | |||
|
6 | 6 | <p><%= setting_select :default_language, lang_options_for_select(false) %></p> |
|
7 | 7 | |
|
8 | 8 | <p><%= setting_select :start_of_week, [[day_name(1),'1'], [day_name(6),'6'], [day_name(7),'7']], :blank => :label_language_based %></p> |
|
9 | <% locale = User.current.language.blank? ? ::I18n.locale : User.current.language %> | |
|
10 | <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 | 11 | |
|
10 |
<p><%= setting_select : |
|
|
11 | ||
|
12 | <p><%= setting_select :time_format, Setting::TIME_FORMATS.collect {|f| [Time.now.strftime(f), f]}, :blank => :label_language_based %></p> | |
|
12 | <p><%= setting_select :time_format, Setting::TIME_FORMATS.collect {|f| [::I18n.l(Time.now, :locale => locale, :format => f), f]}, :blank => :label_language_based %></p> | |
|
13 | 13 | |
|
14 | 14 | <p><%= setting_select :user_format, @options[:user_format] %></p> |
|
15 | 15 |
@@ -37,16 +37,21 module Redmine | |||
|
37 | 37 | |
|
38 | 38 | def format_date(date) |
|
39 | 39 | return nil unless date |
|
40 | Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format) | |
|
40 | options = {} | |
|
41 | options[:format] = Setting.date_format unless Setting.date_format.blank? | |
|
42 | options[:locale] = User.current.language unless User.current.language.blank? | |
|
43 | ::I18n.l(date.to_date, options) | |
|
41 | 44 | end |
|
42 | 45 | |
|
43 | 46 | def format_time(time, include_date = true) |
|
44 | 47 | return nil unless time |
|
48 | options = {} | |
|
49 | options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format) | |
|
50 | options[:locale] = User.current.language unless User.current.language.blank? | |
|
45 | 51 | time = time.to_time if time.is_a?(String) |
|
46 | 52 | zone = User.current.time_zone |
|
47 | 53 | local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) |
|
48 | (include_date ? "#{format_date(local)} " : "") + | |
|
49 | (Setting.time_format.blank? ? ::I18n.l(local, :format => :time) : local.strftime(Setting.time_format)) | |
|
54 | (include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options) | |
|
50 | 55 | end |
|
51 | 56 | |
|
52 | 57 | def day_name(day) |
@@ -22,7 +22,7 class Redmine::I18nTest < ActiveSupport::TestCase | |||
|
22 | 22 | include ActionView::Helpers::NumberHelper |
|
23 | 23 | |
|
24 | 24 | def setup |
|
25 | @hook_module = Redmine::Hook | |
|
25 | User.current.language = nil | |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_date_format_default |
@@ -39,6 +39,16 class Redmine::I18nTest < ActiveSupport::TestCase | |||
|
39 | 39 | assert_equal today.strftime('%d %m %Y'), format_date(today) |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | def test_date_format_default_with_user_locale | |
|
43 | set_language_if_valid 'es' | |
|
44 | today = now = Time.parse('2011-02-20 14:00:00') | |
|
45 | Setting.date_format = '%d %B %Y' | |
|
46 | User.current.language = 'fr' | |
|
47 | assert_equal "20 f\u00E9vrier 2011", format_date(today) | |
|
48 | User.current.language = nil | |
|
49 | assert_equal '20 Febrero 2011', format_date(today) | |
|
50 | end | |
|
51 | ||
|
42 | 52 | def test_date_and_time_for_each_language |
|
43 | 53 | Setting.date_format = '' |
|
44 | 54 | valid_languages.each do |lang| |
@@ -99,6 +109,22 class Redmine::I18nTest < ActiveSupport::TestCase | |||
|
99 | 109 | end |
|
100 | 110 | end |
|
101 | 111 | |
|
112 | def test_time_format_default_with_user_locale | |
|
113 | set_language_if_valid 'en' | |
|
114 | User.current.language = 'fr' | |
|
115 | now = Time.parse('2011-02-20 15:45:22') | |
|
116 | with_settings :time_format => '' do | |
|
117 | with_settings :date_format => '' do | |
|
118 | assert_equal '20/02/2011 15:45', format_time(now) | |
|
119 | assert_equal '15:45', format_time(now, false) | |
|
120 | end | |
|
121 | with_settings :date_format => '%Y-%m-%d' do | |
|
122 | assert_equal '2011-02-20 15:45', format_time(now) | |
|
123 | assert_equal '15:45', format_time(now, false) | |
|
124 | end | |
|
125 | end | |
|
126 | end | |
|
127 | ||
|
102 | 128 | def test_time_format |
|
103 | 129 | set_language_if_valid 'en' |
|
104 | 130 | now = Time.now |
General Comments 0
You need to be logged in to leave comments.
Login now