Enable Case Sensitive Field in Mysql (Ruby on Rails) rspec - match arguments with code block
Jan 17

The current will_paginate plugin doesn’t support localization. Adding the following code into the application_helper will enable i18n for will_paginate.


include WillPaginate::ViewHelpers

def will_paginate_with_i18n(collection, options = {})
will_paginate_without_i18n(collection, options.merge(:previous_label => I18n.t(:previous), :next_label => I18n.t(:next)))
end

alias_method_chain :will_paginate, :i18n

And add ‘next’ and ‘previous’ attribute in the locales file.

for example zh.yml under RAILS_ROOT/config/locales

zh:
previous: '前一页'
next: '下一页'

7 Responses to “Enable i18n in will_paginate Plugin”

  1. Roman Says:

    Very nice!

    I would add a default option to I18n.translate in order to keep backward compatibility:

    will_paginate_without_i18n(collection, options.merge(:previous_label => I18n.t(’previous’, :default=>’Previous’), :next_label => I18n.t(’next’, :default => ‘Next’)))

  2. Al Says:

    Nice!. Thanks!.

  3. Umberto Says:

    The key :previous_label doesn’t work for me (using the will_paginate gem instead of the plugin). Had to change it to :prev_label.

  4. sam Says:

    Nice work!

  5. Chris Says:

    Thx, works fine for me 2.

  6. fguillen Says:

    Works for me, and I am using the gem.

    config.gem ‘mislav-will_paginate’, :version => ‘~> 2.3.8′, :lib => ‘will_paginate’, :source => ‘http://gems.github.com’

    Thanks

    f.

  7. BSise Says:

    Thanks Lawrence, I implemented this successfully for iLearnWords (http://www.ilearnwords.com/), an audio-based language learning site!

Leave a Reply