##// END OF EJS Templates
Use abbr_day_name to get the first letter of the day name (#9839)....
Jean-Philippe Lang -
r10019:3119d1996c3c
parent child
Show More
@@ -1,191 +1,191
1 1 <% @gantt.view = self %>
2 2 <h2><%= @query.new_record? ? l(:label_gantt) : h(@query.name) %></h2>
3 3
4 4 <%= form_tag({:controller => 'gantts', :action => 'show',
5 5 :project_id => @project, :month => params[:month],
6 6 :year => params[:year], :months => params[:months]},
7 7 :method => :get, :id => 'query_form') do %>
8 8 <%= hidden_field_tag 'set_filter', '1' %>
9 9 <fieldset id="filters" class="collapsible <%= @query.new_record? ? "" : "collapsed" %>">
10 10 <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
11 11 <div style="<%= @query.new_record? ? "" : "display: none;" %>">
12 12 <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
13 13 </div>
14 14 </fieldset>
15 15
16 16 <p class="contextual">
17 17 <%= gantt_zoom_link(@gantt, :in) %>
18 18 <%= gantt_zoom_link(@gantt, :out) %>
19 19 </p>
20 20
21 21 <p class="buttons">
22 22 <%= text_field_tag 'months', @gantt.months, :size => 2 %>
23 23 <%= l(:label_months_from) %>
24 24 <%= select_month(@gantt.month_from, :prefix => "month", :discard_type => true) %>
25 25 <%= select_year(@gantt.year_from, :prefix => "year", :discard_type => true) %>
26 26 <%= hidden_field_tag 'zoom', @gantt.zoom %>
27 27
28 28 <%= link_to_function l(:button_apply), '$("#query_form").submit()', :class => 'icon icon-checked' %>
29 29 <%= link_to l(:button_clear), { :project_id => @project, :set_filter => 1 }, :class => 'icon icon-reload' %>
30 30 </p>
31 31 <% end %>
32 32
33 33 <%= error_messages_for 'query' %>
34 34 <% if @query.valid? %>
35 35 <%
36 36 zoom = 1
37 37 @gantt.zoom.times { zoom = zoom * 2 }
38 38
39 39 subject_width = 330
40 40 header_heigth = 18
41 41
42 42 headers_height = header_heigth
43 43 show_weeks = false
44 44 show_days = false
45 45
46 46 if @gantt.zoom > 1
47 47 show_weeks = true
48 48 headers_height = 2 * header_heigth
49 49 if @gantt.zoom > 2
50 50 show_days = true
51 51 headers_height = 3 * header_heigth
52 52 end
53 53 end
54 54
55 55 # Width of the entire chart
56 56 g_width = ((@gantt.date_to - @gantt.date_from + 1) * zoom).to_i
57 57 @gantt.render(:top => headers_height + 8,
58 58 :zoom => zoom,
59 59 :g_width => g_width,
60 60 :subject_width => subject_width)
61 61 g_height = [(20 * (@gantt.number_of_rows + 6)) + 150, 206].max
62 62 t_height = g_height + headers_height
63 63 %>
64 64
65 65 <% if @gantt.truncated %>
66 66 <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p>
67 67 <% end %>
68 68
69 69 <table style="width:100%; border:0; border-collapse: collapse;">
70 70 <tr>
71 71 <td style="width:<%= subject_width %>px; padding:0px;">
72 72
73 73 <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;">
74 74 <div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
75 75 <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
76 76
77 77 <div class="gantt_subjects">
78 78 <%= @gantt.subjects.html_safe %>
79 79 </div>
80 80
81 81 </div>
82 82 </td>
83 83 <td>
84 84
85 85 <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
86 86 <div style="width:<%= g_width - 1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
87 87 <%
88 88 #
89 89 # Months headers
90 90 #
91 91 month_f = @gantt.date_from
92 92 left = 0
93 93 height = (show_weeks ? header_heigth : header_heigth + g_height)
94 94 @gantt.months.times do
95 95 width = (((month_f >> 1) - month_f) * zoom - 1).to_i
96 96 %>
97 97 <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
98 98 <%= link_to h("#{month_f.year}-#{month_f.month}"), @gantt.params.merge(:year => month_f.year, :month => month_f.month), :title => "#{month_name(month_f.month)} #{month_f.year}"%>
99 99 </div>
100 100 <%
101 101 left = left + width + 1
102 102 month_f = month_f >> 1
103 103 end %>
104 104
105 105 <%
106 106 #
107 107 # Weeks headers
108 108 #
109 109 if show_weeks
110 110 left = 0
111 111 height = (show_days ? header_heigth - 1 : header_heigth - 1 + g_height)
112 112 if @gantt.date_from.cwday == 1
113 113 # @date_from is monday
114 114 week_f = @gantt.date_from
115 115 else
116 116 # find next monday after @date_from
117 117 week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1)
118 118 width = (7 - @gantt.date_from.cwday + 1) * zoom - 1
119 119 %>
120 120 <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">&nbsp;</div>
121 121 <%
122 122 left = left + width + 1
123 123 end %>
124 124 <%
125 125 while week_f <= @gantt.date_to
126 126 width = ((week_f + 6 <= @gantt.date_to) ? 7 * zoom - 1 : (@gantt.date_to - week_f + 1) * zoom - 1).to_i
127 127 %>
128 128 <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
129 129 <small><%= week_f.cweek if width >= 16 %></small>
130 130 </div>
131 131 <%
132 132 left = left + width + 1
133 133 week_f = week_f + 7
134 134 end
135 135 end %>
136 136
137 137 <%
138 138 #
139 139 # Days headers
140 140 #
141 141 if show_days
142 142 left = 0
143 143 height = g_height + header_heigth - 1
144 144 wday = @gantt.date_from.cwday
145 145 (@gantt.date_to - @gantt.date_from + 1).to_i.times do
146 146 width = zoom - 1
147 147 %>
148 148 <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr">
149 <%= day_name(wday).first %>
149 <%= day_letter(wday) %>
150 150 </div>
151 151 <%
152 152 left = left + width + 1
153 153 wday = wday + 1
154 154 wday = 1 if wday > 7
155 155 end
156 156 end %>
157 157
158 158 <%= @gantt.lines.html_safe %>
159 159
160 160 <%
161 161 #
162 162 # Today red line (excluded from cache)
163 163 #
164 164 %>
165 165 <% if Date.today >= @gantt.date_from and Date.today <= @gantt.date_to %>
166 166 <div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= (((Date.today - @gantt.date_from + 1) * zoom).floor() - 1).to_i %>px;width:10px;border-left: 1px dashed red;">&nbsp;</div>
167 167 <% end %>
168 168
169 169 </div>
170 170 </td>
171 171 </tr>
172 172 </table>
173 173
174 174 <table style="width:100%">
175 175 <tr>
176 176 <td align="left"><%= link_to_content_update("\xc2\xab " + l(:label_previous), params.merge(@gantt.params_previous)) %></td>
177 177 <td align="right"><%= link_to_content_update(l(:label_next) + " \xc2\xbb", params.merge(@gantt.params_next)) %></td>
178 178 </tr>
179 179 </table>
180 180
181 181 <% other_formats_links do |f| %>
182 182 <%= f.link_to 'PDF', :url => params.merge(@gantt.params) %>
183 183 <%= f.link_to('PNG', :url => params.merge(@gantt.params)) if @gantt.respond_to?('to_image') %>
184 184 <% end %>
185 185 <% end # query.valid? %>
186 186
187 187 <% content_for :sidebar do %>
188 188 <%= render :partial => 'issues/sidebar' %>
189 189 <% end %>
190 190
191 191 <% html_title(l(:label_gantt)) -%>
@@ -1,84 +1,88
1 1 module Redmine
2 2 module I18n
3 3 def self.included(base)
4 4 base.extend Redmine::I18n
5 5 end
6 6
7 7 def l(*args)
8 8 case args.size
9 9 when 1
10 10 ::I18n.t(*args)
11 11 when 2
12 12 if args.last.is_a?(Hash)
13 13 ::I18n.t(*args)
14 14 elsif args.last.is_a?(String)
15 15 ::I18n.t(args.first, :value => args.last)
16 16 else
17 17 ::I18n.t(args.first, :count => args.last)
18 18 end
19 19 else
20 20 raise "Translation string with multiple values: #{args.first}"
21 21 end
22 22 end
23 23
24 24 def l_or_humanize(s, options={})
25 25 k = "#{options[:prefix]}#{s}".to_sym
26 26 ::I18n.t(k, :default => s.to_s.humanize)
27 27 end
28 28
29 29 def l_hours(hours)
30 30 hours = hours.to_f
31 31 l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f))
32 32 end
33 33
34 34 def ll(lang, str, value=nil)
35 35 ::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" })
36 36 end
37 37
38 38 def format_date(date)
39 39 return nil unless date
40 40 options = {}
41 41 options[:format] = Setting.date_format unless Setting.date_format.blank?
42 42 options[:locale] = User.current.language unless User.current.language.blank?
43 43 ::I18n.l(date.to_date, options)
44 44 end
45 45
46 46 def format_time(time, include_date = true)
47 47 return nil unless time
48 48 options = {}
49 49 options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format)
50 50 options[:locale] = User.current.language unless User.current.language.blank?
51 51 time = time.to_time if time.is_a?(String)
52 52 zone = User.current.time_zone
53 53 local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
54 54 (include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options)
55 55 end
56 56
57 57 def day_name(day)
58 58 ::I18n.t('date.day_names')[day % 7]
59 59 end
60 60
61 def day_letter(day)
62 ::I18n.t('date.abbr_day_names')[day % 7].first
63 end
64
61 65 def month_name(month)
62 66 ::I18n.t('date.month_names')[month]
63 67 end
64 68
65 69 def valid_languages
66 70 @@valid_languages ||= Dir.glob(File.join(Rails.root, 'config', 'locales', '*.yml')).collect {|f| File.basename(f).split('.').first}.collect(&:to_sym)
67 71 end
68 72
69 73 def find_language(lang)
70 74 @@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k }
71 75 @@languages_lookup[lang.to_s.downcase]
72 76 end
73 77
74 78 def set_language_if_valid(lang)
75 79 if l = find_language(lang)
76 80 ::I18n.locale = l
77 81 end
78 82 end
79 83
80 84 def current_language
81 85 ::I18n.locale
82 86 end
83 87 end
84 88 end
@@ -1,206 +1,222
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../../../test_helper', __FILE__)
19 19
20 20 class Redmine::I18nTest < ActiveSupport::TestCase
21 21 include Redmine::I18n
22 22 include ActionView::Helpers::NumberHelper
23 23
24 24 def setup
25 25 User.current.language = nil
26 26 end
27 27
28 def teardown
29 set_language_if_valid 'en'
30 end
31
28 32 def test_date_format_default
29 33 set_language_if_valid 'en'
30 34 today = Date.today
31 35 Setting.date_format = ''
32 36 assert_equal I18n.l(today), format_date(today)
33 37 end
34 38
35 39 def test_date_format
36 40 set_language_if_valid 'en'
37 41 today = Date.today
38 42 Setting.date_format = '%d %m %Y'
39 43 assert_equal today.strftime('%d %m %Y'), format_date(today)
40 44 end
41 45
42 46 def test_date_format_default_with_user_locale
43 47 set_language_if_valid 'es'
44 48 today = now = Time.parse('2011-02-20 14:00:00')
45 49 Setting.date_format = '%d %B %Y'
46 50 User.current.language = 'fr'
47 51 s1 = "20 f\xc3\xa9vrier 2011"
48 52 s1.force_encoding("UTF-8") if s1.respond_to?(:force_encoding)
49 53 assert_equal s1, format_date(today)
50 54 User.current.language = nil
51 55 assert_equal '20 Febrero 2011', format_date(today)
52 56 end
53 57
54 58 def test_date_and_time_for_each_language
55 59 Setting.date_format = ''
56 60 valid_languages.each do |lang|
57 61 set_language_if_valid lang
58 62 assert_nothing_raised "#{lang} failure" do
59 63 format_date(Date.today)
60 64 format_time(Time.now)
61 65 format_time(Time.now, false)
62 66 assert_not_equal 'default', ::I18n.l(Date.today, :format => :default),
63 67 "date.formats.default missing in #{lang}"
64 68 assert_not_equal 'time', ::I18n.l(Time.now, :format => :time),
65 69 "time.formats.time missing in #{lang}"
66 70 end
67 71 assert l('date.day_names').is_a?(Array)
68 72 assert_equal 7, l('date.day_names').size
69 73
70 74 assert l('date.month_names').is_a?(Array)
71 75 assert_equal 13, l('date.month_names').size
72 76 end
73 77 end
74 78
75 79 def test_time_for_each_zone
76 80 ActiveSupport::TimeZone.all.each do |zone|
77 81 User.current.stubs(:time_zone).returns(zone.name)
78 82 assert_nothing_raised "#{zone} failure" do
79 83 format_time(Time.now)
80 84 end
81 85 end
82 86 end
83 87
84 88 def test_time_format
85 89 set_language_if_valid 'en'
86 90 now = Time.parse('2011-02-20 15:45:22')
87 91 with_settings :time_format => '%H:%M' do
88 92 with_settings :date_format => '' do
89 93 assert_equal '02/20/2011 15:45', format_time(now)
90 94 assert_equal '15:45', format_time(now, false)
91 95 end
92 96 with_settings :date_format => '%Y-%m-%d' do
93 97 assert_equal '2011-02-20 15:45', format_time(now)
94 98 assert_equal '15:45', format_time(now, false)
95 99 end
96 100 end
97 101 end
98 102
99 103 def test_time_format_default
100 104 set_language_if_valid 'en'
101 105 now = Time.parse('2011-02-20 15:45:22')
102 106 with_settings :time_format => '' do
103 107 with_settings :date_format => '' do
104 108 assert_equal '02/20/2011 03:45 pm', format_time(now)
105 109 assert_equal '03:45 pm', format_time(now, false)
106 110 end
107 111 with_settings :date_format => '%Y-%m-%d' do
108 112 assert_equal '2011-02-20 03:45 pm', format_time(now)
109 113 assert_equal '03:45 pm', format_time(now, false)
110 114 end
111 115 end
112 116 end
113 117
114 118 def test_time_format_default_with_user_locale
115 119 set_language_if_valid 'en'
116 120 User.current.language = 'fr'
117 121 now = Time.parse('2011-02-20 15:45:22')
118 122 with_settings :time_format => '' do
119 123 with_settings :date_format => '' do
120 124 assert_equal '20/02/2011 15:45', format_time(now)
121 125 assert_equal '15:45', format_time(now, false)
122 126 end
123 127 with_settings :date_format => '%Y-%m-%d' do
124 128 assert_equal '2011-02-20 15:45', format_time(now)
125 129 assert_equal '15:45', format_time(now, false)
126 130 end
127 131 end
128 132 end
129 133
130 134 def test_time_format
131 135 set_language_if_valid 'en'
132 136 now = Time.now
133 137 Setting.date_format = '%d %m %Y'
134 138 Setting.time_format = '%H %M'
135 139 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
136 140 assert_equal now.strftime('%H %M'), format_time(now, false)
137 141 end
138 142
139 143 def test_utc_time_format
140 144 set_language_if_valid 'en'
141 145 now = Time.now
142 146 Setting.date_format = '%d %m %Y'
143 147 Setting.time_format = '%H %M'
144 148 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now.utc)
145 149 assert_equal now.strftime('%H %M'), format_time(now.utc, false)
146 150 end
147 151
148 152 def test_number_to_human_size_for_each_language
149 153 valid_languages.each do |lang|
150 154 set_language_if_valid lang
151 155 assert_nothing_raised "#{lang} failure" do
152 156 size = number_to_human_size(257024)
153 157 assert_match /251/, size
154 158 end
155 159 end
156 160 end
157 161
162 def test_day_name
163 set_language_if_valid 'fr'
164 assert_equal 'dimanche', day_name(0)
165 assert_equal 'jeudi', day_name(4)
166 end
167
168 def test_day_letter
169 set_language_if_valid 'fr'
170 assert_equal 'd', day_letter(0)
171 assert_equal 'j', day_letter(4)
172 end
173
158 174 def test_valid_languages
159 175 assert valid_languages.is_a?(Array)
160 176 assert valid_languages.first.is_a?(Symbol)
161 177 end
162 178
163 179 def test_locales_validness
164 180 lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size
165 181 assert_equal lang_files_count, valid_languages.size
166 182 valid_languages.each do |lang|
167 183 assert set_language_if_valid(lang)
168 184 end
169 185 set_language_if_valid('en')
170 186 end
171 187
172 188 def test_valid_language
173 189 to_test = {'fr' => :fr,
174 190 'Fr' => :fr,
175 191 'zh' => :zh,
176 192 'zh-tw' => :"zh-TW",
177 193 'zh-TW' => :"zh-TW",
178 194 'zh-ZZ' => nil }
179 195 to_test.each {|lang, expected| assert_equal expected, find_language(lang)}
180 196 end
181 197
182 198 def test_fallback
183 199 ::I18n.backend.store_translations(:en, {:untranslated => "Untranslated string"})
184 200 ::I18n.locale = 'en'
185 201 assert_equal "Untranslated string", l(:untranslated)
186 202 ::I18n.locale = 'fr'
187 203 assert_equal "Untranslated string", l(:untranslated)
188 204
189 205 ::I18n.backend.store_translations(:fr, {:untranslated => "Pas de traduction"})
190 206 ::I18n.locale = 'en'
191 207 assert_equal "Untranslated string", l(:untranslated)
192 208 ::I18n.locale = 'fr'
193 209 assert_equal "Pas de traduction", l(:untranslated)
194 210 end
195 211
196 212 def test_utf8
197 213 set_language_if_valid 'ja'
198 214 str_ja_yes = "\xe3\x81\xaf\xe3\x81\x84"
199 215 i18n_ja_yes = l(:general_text_Yes)
200 216 if str_ja_yes.respond_to?(:force_encoding)
201 217 str_ja_yes.force_encoding('UTF-8')
202 218 assert_equal "UTF-8", i18n_ja_yes.encoding.to_s
203 219 end
204 220 assert_equal str_ja_yes, i18n_ja_yes
205 221 end
206 222 end
General Comments 0
You need to be logged in to leave comments. Login now