Reputation: 665
I'd like to concatenate the strings from my localization file "admin.titles.index" and "%{model_name}" (which takes from activerecord.models.harddisk).
I tried with:
<% title = I18n.t("admin.titles.index") + I18n.t("%{model_name}",
model_name: admin.model_name,
pluralized_model_name: admin.model_name.pluralize)%>
<% content_for(:title, title) %>
But I get an error message:
translation missing: de.%{model_name}
How can I fix that?
Upvotes: 0
Views: 3873
Reputation: 15045
You need to provide a translation for a string, that you pass in I18n.t
. As long as you don't have a translation for "%{model_name}"
you'll get the error message.
In your case, you can just concatenate the string from localization with your model name:
<% title = I18n.t("admin.titles.index") + admin.model_name %>
Otherwise, you need to provide a translation for model_name
in yml
file. For example:
en:
model_name: "English %{model_name}"
de:
model_name: "German %{model_name}"
and then use it as
I18n.t("admin.titles.index") + I18n.t("model_name", model_name: admin.model_name)
Upvotes: 1