I'm trying to use Gettext and domains in a phoenix app to translate "materials" (wood, wool, cotton, kapok...). Materials come from a database.
This works:
<%= MyApp.Gettext.dgettext "materials", "cotton" %>
But this does not:
<%= MyApp.Gettext.dgettext "materials", "#{material.name}" %>
I'm trying to add the translation to a template
<%= for material <- @materials do %>
<td><%= AmazingApp.Gettext.dgettext "materials", "#{material.name}" %></td>
<% end %>
How can one go about translating in this situation?
You can use Gettext.dgettext/3
for this:
<%= Gettext.dgettext(MyApp.Gettext, "materials", material.name) %>
From the documentation:
Dynamic translations should be avoided as they limit Gettext's ability to extract translations from your source code. If you are sure you need dynamic lookup, you can use the functions in the Gettext module:
string = "hello world" Gettext.gettext(#{inspect(gettext_module)}, string)