From 0511ea3a3ae38b792e103250524384c71f5e5e62 Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Sat, 20 Aug 2016 14:43:42 -0500 Subject: [PATCH] Add a fallback to :other for i18n In most cases, translations don't supply `:few` even though the language may support the construct. Instead of the app blowing up if the translation for `:few` doesn't exist, fall back to `:other` instead. --- config/initializers/i18n-config.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/initializers/i18n-config.rb b/config/initializers/i18n-config.rb index d9f738a6..a951eeac 100644 --- a/config/initializers/i18n-config.rb +++ b/config/initializers/i18n-config.rb @@ -27,10 +27,11 @@ module I18n::Backend::Pluralization n==1 ? :one : :other # default :en end end + key = :other if key == :few && !entry.has_key?(key) #fallback to :other if :few is missing raise InvalidPluralizationData.new(entry, n) unless entry.has_key?(key) entry[key] end end I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization) -I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) \ No newline at end of file +I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)