Project

General

Profile

Feature #21677 » 21677-localised_decimals_in_web.patch

Felix Schäfer, 2016-01-08 13:06

View differences:

app/helpers/application_helper.rb
end
def html_hours(text)
text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>').html_safe
hours_int_sep_dec = Regexp.new("(\\d+)([\\.#{Regexp.escape l(:general_csv_decimal_separator)}])(\\d+)")
text.gsub(hours_int_sep_dec, '<span class="hours hours-int">\1</span><span class="hours hours-dec">\2\3</span>').html_safe
end
def authoring(created, author, options={})
app/helpers/queries_helper.rb
content_tag('span',
value.to_s(issue) {|other| link_to_issue(other, :subject => false, :tracker => false)}.html_safe,
:class => value.css_classes_for(issue))
when :hours, :total_spent_hours, :estimated_hours
l_number("%.2f", value)
else
format_object(value)
end
......
format_object(value, false) do |value|
case value.class.name
when 'Float'
sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
l_number("%.2f", value)
when 'IssueRelation'
value.to_s(object)
when 'Issue'
app/views/my/blocks/_timelog.html.erb
<% end %>
<div class="total-hours">
<p><%= l(:label_total_time) %>: <%= html_hours("%.2f" % entries.sum(&:hours).to_f) %></p>
<p><%= l(:label_total_time) %>: <%= html_hours(l_number("%.2f", entries.sum(&:hours).to_f)) %></p>
</div>
<% if entries.any? %>
......
<tr class="odd">
<td><strong><%= day == Date.today ? l(:label_today).titleize : format_date(day) %></strong></td>
<td colspan="2"></td>
<td class="hours"><em><%= html_hours("%.2f" % entries_by_day[day].sum(&:hours).to_f) %></em></td>
<td class="hours"><em><%= html_hours(l_number("%.2f", entries_by_day[day].sum(&:hours).to_f)) %></em></td>
<td></td>
</tr>
<% entries_by_day[day].each do |entry| -%>
......
<td class="activity"><%= entry.activity %></td>
<td class="subject"><%= entry.project %> <%= h(' - ') + link_to_issue(entry.issue, :truncate => 50) if entry.issue %></td>
<td class="comments"><%= entry.comments %></td>
<td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
<td class="hours"><%= html_hours(l_number("%.2f", entry.hours)) %></td>
<td class="buttons">
<% if entry.editable_by?(@user) -%>
<%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => entry},
app/views/timelog/_report_criteria.html.erb
<% total = 0 -%>
<% @report.periods.each do |period| -%>
<% sum = sum_hours(select_hours(hours_for_value, @report.columns, period.to_s)); total += sum -%>
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
<td class="hours"><%= html_hours(l_number("%.2f", sum)) if sum > 0 %></td>
<% end -%>
<td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
<td class="hours"><%= html_hours(l_number("%.2f", total)) if total > 0 %></td>
</tr>
<% if criterias.length > level+1 -%>
<%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
app/views/timelog/report.html.erb
<% total = 0 -%>
<% @report.periods.each do |period| -%>
<% sum = sum_hours(select_hours(@report.hours, @report.columns, period.to_s)); total += sum -%>
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
<td class="hours"><%= html_hours(l_number("%.2f", sum)) if sum > 0 %></td>
<% end -%>
<td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
<td class="hours"><%= html_hours(l_number("%.2f", total)) if total > 0 %></td>
</tr>
</tbody>
</table>
lib/redmine/i18n.rb
def l_hours(hours)
hours = hours.to_f
l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f))
l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => l_number("%.2f", hours.to_f))
end
def l_number(format, value)
return '' if value.blank?
sprintf(format, value).gsub('.', l(:general_csv_decimal_separator))
end
def l_hours_short(hours)
    (1-1/1)