Skip to content

Commit a672da8

Browse files
Only downcase first letter of each auth key, not the entire string
A previous change #4834 introduced a downcase call to each attribute, so that it'd fix an invalid grammar issue on some languages like English that were showing `Email` in the middle of flash message sentences. However, it caused a bug with German which uses the word `E-Mail` and at the beginning of the sentence, causing it to be converted to `E-mail` incorrectly. The fix here will only downcase the first char of each word, and convert it back to upcase at the beginning of the sentence, which should work for both the original fix (English message), and for the new bug (German message) If we end up running into any more of these edge cases with the message, we might roll it all back and provide a different set of interpolation values for the original vs downcased translations, so people can use what makes the most sense for each language without us having to manually massage these strings. Fixes #5820
1 parent dbc1bb2 commit a672da8

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/devise/failure_app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def i18n_message(default = nil)
112112
options[:default] = [message]
113113
auth_keys = scope_class.authentication_keys
114114
human_keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key|
115-
scope_class.human_attribute_name(key).downcase
115+
scope_class.human_attribute_name(key).downcase_first
116116
}
117117
options[:authentication_keys] = human_keys.join(I18n.t(:"support.array.words_connector"))
118118
options = i18n_options(options)

test/failure_app_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ def call_failure(env_params = {})
215215

216216
assert_equal 'Email ou senha inválidos.', @request.flash[:alert]
217217
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
218+
219+
call_failure('warden' => OpenStruct.new(message: :invalid), 'warden.options' => { locale: :de })
220+
221+
assert_equal 'E-Mail oder Passwort ist ungültig.', @request.flash[:alert]
222+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
218223
end
219224

220225
test 'uses the proxy failure message as string' do

test/support/locale/de.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
de:
2+
activerecord:
3+
attributes:
4+
user:
5+
email: E-Mail
6+
devise:
7+
failure:
8+
invalid: "%{authentication_keys} oder Passwort ist ungültig."

0 commit comments

Comments
 (0)