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