New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add pluralization based on locale setup for any language #899
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
class ActionViewExtensionTest < ActionView::TestCase | ||
setup do | ||
self.output_buffer = ::ActionView::OutputBuffer.new | ||
I18n.available_locales = [:en, :de, :fr] | ||
I18n.locale = :en | ||
end | ||
teardown do | ||
User.delete_all | ||
|
@@ -266,6 +268,132 @@ def to_s | |
I18n.backend.reload! | ||
end | ||
end | ||
|
||
sub_test_case 'with any other locale' do | ||
sub_test_case ':de' do | ||
setup do | ||
I18n.locale = :de | ||
end | ||
|
||
test 'with default entry name' do | ||
users = User.page(1).per(50) | ||
begin | ||
I18n.backend.store_translations(:de, | ||
helpers: { | ||
page_entries_info: { | ||
one_page: { | ||
display_entries: { | ||
one: "Displaying <b>1</b> %{entry_name}", | ||
other: "Displaying <b>all %{count}</b> %{entry_name}" | ||
} | ||
} | ||
} | ||
} | ||
) | ||
assert_equal 'Displaying <b>all 50</b> Benutzer', view.page_entries_info(users, entry_name: 'Benutzer') | ||
ensure | ||
I18n.backend.reload! | ||
end | ||
end | ||
|
||
test 'the last page with default entry name' do | ||
User.max_pages 4 | ||
users = User.page(4).per(10) | ||
begin | ||
I18n.backend.store_translations(:de, | ||
helpers: { | ||
page_entries_info: { | ||
more_pages: { | ||
display_entries: "Displaying %{entry_name} <b>%{first} - %{last}</b> of <b>%{total}</b> in total" | ||
} | ||
} | ||
} | ||
) | ||
assert_equal 'Displaying Benutzer <b>31 - 40</b> of <b>50</b> in total', view.page_entries_info(users, entry_name: 'Benutzer') | ||
ensure | ||
I18n.backend.reload! | ||
end | ||
end | ||
end | ||
end | ||
|
||
sub_test_case ':fr' do | ||
setup do | ||
I18n.locale = :fr | ||
ActiveSupport::Inflector.inflections(:fr) do |inflect| | ||
inflect.plural(/$/, 's') | ||
inflect.singular(/s$/, '') | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks great 👍🏻 |
||
end | ||
|
||
sub_test_case 'having 1 entry' do | ||
setup do | ||
User.delete_all | ||
User.create! name: 'user1' | ||
end | ||
|
||
test 'with default entry name' do | ||
users = User.page(1).per(25) | ||
begin | ||
I18n.backend.store_translations(:fr, | ||
helpers: { | ||
page_entries_info: { | ||
one_page: { | ||
display_entries: { | ||
one: "Displaying <b>1</b> %{entry_name}", | ||
other: "Displaying <b>all %{count}</b> %{entry_name}" | ||
} | ||
} | ||
} | ||
} | ||
) | ||
assert_equal 'Displaying <b>1</b> utilisateur', view.page_entries_info(users, entry_name: 'utilisateur') | ||
ensure | ||
I18n.backend.reload! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using |
||
end | ||
end | ||
end | ||
|
||
test 'having multiple entries with default entry name' do | ||
users = User.page(1).per(50) | ||
begin | ||
I18n.backend.store_translations(:fr, | ||
helpers: { | ||
page_entries_info: { | ||
one_page: { | ||
display_entries: { | ||
one: "Displaying <b>1</b> %{entry_name}", | ||
other: "Displaying <b>all %{count}</b> %{entry_name}" | ||
} | ||
} | ||
} | ||
} | ||
) | ||
assert_equal 'Displaying <b>all 50</b> utilisateurs', view.page_entries_info(users, entry_name: 'utilisateur') | ||
ensure | ||
I18n.backend.reload! | ||
end | ||
end | ||
|
||
test 'the last page with default entry name' do | ||
User.max_pages 4 | ||
users = User.page(4).per(10) | ||
begin | ||
I18n.backend.store_translations(:fr, | ||
helpers: { | ||
page_entries_info: { | ||
more_pages: { | ||
display_entries: "Displaying %{entry_name} <b>%{first} - %{last}</b> of <b>%{total}</b> in total" | ||
} | ||
} | ||
} | ||
) | ||
assert_equal 'Displaying utilisateurs <b>31 - 40</b> of <b>50</b> in total', view.page_entries_info(users, entry_name: 'utilisateur') | ||
ensure | ||
I18n.backend.reload! | ||
end | ||
end | ||
end | ||
end | ||
|
||
sub_test_case 'on a model with namespace' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this entire sub test case for
:de
is necessary when there is a test case for:fr
. Are there any tests that fail without your change?