-
Notifications
You must be signed in to change notification settings - Fork 106
Open
Description
Problem
When using non-English locales, the model names in the "Add" and "Remove" buttons are not correctly translated. The current implementation uses field.associated_class_name.titleize directly, which doesn't go through the Rails translation system.
For example, even when I have defined translations for model names in config/locales/ja.yml:
ja:
activerecord:
models:
app_release: "お知らせ"The button still displays "Add App Release" instead of "Add お知らせ".
Steps to Reproduce
- Set up a non-English locale (e.g., Japanese)
- Define translations for model names in the locale files
- Use nested_has_many fields in a form
- Observe that the model name in the buttons is not translated
Proposed Solution
I propose two possible solutions:
1. Prioritize the name_label option if it's present:
<%= link_to_add_association(
field.options.try(:[], :name_label).present? ?
"#{I18n.t('administrate.fields.nested_has_many.add_with_name', name: field.options[:name_label])}" :
I18n.t("administrate.fields.nested_has_many.add", resource: field.associated_class_name.titleize),
f,
field.association_name,
...
) %>2. Or use Rails' translation system to get the model name:
<%= link_to_add_association(
I18n.t("administrate.fields.nested_has_many.add", resource: I18n.t("activerecord.models.#{field.associated_class_name.underscore}", default: field.associated_class_name.titleize)),
f,
field.association_name,
...
) %>I'm happy to submit a pull request with this change if it's considered valuable.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels