gpt4 book ai didi

ruby-on-rails - Rails 中的 I18n 过滤器

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:34 26 4
gpt4 key购买 nike

我有一个无法通过 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' } %>

下拉列表始终以西类牙语显示...

谢谢!

编辑:我尝试了更多没有翻译的类别,似乎下拉菜单将西类牙语作为默认语言(来自英语语言环境网站的屏幕截图): enter image description here

有什么线索吗?

最佳答案

<%= f.select :categories_name_in, options_for_select(@categories.values, @category_selected), { include_blank: t('all_categories') }, { class: 'selectbox' } %>

您需要使用@categories.values 而不是@categoties

关于ruby-on-rails - Rails 中的 I18n 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33387140/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com