how to use rails i18n fallback features

后端 未结 6 1648
难免孤独
难免孤独 2020-12-03 13:02

I have this i18n problem

activerecord:
  notices:
    messages:
      success: 
        create: \"Something was created\"
    models:
      user:
        suc         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 14:00

    I believe the best way to handle a missing string, is to display a default locale, rather than an error message.

    Add this line in application.rb to fallback to the english locale.

    config.i18n.fallbacks = [:en]
    

    In case you want to specify locale-specific fallbacks, you can use the following:

    config.i18n.fallbacks = {:de => [:de,:en], :en => [:en,:de]}
    

    Also, note that you can enable and disable fallbacks based on your environment. So while on development it might make sense to have an error displayed, you can instead enable fallbacks in your environments/production.rb with the following:

    config.i18n.fallbacks = true
    

提交回复
热议问题