From 3115f71e0d21f449204b5bea5256232402252d04 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 2 Jun 2023 21:23:23 +0900 Subject: [PATCH] Simplify the "Translation missing" message when default is an empty Array follows up c5c6e753f31e2c107925cee5fce37639d68a6a9d --- lib/i18n/exceptions.rb | 4 ++-- test/backend/fallbacks_test.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/i18n/exceptions.rb b/lib/i18n/exceptions.rb index c9908973..23ca46ec 100644 --- a/lib/i18n/exceptions.rb +++ b/lib/i18n/exceptions.rb @@ -63,8 +63,8 @@ def keys end def message - if options[:default].is_a?(Array) - other_options = ([key, *options[:default]]).map { |k| normalized_option(k).prepend('- ') }.join("\n") + if (default = options[:default]).is_a?(Array) && default.any? + other_options = ([key, *default]).map { |k| normalized_option(k).prepend('- ') }.join("\n") "Translation missing. Options considered were:\n#{other_options}" else "Translation missing: #{keys.join('.')}" diff --git a/test/backend/fallbacks_test.rb b/test/backend/fallbacks_test.rb index 6d61408f..8c20a04b 100644 --- a/test/backend/fallbacks_test.rb +++ b/test/backend/fallbacks_test.rb @@ -70,6 +70,10 @@ def setup assert_equal translation_missing_message.chomp, I18n.t(:missing_bar, :locale => :'de-DE', :default => [:missing_baz]) end + test "returns the simple Translation missing: message when default is an empty Array" do + assert_equal "Translation missing: de-DE.missing_bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => []) + end + test "returns the :'de-DE' default :baz translation for a missing :'de-DE' when defaults contains Symbol" do assert_equal 'Baz in :de-DE', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:baz, "Default Bar"]) end