Skip to content

How do I set the locale if I don't have a param? #526

Closed Answered by ddnexus
tkhobbes asked this question in Q&A
Discussion options

You must be logged in to vote

OK, I got a few problems recently. Sorry for the late answer.

The easiest and recommended way to work with default de locale is setting de as the first locale:

Pagy::I18n.load({ locale: 'de' }, { locale: 'en' })

Then you can simply do:

before_action { @pagy_locale = params[:locale] }

There will be no :locale param for de, only for en (and/or any other locale that is not the first default).

before_action { @pagy_locale = params[:locale] || I18n.default_locale }
When I log @pagy_locale, it correctly seems to be set to "de" - why isn't pagy picking that up?

It could be a number of things: I should have a minimal example of your case to be able to understand what is going on in your code.

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@tkhobbes
Comment options

Comment options

You must be logged in to vote
1 reply
@tkhobbes
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by tkhobbes
Comment options

You must be logged in to vote
3 replies
@ddnexus
Comment options

@tkhobbes
Comment options

@ddnexus
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants