如何在 Rails 3 中使用 I18n 后备功能 [英] How to use the I18n fallback features in Rails 3

查看:16
本文介绍了如何在 Rails 3 中使用 I18n 后备功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到翻译缺失";来自 Rails 3 的错误消息:

I am getting an "translation missing" error message from Rails 3:

activerecord:
  notices:
    messages:
      success: 
        create: "Something was created"
    models:
      user:
        success:
          create: "Thanks for registration"

I18n.t("activerecord.notices.models.user.success.create")
# => "Thanks for registration"


I18n.t("activerecord.notices.models.book.success.create") 
# => "translation missing: de, activerecord, notices, models, book, success, create"

我不知道为什么书本模型没有得到后备按摩.我已经设置了 config.i18n.fallbacks = true.

I don't know why the book model doesn't get the fallback massage. I have set config.i18n.fallbacks = true.

推荐答案

当给定一个 :default 选项时,如果翻译缺失,则返回其值:

When a :default option is given, its value will be returned if the translation is missing:

I18n.t :missing, :default => 'Not here'
# => 'Not here'

更多信息这里

这篇关于如何在 Rails 3 中使用 I18n 后备功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆