Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to disable fallbacks for the I18n.exists? check #482

Merged

Conversation

jeffjyang
Copy link
Contributor

Issue: #365

This PR adds a option to disable fallbacks for the I18n.exists? method in the Fallbacks backend.

Before, with fallbacks enabled, the following would return true because the exists? check would fallback from fr-CA to fr.

I18n.exists?('key_only_found_in_fr', locale: :'fr-CA') # returns true

Now, similar to how I18n.t has the option to disable fallbacks, we can do the following if we don't want to fallback:

I18n.exists?('key_only_found_in_fr', locale: :'fr-CA', fallback: false) # returns false

Screenshots:

Screen Shot 2019-06-24 at 6 50 16 PM

Let me know what you guys think :)

@jeffjyang jeffjyang changed the title [WIP] Add an option to disable fallbacks for the I18n.exists? check Add an option to disable fallbacks for the I18n.exists? check Jun 24, 2019
@toncid
Copy link

toncid commented Jan 20, 2020

Any chances of merging this?

Copy link
Collaborator

@radar radar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@radar radar merged commit eac7a9e into ruby-i18n:master Jan 20, 2020
peteryates added a commit to x-govuk/govuk-form-builder that referenced this pull request Apr 30, 2020
When Rails is configured with `config.i18n.fallbacks = true`[0] the
behaviour of `I18n.exists?` is unclear[1]. It returns true when passed
`nil` because fallbacks are considered.

This could be fixed by specifying `fallback: false` as a keyword arg to
`I18n.exists?`[2] but if we have no key there's no point in proceeding to
the check stage.

[0] https://guides.rubyonrails.org/v6.0.0/configuring.html#configuring-i18n
[1] ruby-i18n/i18n#365
[2] ruby-i18n/i18n#482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants