Skip to content

Commit

Permalink
Correct translation missing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed May 31, 2023
1 parent a5a2ba6 commit ec044d8
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/i18n/tests/localization/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def setup
end

test "localize Date: given missing translations it returns the correct error message" do
assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@date, :format => '%b', :locale => :fr)
assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@date, :format => '%b', :locale => :fr)
end

test "localize Date: given an unknown format it does not fail" do
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tests/localization/date_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def setup
end

test "localize DateTime: given missing translations it returns the correct error message" do
assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@datetime, :format => '%b', :locale => :fr)
assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@datetime, :format => '%b', :locale => :fr)
end

test "localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tests/localization/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def setup
end

test "localize Time: given missing translations it returns the correct error message" do
assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@time, :format => '%b', :locale => :fr)
assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@time, :format => '%b', :locale => :fr)
end

test "localize Time: given a meridian indicator format it returns the correct meridian indicator" do
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tests/lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setup
end

test "lookup: given a missing key, no default and no raise option it returns an error message" do
assert_equal "translation missing: en.missing", I18n.t(:missing)
assert_equal "Translation missing: en.missing", I18n.t(:missing)
end

test "lookup: given a missing key, no default and the raise option it raises MissingTranslationData" do
Expand Down
6 changes: 3 additions & 3 deletions test/backend/exceptions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ def setup
exception = catch(:exception) do
I18n.t(:'baz.missing', :scope => :'foo.bar', :throw => true)
end
assert_equal "translation missing: en.foo.bar.baz.missing", exception.message
assert_equal "Translation missing: en.foo.bar.baz.missing", exception.message
end

test "exceptions: MissingTranslationData message from #translate includes the given scope and full key" do
begin
I18n.t(:'baz.missing', :scope => :'foo.bar', :raise => true)
rescue I18n::MissingTranslationData => exception
end
assert_equal "translation missing: en.foo.bar.baz.missing", exception.message
assert_equal "Translation missing: en.foo.bar.baz.missing", exception.message
end

test "exceptions: MissingTranslationData message from #localize includes the given scope and full key" do
begin
I18n.l(Time.now, :format => :foo)
rescue I18n::MissingTranslationData => exception
end
assert_equal "translation missing: en.time.formats.foo", exception.message
assert_equal "Translation missing: en.time.formats.foo", exception.message
end

test "exceptions: MissingInterpolationArgument message includes missing key, provided keys and full string" do
Expand Down
4 changes: 2 additions & 2 deletions test/backend/fallbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def setup
assert_nil I18n.t(:missing_bar, :locale => :'de-DE', :default => nil)
end

test "returns the translation missing message if the default is also missing" do
assert_equal 'translation missing: de-DE.missing_bar', I18n.t(:missing_bar, :locale => :'de-DE', :default => [:missing_baz])
test "returns the Translation missing: message if the default is also missing" do
assert_equal 'Translation missing: de-DE.missing_bar', I18n.t(:missing_bar, :locale => :'de-DE', :default => [:missing_baz])
end

test "returns the :'de-DE' default :baz translation for a missing :'de-DE' when defaults contains Symbol" do
Expand Down
12 changes: 6 additions & 6 deletions test/backend/key_value_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def assert_flattens(expected, nested, escape=true, subtree=true)
assert_flattens({:"a.b"=>['a', 'b']}, {:a=>{:b =>['a', 'b']}}, true, false)
assert_flattens({:"a.b" => "c"}, {:"a.b" => "c"}, false)
end

test "store_translations supports numeric keys" do
setup_backend!
store_translations(:en, 1 => 'foo')
Expand Down Expand Up @@ -60,8 +60,8 @@ def assert_flattens(expected, nested, escape=true, subtree=true)
I18n.backend.send(:translations)
expected = { :en => {:foo => { :bar => 'bar', :baz => 'baz' }} }
assert_equal expected, translations
end
end

test "subtrees enabled: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do
setup_backend!
store_translations(:en, :bar => { :one => "One" })
Expand All @@ -71,15 +71,15 @@ def assert_flattens(expected, nested, escape=true, subtree=true)
test "subtrees disabled: given incomplete pluralization data it returns an error message" do
setup_backend!(false)
store_translations(:en, :bar => { :one => "One" })
assert_equal "translation missing: en.bar", I18n.t(:bar, :count => 2)
assert_equal "Translation missing: en.bar", I18n.t(:bar, :count => 2)
end

test "translate handles subtrees for pluralization" do
setup_backend!(false)
store_translations(:en, :bar => { :one => "One" })
assert_equal("One", I18n.t("bar", :count => 1))
end

test "subtrees enabled: returns localized string given missing pluralization data" do
setup_backend!(true)
assert_equal 'bar', I18n.t("foo.bar", count: 1)
Expand All @@ -89,7 +89,7 @@ def assert_flattens(expected, nested, escape=true, subtree=true)
setup_backend!(false)
assert_equal 'bar', I18n.t("foo.bar", count: 1)
end

test "subtrees enabled: Returns fallback default given missing pluralization data" do
setup_backend!(true)
I18n.backend.extend I18n::Backend::Fallbacks
Expand Down
4 changes: 2 additions & 2 deletions test/i18n/exceptions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def test_invalid_locale_stores_locale

test "MissingTranslationData message contains the locale and scoped key" do
force_missing_translation_data do |exception|
assert_equal 'translation missing: de.bar.foo', exception.message
assert_equal 'Translation missing: de.bar.foo', exception.message
end
end

test "MissingTranslationData message contains all potential options" do
force_missing_translation_data(default: [:option_a, :option_b]) do |exception|
assert_equal "translation missing. Options considered were:\n- de.bar.option_a, \n- de.bar.option_a", exception.message
assert_equal "Translation missing:. Options considered were:\n- de.bar.option_a, \n- de.bar.option_a", exception.message
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ def setup
end

# def test_translate_given_no_args_raises_missing_translation_data
# assert_equal "translation missing: en, no key", I18n.t
# assert_equal "Translation missing: en, no key", I18n.t
# end

test "translate given a bogus key returns an error message" do
assert_equal "translation missing: en.bogus", I18n.t(:bogus)
assert_equal "Translation missing: en.bogus", I18n.t(:bogus)
end

test "translate given multiple bogus keys returns an array of error messages" do
assert_equal(
["translation missing: en.bogus", "translation missing: en.also_bogus"],
["Translation missing: en.bogus", "Translation missing: en.also_bogus"],
I18n.t([:bogus, :also_bogus]),
)
end
Expand Down Expand Up @@ -262,7 +262,7 @@ def setup
I18n.t('foo')
end

assert_equal 'translation missing: en.foo', I18n.t('foo', locale: :en)
assert_equal 'Translation missing: en.foo', I18n.t('foo', locale: :en)
end
end

Expand Down

0 comments on commit ec044d8

Please sign in to comment.