You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Gemfile
# gem 'rails' etc...
gem 'devise'
# app/models/user.rb
class User < ActiveRecord::Base
devise database_authenticatable, :registerable, :recoverable, :validatable
end
# config/locales/devise.en.yml
en:
errors:
messages:
not_found: "not found"
# config/initializers/i18n.rb
require 'i18n/backend/active_record'
require "i18n/backend/fallbacks"
I18n.default_locale = :'en-US'
I18n.available_locales = [I18n.default_locale]
I18n.fallbacks = true
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Fallbacks)
I18n.backend = I18n::Backend::ActiveRecord.new
# in rails console
User.new.errors.add :email, :not_found
# Generates the following SQL queries in the log file
(0.3ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('activerecord.errors.models.user.attributes.email.not_found') OR "key" LIKE 'activerecord.errors.models.user.attributes.email.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('activerecord.errors.models.user.not_found') OR "key" LIKE 'activerecord.errors.models.user.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('activerecord.errors.messages.not_found') OR "key" LIKE 'activerecord.errors.messages.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('errors.attributes.email.not_found') OR "key" LIKE 'errors.attributes.email.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('errors.messages.not_found') OR "key" LIKE 'errors.messages.not_found.%')
(0.4ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en' AND ("key" IN ('activerecord.errors.models.user.attributes.email.not_found') OR "key" LIKE 'activerecord.errors.models.user.attributes.email.not_found.%')
# Console returns with output
[ "translation missing: en-US.activerecord.errors.models.user.attributes.email.not_found" ]
I think it should query all I18n keys given as defaults on the fallback locales too, not just the original, most significant key of the error message.
Whether the fallback queries should happen between each query for a default, or after all default keys have been tried for the original locale then the fallbacks, I think it should try the fallback for each fallback locale for the most significant key, then gradually going the least significant default key symbol and trying the fallback locales on the way.
So the queries should look something like this instead of the above:
# Generates the following SQL queries in the log file
(0.3ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('activerecord.errors.models.user.attributes.email.not_found') OR "key" LIKE 'activerecord.errors.models.user.attributes.email.not_found.%')
(0.3ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en' AND ("key" IN ('activerecord.errors.models.user.attributes.email.not_found') OR "key" LIKE 'activerecord.errors.models.user.attributes.email.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('activerecord.errors.models.user.not_found') OR "key" LIKE 'activerecord.errors.models.user.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en' AND ("key" IN ('activerecord.errors.models.user.not_found') OR "key" LIKE 'activerecord.errors.models.user.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('activerecord.errors.messages.not_found') OR "key" LIKE 'activerecord.errors.messages.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en' AND ("key" IN ('activerecord.errors.messages.not_found') OR "key" LIKE 'activerecord.errors.messages.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('errors.attributes.email.not_found') OR "key" LIKE 'errors.attributes.email.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en' AND ("key" IN ('errors.attributes.email.not_found') OR "key" LIKE 'errors.attributes.email.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en-US' AND ("key" IN ('errors.messages.not_found') OR "key" LIKE 'errors.messages.not_found.%')
(0.2ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = 'en' AND ("key" IN ('errors.messages.not_found') OR "key" LIKE 'errors.messages.not_found.%')
The text was updated successfully, but these errors were encountered:
debreczeni
changed the title
Fallbacks for an array of symbolized keys as defaults are not retrieved from backend, only the initial key
Fallbacks for an array of symbolized keys given as default to I18n.t are not retrieved from backend, only the initial key
Oct 17, 2014
I think it should query all I18n keys given as defaults on the fallback locales too, not just the original, most significant key of the error message.
Whether the fallback queries should happen between each query for a default, or after all default keys have been tried for the original locale then the fallbacks, I think it should try the fallback for each fallback locale for the most significant key, then gradually going the least significant default key symbol and trying the fallback locales on the way.
So the queries should look something like this instead of the above:
The text was updated successfully, but these errors were encountered: