I18n for model-specific Rails submit button

跟風遠走 提交于 2019-12-30 03:40:08

问题


I've found that Rails allows for generic i18n of submit buttons via the following in config/locales/en.yml:

en:
  helpers:
    submit:
      create: "Create %{model}"
      submit: "Save %{model}"
      update: "Update %{model}"

However, I'm looking to update the create value only for one specific model. I'd like the text to read as "Upload %{model}" or just "Upload". How can I make this change for just one model (e.g.: a Photo model)?


回答1:


From the source code, it looks like you should be able to do this:

en:
  helpers:
    submit:
      post:
        create: "Upload %{model}"

where post is the name of your model. The inline docs also mention that you can do this.




回答2:


If you use the i18n-debug gem, the rails server will print translations look-up attempts to the console, like:

[i18n-debug] en.helpers.submit.post.create => nil


来源:https://stackoverflow.com/questions/13547144/i18n-for-model-specific-rails-submit-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!