Commit dd862f149472414502c617fa0ac484efb67378fe
1 parent
f3554630
Exists in
master
and in
22 other branches
ActionItem447: using default Rails date selector
but translating the month names git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2018 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
43 additions
and
18 deletions
Show diff stats
app/helpers/dates_helper.rb
| @@ -2,6 +2,21 @@ module DatesHelper | @@ -2,6 +2,21 @@ module DatesHelper | ||
| 2 | 2 | ||
| 3 | include GetText | 3 | include GetText |
| 4 | 4 | ||
| 5 | + MONTHS = [ | ||
| 6 | + N_('January'), | ||
| 7 | + N_('February'), | ||
| 8 | + N_('March'), | ||
| 9 | + N_('April'), | ||
| 10 | + N_('May'), | ||
| 11 | + N_('June'), | ||
| 12 | + N_('July'), | ||
| 13 | + N_('August'), | ||
| 14 | + N_('September'), | ||
| 15 | + N_('October'), | ||
| 16 | + N_('November'), | ||
| 17 | + N_('December') | ||
| 18 | + ] | ||
| 19 | + | ||
| 5 | # formats a date for displaying. | 20 | # formats a date for displaying. |
| 6 | def show_date(date) | 21 | def show_date(date) |
| 7 | if date | 22 | if date |
| @@ -51,20 +66,7 @@ module DatesHelper | @@ -51,20 +66,7 @@ module DatesHelper | ||
| 51 | end | 66 | end |
| 52 | 67 | ||
| 53 | # FIXME Date#strftime should translate this for us !!! | 68 | # FIXME Date#strftime should translate this for us !!! |
| 54 | - monthname = _([ | ||
| 55 | - N_('January'), | ||
| 56 | - N_('February'), | ||
| 57 | - N_('March'), | ||
| 58 | - N_('April'), | ||
| 59 | - N_('May'), | ||
| 60 | - N_('June'), | ||
| 61 | - N_('July'), | ||
| 62 | - N_('August'), | ||
| 63 | - N_('September'), | ||
| 64 | - N_('October'), | ||
| 65 | - N_('November'), | ||
| 66 | - N_('December') | ||
| 67 | - ][month.to_i - 1]) | 69 | + monthname = _(MONTHS[month.to_i - 1]) |
| 68 | 70 | ||
| 69 | _('%{month} %{year}') % { :year => year, :month => monthname } | 71 | _('%{month} %{year}') % { :year => year, :month => monthname } |
| 70 | end | 72 | end |
| @@ -82,4 +84,9 @@ module DatesHelper | @@ -82,4 +84,9 @@ module DatesHelper | ||
| 82 | 84 | ||
| 83 | link_to show_month(next_month_date.year, next_month_date.month) + ' →', :year => next_month_date.year, :month => next_month_date.month | 85 | link_to show_month(next_month_date.year, next_month_date.month) + ' →', :year => next_month_date.year, :month => next_month_date.month |
| 84 | end | 86 | end |
| 87 | + | ||
| 88 | + def pick_date(object, method) | ||
| 89 | + date_select(object, method, :use_month_names => MONTHS.map {|item| gettext(item)}) | ||
| 90 | + end | ||
| 91 | + | ||
| 85 | end | 92 | end |
app/views/cms/_event.rhtml
| 1 | -<%= calendar_date_select_includes 'silver', :locale => calendar_date_select_language %> | ||
| 2 | - | ||
| 3 | <%# TODO add Textile help here %> | 1 | <%# TODO add Textile help here %> |
| 4 | <%= render :file => 'shared/tiny_mce' %> | 2 | <%= render :file => 'shared/tiny_mce' %> |
| 5 | 3 | ||
| 6 | <%= f.text_field('name', :size => '64') %> | 4 | <%= f.text_field('name', :size => '64') %> |
| 7 | 5 | ||
| 8 | -<%= labelled_form_field(_('Start date'), calendar_date_select(:article, :start_date)) %> | 6 | +<%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> |
| 9 | 7 | ||
| 10 | -<%= labelled_form_field(_('End date'), calendar_date_select(:article, :end_date)) %> | 8 | +<%= labelled_form_field(_('End date'), pick_date(:article, :end_date)) %> |
| 11 | 9 | ||
| 12 | <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> | 10 | <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> |
| 13 | 11 |
test/unit/dates_helper_test.rb
| @@ -79,4 +79,24 @@ class DatesHelperTest < Test::Unit::TestCase | @@ -79,4 +79,24 @@ class DatesHelperTest < Test::Unit::TestCase | ||
| 79 | link_to_previous_month(nil, nil) | 79 | link_to_previous_month(nil, nil) |
| 80 | end | 80 | end |
| 81 | 81 | ||
| 82 | + should 'provide an intertionalized date selector pass month names' do | ||
| 83 | + | ||
| 84 | + expects(:gettext).with('January').returns('January') | ||
| 85 | + expects(:gettext).with('February').returns('February') | ||
| 86 | + expects(:gettext).with('March').returns('March') | ||
| 87 | + expects(:gettext).with('April').returns('April') | ||
| 88 | + expects(:gettext).with('May').returns('May') | ||
| 89 | + expects(:gettext).with('June').returns('June') | ||
| 90 | + expects(:gettext).with('July').returns('July') | ||
| 91 | + expects(:gettext).with('August').returns('August') | ||
| 92 | + expects(:gettext).with('September').returns('September') | ||
| 93 | + expects(:gettext).with('October').returns('October') | ||
| 94 | + expects(:gettext).with('November').returns('November') | ||
| 95 | + expects(:gettext).with('December').returns('December') | ||
| 96 | + | ||
| 97 | + expects(:date_select).with(:object, :method, {:use_month_names => ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']}).returns("KKKKKKKK") | ||
| 98 | + | ||
| 99 | + assert_equal 'KKKKKKKK', pick_date(:object, :method) | ||
| 100 | + end | ||
| 101 | + | ||
| 82 | end | 102 | end |