Search code examples
ruby-on-railsruby-on-rails-3internationalizationrails-i18nfallback

How to use the I18n fallback features in 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"

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


Solution

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

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

    More info here