Skip to content

Commit

Permalink
Add i18n support for Field::HasMany (#2114)
Browse files Browse the repository at this point in the history
If you have ActiveRecord i18n translation of the model you don't need to do
anything extra, if not, make an ActiveRecord i18n translation of the model.

e.g.:

The recipe has many recipe items.

```ruby
ATTRIBUTE_TYPES = {
  recipe_items: Field::HasMany,
  id: Field::Number,
  name: Field::String,
  package_spec: Field::String,
  remark: Field::String,
  created_at: Field::DateTime,
  updated_at: Field::DateTime,
}.freeze
```

```yaml
zh-TW:
  activerecord:
    models:
      recipe: 配方表
      recipe_item: 材料
```
  • Loading branch information
jhang-jhe-wei authored Feb 2, 2022
1 parent b49efe4 commit cfef37b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/fields/has_many/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ as a count of how many objects are associated through the relationship.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
%>

<%= pluralize(field.data.size, field.attribute.to_s.humanize.downcase.singularize) %>
<%= pluralize(field.data.size, t("activerecord.models.#{field.attribute.to_s.singularize}", default: field.attribute.to_s.humanize.downcase.singularize, count: field.data.size)) %>

0 comments on commit cfef37b

Please sign in to comment.