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

Fallback to ActiveModel translations in EmailValidator #369

Merged
merged 2 commits into from
Nov 9, 2015

Conversation

yivo
Copy link

@yivo yivo commented Sep 1, 2015

No description provided.

@booleanbetrayal
Copy link
Collaborator

I don't understand the context for this PR. Why would your DeviseTokenAuth localizations be missing?

@yivo
Copy link
Author

yivo commented Oct 21, 2015

DeviseTokenAuth doesn't have localizations for some languages. We can check if there other localizations for the same locale and with same meaning.
Please see example below.

Localizations we have:

en:
  errors:
    messages:
      invalid: 'is invalid'       # Rails default
    not_email: 'is not an email'  # DeviceTokenAuth
I18n.available_locales = [:en, :it] # Set available locales

# Testing with :en
I18n.locale = :en
I18n.t(:'errors.not_email')                                       # => "is not an email"
I18n.t(:'errors.messages.invalid')                                # => "is invalid"
I18n.t(:'errors.not_email', default: :'errors.messages.invalid')  # => "is not an email"

# Testing with :it (1)
I18n.locale = :it
I18n.t(:'errors.not_email')                                       # => "translation missing: it.errors.not_email"
I18n.t(:'errors.messages.invalid')                                # => "translation missing: it.errors.messages.invalid"
I18n.t(:'errors.not_email', default: :'errors.messages.invalid')  # => "translation missing: it.errors.not_email"

Lets add more localizations:

it:
  errors:
    messages:
      invalid: 'non è valido'     # We have defined this localization in out project

And test again:

# Testing with :it (2)
I18n.locale = :it
I18n.t(:'errors.not_email')                                       # => "translation missing: it.errors.not_email"
I18n.t(:'errors.messages.invalid')                                # => "non è valido"
I18n.t(:'errors.not_email', default: :'errors.messages.invalid')  # => "non è valido"

@booleanbetrayal
Copy link
Collaborator

Gotcha. Sorry for the delay!

booleanbetrayal added a commit that referenced this pull request Nov 9, 2015
Fallback to ActiveModel translations in EmailValidator
@booleanbetrayal booleanbetrayal merged commit 1feace6 into lynndylanhurley:master Nov 9, 2015
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.

2 participants