Commit 70811f900ec4a15107c6e6b5a66323b52b0f5ad8
1 parent
ad280692
Exists in
master
and in
27 other branches
dates_helper: don't use constant for translation
Showing
2 changed files
with
9 additions
and
7 deletions
Show diff stats
app/helpers/dates_helper.rb
... | ... | @@ -2,13 +2,15 @@ require 'noosfero/i18n' |
2 | 2 | |
3 | 3 | module DatesHelper |
4 | 4 | |
5 | - MONTHS = I18n.t('date.month_names') | |
5 | + def months | |
6 | + I18n.t('date.month_names') | |
7 | + end | |
6 | 8 | |
7 | 9 | def month_name(n, abbreviated = false) |
8 | 10 | if abbreviated |
9 | 11 | I18n.t('date.abbr_month_names')[n] |
10 | 12 | else |
11 | - MONTHS[n] | |
13 | + months[n] | |
12 | 14 | end |
13 | 15 | end |
14 | 16 | |
... | ... | @@ -37,7 +39,7 @@ module DatesHelper |
37 | 39 | end |
38 | 40 | end |
39 | 41 | |
40 | - # formats a datetime for displaying. | |
42 | + # formats a datetime for displaying. | |
41 | 43 | def show_time(time) |
42 | 44 | if time |
43 | 45 | _('%{day} %{month} %{year}, %{hour}:%{minutes}') % { :year => time.year, :month => month_name(time.month), :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") } |
... | ... | @@ -138,7 +140,7 @@ module DatesHelper |
138 | 140 | else |
139 | 141 | order = [:day, :month, :year] |
140 | 142 | end |
141 | - date_select(object, method, html_options.merge(options.merge(:include_blank => true, :order => order, :use_month_names => MONTHS))) | |
143 | + date_select(object, method, html_options.merge(options.merge(:include_blank => true, :order => order, :use_month_names => months))) | |
142 | 144 | end |
143 | 145 | |
144 | 146 | end | ... | ... |
test/unit/dates_helper_test.rb
... | ... | @@ -99,20 +99,20 @@ class DatesHelperTest < ActiveSupport::TestCase |
99 | 99 | |
100 | 100 | should 'provide an intertionalized date selector pass month names' do |
101 | 101 | expects(:language).returns('en') |
102 | - expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => MONTHS }).returns("KKKKKKKK") | |
102 | + expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => months }).returns("KKKKKKKK") | |
103 | 103 | assert_equal 'KKKKKKKK', pick_date(:object, :method) |
104 | 104 | end |
105 | 105 | |
106 | 106 | should 'order date in english like month day year' do |
107 | 107 | expects(:language).returns('en') |
108 | - expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => MONTHS }).returns("KKKKKKKK") | |
108 | + expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => months }).returns("KKKKKKKK") | |
109 | 109 | |
110 | 110 | assert_equal 'KKKKKKKK', pick_date(:object, :method) |
111 | 111 | end |
112 | 112 | |
113 | 113 | should 'order date in other languages like day month year' do |
114 | 114 | expects(:language).returns('pt_BR') |
115 | - expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:day, :month, :year], :use_month_names => MONTHS }).returns("KKKKKKKK") | |
115 | + expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:day, :month, :year], :use_month_names => months }).returns("KKKKKKKK") | |
116 | 116 | |
117 | 117 | assert_equal 'KKKKKKKK', pick_date(:object, :method) |
118 | 118 | end | ... | ... |