Max*_*Max 0 yaml ruby-on-rails internationalization
我注意到在i18n rails指南中,它们有以下代码:
en:
activerecord:
errors:
template:
header:
one: "1 error prohibited this %{model} from being saved"
other: "%{count} errors prohibited this %{model} from being saved"
body: "There were problems with the following fields:"
Run Code Online (Sandbox Code Playgroud)
这是什么%{...}意思?这有什么不同#{...}?
如果您再多阅读本指南,您会遇到Passing变量到翻译部分:
您可以在翻译消息中使用变量,并从视图中传递它们的值.
Run Code Online (Sandbox Code Playgroud)# app/views/home/index.html.erb <%=t 'greet_username', :user => "Bill", :message => "Goodbye" %> # config/locales/en.yml en: greet_username: "%{message}, %{user}!"
和插值部分:
在许多情况下,您希望抽象您的翻译,以便可以将变量插入到翻译中.因此,I18n API提供了插值功能.
除了
:default和:scope传递给的所有选项都#translate将插入到翻译中:Run Code Online (Sandbox Code Playgroud)I18n.backend.store_translations :en, :thanks => 'Thanks %{name}!' I18n.translate :thanks, :name => 'Jeremy' # => 'Thanks Jeremy!'
所以这些%{...}东西与YAML没有任何关系,这就是I18n在消息中处理变量插值的方式.
| 归档时间: |
|
| 查看次数: |
3153 次 |
| 最近记录: |