I18n with arguments
suggest changeYou can pass parameters to the I18n t method:
# config/locales/en.yml
en:
page:
users: "%{users_count} users currently online"
# In models, controllers, and elsewhere
I18n.t("page.users", users_count: 12)
# => "12 users currently online"
<%= t("page.users", users_count: 12) %>
= t("page.users", users_count: 12)
A leading dot is a lazy lookup, scoped to the current template. In app/views/page/users.html.erb, t(".users") looks up page.users.users, not page.users. For the YAML above, call t("page.users"), or call t(".") from that template. t(".") uses the template scope itself.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents