Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the text will_paginate renders

How can change the text that will_paginate shows?

Right now, it renders Previous ... Next. I need to put that in french Précédent ... Suivant. I checked on google and got this link : http://thewebfellas.com/blog/2010/8/22/revisited-roll-your-own-pagination-links-with-will_paginate-and-rails-3

However, I was wondering if there was an easier way.

like image 358
Justin D. Avatar asked Mar 17 '12 17:03

Justin D.


2 Answers

You can override the default of Previous and Next this way:

<%= will_paginate @posts, :previous_label => 'Précédent', :next_label => 'Suivant' %>

Note: :previous_label was called :prev_label in versions 2.3.2 and older

like image 153
ScottJShea Avatar answered Oct 13 '22 22:10

ScottJShea


So you have to ensure that the following is in place:

  • Your locale is set to french. This normally depends on the browser your are using. Chrome e.g. uses the locale of the operating system. I have set in application.rb the default locale (german for me): config.i18n.default_locale = :de
  • The directory config/locales contains a file fr.yml with the following content (there could be more customization):

    views:
      pagination:
        first: "F"
        previous: "&laquo; Prev"
        next: "Next &raquo;"
        last: "L"
        truncate: "..."
    

This works for me in the current version of Rails 3.2.2 with gem 'will_paginate', '>= 3.0'.

like image 35
mliebelt Avatar answered Oct 13 '22 23:10

mliebelt