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

do not downcase model name in errors (fixes #260) #261

Closed
wants to merge 1 commit into from

Conversation

fwolfst
Copy link

@fwolfst fwolfst commented Mar 15, 2019

I don't know what is the "right" way to define keys in vanilla rails
i18n model translations regarding uppercased/downcased model names.

In German, all Nouns start with a capital Letter, thus for correct
German spelling without this patch you need to rails g devise:views
and adjust the _error_messages.html.erb template. I'd prefer this
working out of the box, but cannot judge the implications for other
locales.

I don't know what is the "right" way to define keys in vanilla rails
i18n model translations regarding uppercased/downcased model names.

In German, all Nouns start with a capital Letter, thus for correct
German spelling without this patch you need to `rails g devise:views`
and adjust the `_error_messages.html.erb` template.  I'd prefer this
working out of the box, but cannot judge the implications for other
locales.
@JasonBarnabe
Copy link
Collaborator

This would be unexpected, at least for English. I would not accept this change as is, but would accept something a bit smarter (either a built-in method that determines this, or at worst a method with a list of locales where capitalization changes should/should not happen).

@fwolfst
Copy link
Author

fwolfst commented Mar 15, 2019

Understandable. Right now, I lack the smartness.

The problem would also arise if e.g. the en-GB translation would resemble the German one:
"%{resource} could not be saved, because 1 error prohibited it", as it would start with a noun which would need to be capitalized.

There is humanize https://www.rubydoc.info/docs/rails/ActiveSupport/Inflector#humanize-instance_method , but I believe its not l10n-aware and thus would probably introduce errors for all-lowercase-languages if they exist.

@fwolfst
Copy link
Author

fwolfst commented Mar 15, 2019

either a built-in method that determines this

something like this?

def maybe_downcase(noun)
 [:de].include(i18n.locale) ? noun : noun.downcase
end

(kind of pseudo-code, not knowing wether :de should be a symbol and so on, just a sketch).
I could totally do that and adjust the PR.

@JasonBarnabe
Copy link
Collaborator

Yeah that's what I'm thinking for my "at worst" case.

I wonder though - is that even the right thing to do for German? What if the model name is multiple words (like "Admin User" or "User Of Admin" or equivalents in German)? Would that end up correct?

@fwolfst
Copy link
Author

fwolfst commented Mar 16, 2019 via email

@JasonBarnabe
Copy link
Collaborator

See heartcombo/devise#4834 . I assume that the German equivalent of "Invalid email or password" also has incorrect capitalization.

Go ahead with something like your suggested code. Let's not let perfect get in the way of better.

@fwolfst
Copy link
Author

fwolfst commented Mar 17, 2019

smartness arrived maybe:
I remembered that localized templates could be used. In this case I could create a _error_messages.de.html.erb (note the .de in filename) that in my experiments get picked up correctly. The template would not include the downcasing. What do you think?

@fwolfst
Copy link
Author

fwolfst commented Mar 17, 2019

See plataformatec/devise#4834 . I assume that the German equivalent of "Invalid email or password" also has incorrect capitalization.

No it is correct as-is: "E-Mail oder Passwort ungültig. "

@JasonBarnabe
Copy link
Collaborator

I don't think having a full separate template would be appropriate.

This PR as submitted would break other languages. Passing it through a helper that would do something different for German would work. If you come up with something like that, please create a new PR.

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