Skip to content

Commit

Permalink
Merge pull request #662 from amatsuda/default_empty_array
Browse files Browse the repository at this point in the history
Simplify the "Translation missing" message when default is an empty Array
  • Loading branch information
radar committed Jun 2, 2023
2 parents 0bbef26 + 3115f71 commit bbe078b
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
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
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 bbe078b

Please sign in to comment.