Skip to content

Commit

Permalink
Simplify the "Translation missing" message when default is an empty A…
Browse files Browse the repository at this point in the history
…rray

follows up c5c6e75
  • Loading branch information
amatsuda committed Jun 2, 2023
1 parent 4045d30 commit 3115f71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/i18n/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')}"
Expand Down
4 changes: 4 additions & 0 deletions test/backend/fallbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3115f71

Please sign in to comment.