FIX: Catch InvalidPluralizationData exception in fallback locales

FIX: Catch InvalidPluralizationData exception in fallback locales

It shouldn’t raise an exception when a pluralized string in a fallback locale is only partially translated.

diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rb
index ad5313c..6578091 100644
--- a/lib/i18n/backend/discourse_i18n.rb
+++ b/lib/i18n/backend/discourse_i18n.rb
@@ -25,6 +25,15 @@ module I18n
         end
       end
 
+      def pluralize(locale, entry, count)
+        begin
+          super
+        rescue I18n::InvalidPluralizationData => e
+          raise e if I18n.fallbacks[locale] == [locale]
+          throw(:exception, e)
+        end
+      end
+
       def self.create_search_regexp(query, as_string: false)
         regexp = Regexp.escape(query)

GitHub sha: 6d44be51

1 Like

Shouldn’t we have a test for that?

1 Like

Yes, we should. :blush:

1 Like

DEV: Add specs for handling InvalidPluralizationData exception