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

Use I18n strings if available #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seccomiro
Copy link

Tries to call I18n.t!("email_address.#{name}") at error_message().
This could raise exceptions in two cases:

  • I18n doesn't exist (because you are not on Rails)
  • The key was not found on i18n YAML files for the current locale
    Both cases are caught by the rescue clause, which returns a string based on existing @errors.
    Now it's possible to define translations inside your Rails app in the regular way.

Tries to call `I18n.t!("email_address.#{name}")` at `error_message()`.
This could raise exceptions in two cases:
 - `I18n` doesn't exist (because you are not on Rails)
 - The key was not found on i18n YAML files for the current locale
 Both cases are caught by the rescue clause, which returns a string based on existing `@errors`.
 Now it's possible to define translations inside your Rails app in the regular way.
Copy link
Contributor

@AlexWayfer AlexWayfer left a comment

Choose a reason for hiding this comment

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

I don't think that we need it.

There is the pretty simple error messages assignment, it's independent of your translation system.

We can bloat this gem with support of I18n, R18n, GetText, something else. And different users use different keys for translations.

And… anyway, rescuing exception is bad approach for your code. It's better to use something like Object.const_defined? and other conditions for other things.

fauno added a commit to fauno/email_address that referenced this pull request Feb 23, 2021
Like afair#67 but I18n is used on Rails' side
@fauno fauno mentioned this pull request Feb 24, 2021
afair pushed a commit that referenced this pull request Jul 1, 2021
Like #67 but I18n is used on Rails' side
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