如何在我的视图中国际化 button_to 方法中的实例变量?

How do I internationalize instance variables in button_to methods in my views?

我有一些试图国际化的视图文件。这些文件之一恰好有这样的代码行:

= button_to t('.spam'), label_as_spammer_account_path(@topic.account), method: :post,
  data: { confirm: t('.spam_confirmation'), user: @topic.posts.first.account.name }, class: 'btn btn-mini btn-warning'

我尝试国际化的部分特别是消息的数据确认部分。如何国际化消息的 @topic.posts.first.account.name 部分?到目前为止,我的 topics.en.yml 文件中有这个(当然是压缩的)

topics:
  show:
    spam_confirmation: "Are you sure you want to mark %{user} as a spammer, disabling the account and removing all posts?"

%{user}部分我怎么修改上面的代码都拒绝国际化

我试过:

data: { confirm: t('.spam_confirmation'), user: "@topic.posts.first.account.name" }
data: { confirm: t('.spam_confirmation'), user: #{@topic.posts.first.account.name} }
data: { confirm: t('.spam_confirmation'), user: "#{@topic.posts.first.account.name}" }

在这一点上,我只是想尽一切努力看看是否有任何效果。但我必须具体说明,因为 rubocop/haml-lint 如果我做得不对就会抱怨。如果有人知道我可以尝试的其他任何事情,我们将不胜感激。提前致谢。

尝试将 user: 选项传递给 t 辅助方法:

data: { confirm: t('.spam_confirmation', user: @topic.posts.first.account.name) }