0

我的代码在这里工作正常。我关心的是 :confirm =>

<%= link_to I18n.t('helpers.links.remove_from_your_page'), '#', 
            :confirm => I18n.t('helpers.links.confirmation'), 
            :remote_url => reject_review_path(review),
            :class => 'btn btn-danger remove_page_button_pos remove-from-your-page', 
            :id => "remove_from_your_page_#{review.id}" %>

我的国际化文件有:

Helpers:
 links:
  confirmation: "Are you sure?"

因此,当该人单击按钮时,在继续之前,他们会收到带有“您确定吗?”的确认框,带有“取消”和“确定”按钮 - 按计划工作。

问题是当我想在确认框中的行之间放置空格时。例如,我想要:

Are you sure?

If you do this, that might happen.

If you do that, this might happen.

Cancel     OK

我认为我下面的内容会起作用,但它没有:

(注意'原始',在:确认等......)

<%= link_to I18n.t('helpers.links.remove_from_your_page'), '#', 
            :confirm => raw I18n.t('helpers.links.confirmation'), 
            :remote_url => reject_review_path(review),
            :class => 'btn btn-danger remove_page_button_pos remove-from-your-page', 
            :id => "remove_from_your_page_#{review.id}" %>

在我的国际化中,我有:

Helpers:
 links:
  confirmation: "Are you sure?<br/>If you do this, that might happen. <br/>If you do that, this might happen."

但我得到一个语法错误。知道如何让它工作吗?谢谢。

4

1 回答 1

1

您将无法生成 HTML 标记,但您当然可以插入换行符

Helpers:
  links:
    confirmation: |
      Are you sure?
      If you do this, that might happen.
      If you do that, this might happen."

I18n.t('confirmation') #=> "Are you sure?\nIf you do this, that might happen.\nIf you do that, this might happen.\n"

记住要注意空格和制表符。YAML 对间距的一致性非常具体。标准是两个空格缩进并且没有制表符。

于 2013-06-18T00:45:03.097 回答