如何将link_to确认消息国际化?

时间:2015-02-09 18:56:32

标签: ruby-on-rails internationalization rails-i18n

正如标题所暗示的那样。我将如何将这样的内容国际化:

 = link_to t('.close'), topic_path(@topic, topic: { closed: '0' }),
    method: :put, confirm: 'Are you sure you want to close this topic?',
    class: 'btn btn-mini', title: "Close topic '#{@topic.title}'"

我想要做的是I18n方法链接的确认部分。我该怎么做呢?我现在已经玩了很多我的topics.en.yml文件(如下所示)。一些帮助将不胜感激。

en:

topics:
  new:
    create_topic: 'Post Topic'
  create:
    success: 'Topic successfully created'
    error: 'Unable to successfully create topic'
  show:
    close: 'Close'
    # close_confirm: 'Are you sure you want to close this topic?'
    delete: 'Delete'
    reopen: 'Re-open'
  edit:
    save_changes: 'Save Changes'
  update:
    success: 'Topic updated'
    error: 'Sorry, there was a problem updating the topic'
  destroy:
    success: 'Topic successfully removed'
    error: 'There was a problem deleting the forum'
  form:
    title: 'Title (required)'
    enter_topic_title: 'Enter the topic title.'
    message: 'Message'
    first_post: 'This will be the first post'
    sticky: 'Sticky'
    closed: 'Closed'

1 个答案:

答案 0 :(得分:0)

取消注释close_confirm中的topics.en.yml密钥并使用t辅助方法。

= link_to t('.close'), topic_path(@topic, topic: { closed: '0' }),
   method: :put, confirm: t('.close_confirm'),
   class: 'btn btn-mini', title: "Close topic '#{@topic.title}'"

http://api.rubyonrails.org/classes/ActionView/Helpers/TranslationHelper.html#method-i-translate