I’m having trouble using I18n.translate to translate an array.
Specifically, I’ve got this array,
module TaskEnums
OCTAVE_BANDS = [:hz63, :hz125, :hz250, :hz500, :hz1000, :hz2000, :hz4000, :hz8000, :hz16000]
end
and I have the following translation in a YAML file.
en:
TaskEnums:
OCTAVE_BANDS:
hz63: "63 Hz"
hz125: "125 Hz"
hz250: "250 Hz"
hz500: "500 Hz"
hz1000: "1000 Hz"
hz2000: "2000 Hz"
hz4000: "4000 Hz"
hz8000: "8000 Hz"
hz16000: "16000 Hz"
In my view, I’d like to display a dropdown menu that allows users to select a frequency.
<%= form_for(@task) do |f| %>
<%= f.select :frequency, TaskEnums::OCTAVE_BANDS %>
<% end %>
I know I can translate individual symbols with t :symbol, but this approach doesn’t seem to work with arrays (e.g. t TaskEnums::OCTAVE_BANDS doesn’t do what I need).
Does anyone know how I can translate the OCTAVE_BANDS array, so that the translations appear in the dropdown? This seems like it must be a common problem, so I assume (and hope!) that there’s a simple solution… can anyone suggest how to get it done?
Many thanks,
D.
Use
scopeoption for yourI18n.tcall: