Skip to content
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

Defining translations for nested forms in namespaced resources #693

Open
cestbalez opened this issue May 15, 2024 · 1 comment
Open

Defining translations for nested forms in namespaced resources #693

cestbalez opened this issue May 15, 2024 · 1 comment

Comments

@cestbalez
Copy link

cestbalez commented May 15, 2024

What I tried to do

I have the below setup

class BudgetLine < ApplicationRecord
  has_many :budget_line_items
  accepts_nested_attributes_for :budget_line_items
end

class BudgetLine::Accommodation < BudgetLine
end

class BudgetLineItem < ApplicationRecord
  belongs_to :budget_line
end

Now I'm trying to specify labels for the nested form of BudgetLineItem inside a BudgetLine::Accommodation form.

What I expected to happen

According to the i18n documentation, you can normally do something like this:

en:
  activerecord:
    attributes:
      user/role:
        admin: "Admin"
        contributor: "Contributor"

What actually happened

This works if the model in question is not namespaced, as with User above. However, when you want to specify a namespaced model it has the same syntax with '/', so it becomes:

en:
  activerecord:
    attributes:
      budget_line/accommodation/budget_line_items:
        unit: Room

which does not work.

I've tried different variations of this, e.g.

en:
  activerecord:
    attributes:
      budget_line:
        accommodation/budget_line_items:
          unit: Room

which also does not work, because this way of specifying namespaces in locales seems to be deprecated..?

As far as I understand, if the label is to be translated correctly in my case, the following should return the correct translation: BudgetLine::Accommodation.human_attribute_name("budget_line_items.unit"), but so far I've been unsuccessful in my attempts to target this.

I'm not sure if this is a limitation with the library, of if there's something I'm missing here..?

Versions of i18n, rails, and anything else you think is necessary

i18n (1.14.4)
rails (7.1.3.2)
´´´
@cestbalez cestbalez changed the title [BUG] Defining translations for nested forms in namespaced resources Defining translations for nested forms in namespaced resources May 15, 2024
@omarsancas
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants