我有一个问题我无法用Rails中的国际化来解决。我在Rails中完全是新手。
我在room.rb中定义了一系列类别:
CATEGORY_COLLECTION = {
I18n.t('meeting_rooms') => "sala-de-reuniones",
"Aula de formación" => "aula-de-formacion",
"Sala para entrevistas" => "sala-para-entrevistas",
"Espacio para Eventos de Empresa" => "corporate-events",
"Showroom" => "showroom",
"Despacho" => "office",
"Sala multiusos" => "sala-multiusos",
"Puesto de Coworking" => "puesto-de-trabajo",
"Sala para conferencias" => "sala-para-conferencias",
"Sala de terapias" =>"sala-de-terapias",
"Otras salas" => "otras-salas",
"Espacio para rodaje" => "espacio-para-rodaje",
"Multiespacio" => "multiespacio",
"Fiesta de Navidad" => "christmas-events",
"Presentación de producto" => "product-presentation",
"Pop-up Stores" => "pop-up-stores",
"Show cooking" => "kitchen-studio",
"Shooting" => "shooting",
"Teatro" => "theater",
"Baile" => "dance-practice",
"Yoga" => "yoga",
"Performance" => "performance",
"Sala para fiestas particulares" => "sala-para-eventos"
正如你所看到的,我把国际化放在模型中,但是当我想要一个下拉列表时,没有国际化。
助手:
def categories
@categories = Room::CATEGORY_COLLECTION
@category_selected = Room::FILTER_CATEGORY_COLLECTION
end
下拉:
<%= f.select :categories_name_in, options_for_select(@categories, @category_selected), { include_blank: t('all_categories') }, { class: 'selectbox' } %>
下拉列表始终以西班牙语显示...
编辑: 我尝试了更多类别没有翻译,似乎下拉菜单将西班牙语作为默认语言(来自英语语言环境网站的截图):
有任何线索吗?
答案 0 :(得分:0)
<%= f.select :categories_name_in, options_for_select(@categories.values, @category_selected), { include_blank: t('all_categories') }, { class: 'selectbox' } %>
您需要使用 @ categories.values 而不是 @categoties