Skip to content

Commit

Permalink
Add a test to verify that translated labels work
Browse files Browse the repository at this point in the history
Problem:

There was uncertainty about how to create custom labels for fields.
In #451,
it was suggested that we could use I18n translations
to solve the problem.

If we accept that as the standard way to set custom labels,
we should have a test for it.

Solution:

- Add a test to verify that labels can be customized through I18n.
- Add documentation about how to customize labels

To Do:

- Update view code so the same translation definition
  applies on the show and collection pages,
  in addition to the form page.
  • Loading branch information
c-lliope committed Mar 8, 2016
1 parent e9a7134 commit 47e2fc4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/customizing_dashboards.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,15 @@ if the value is stored by the number of cents:
)
```

To change the user-facing label for an attribute,
define a custom I18n translation:

```yaml
en:
helpers:
label:
customer:
name: Full Name
```
[define your own]: /adding_custom_field_types
20 changes: 20 additions & 0 deletions spec/features/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,24 @@

expect(page).to have_css("form.form")
end

it "displays translated labels" do
custom_label = "Newsletter Subscriber"

translations = {
helpers: {
label: {
customer: {
email_subscriber: custom_label,
},
},
},
}

with_translations(:en, translations) do
visit new_admin_customer_path

expect(page).to have_label(custom_label)
end
end
end
4 changes: 4 additions & 0 deletions spec/support/features/page_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ module Features
def have_header(title)
have_css("h1", text: title)
end

def have_label(title)
have_css("label", text: title)
end
end

0 comments on commit 47e2fc4

Please sign in to comment.