Add translations for ActiveRecord models #180
Closed
Conversation
Hey, @mgrachev! Sorry I haven't responded sooner. Could you add some tests for this? Maybe something like this, in it "honors model translations" do
allow(I18n).to receive(:translate).with("customer").and_return("user")
visit admin_customers_path
sidebar = find(".sidebar__list")
expect(sidebar).to have_link("Users")
expect(page).to have_header("Users")
end |
@@ -11,7 +11,7 @@ as defined by the DashboardManifest. | |||
<% DashboardManifest::DASHBOARDS.each do |resource| %> | |||
<li> | |||
<%= link_to( | |||
resource.to_s.titleize, | |||
resource.to_s.classify.constantize.model_name.human(default: resource.to_s.titleize), |
gracewashere
Nov 21, 2015
Contributor
Do we want to pluralize this?
Do we want to pluralize this?
mgrachev
Nov 23, 2015
Author
Contributor
No. The user decides how to display the model name through a file locale. In default pluralization.
No. The user decides how to display the model name through a file locale. In default pluralization.
@@ -21,7 +21,9 @@ It renders the `_table` partial to display details about the resources. | |||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Table | |||
%> | |||
|
|||
<% content_for(:title) { page.resource_name.pluralize.titleize } %> | |||
<% content_for(:title) do | |||
page.resource_name.classify.constantize.model_name.human(default: page.resource_name.pluralize.titleize) |
gracewashere
Nov 21, 2015
Contributor
Maybe the pluralization should happen after the human(...)
call? That way it would apply even if it didn't use the default.
Maybe the pluralization should happen after the human(...)
call? That way it would apply even if it didn't use the default.
mgrachev
Nov 23, 2015
Author
Contributor
So better not to do. For example, for the Russian language the forced pluralization it looks like this:
# config/locales/ru.yml
ru:
activerecord:
models:
bet: Ставки
[1] pry(main)> Bet.model_name.human(default: 'Bets').pluralize
=> Ставкиs
So better not to do. For example, for the Russian language the forced pluralization it looks like this:
# config/locales/ru.yml
ru:
activerecord:
models:
bet: Ставки
[1] pry(main)> Bet.model_name.human(default: 'Bets').pluralize
=> Ставкиs
@@ -8,4 +8,14 @@ | |||
|
|||
expect(active_link.text).to eq "Customers" | |||
end | |||
|
|||
it "displays translated name of model" do | |||
allow(Customer.model_name).to receive(:human).and_return('Users') |
houndci-bot
Nov 23, 2015
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Added test |
Please, restart the build on CircleCI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Hi. Added translation support for ActiveRecord models in the sidebar and on the index page (header).
File locale must be of such content: