首页 > 解决方案 > 仅当在 ruby​​ 中使用 i18n api 时,如何将我的 www.example.com/en 设置为 www.example.com?

问题描述

我有一个下拉菜单,其中包含选项 1. 英语 2. 泰语 但我想要类似当我选择英语时应该选择默认 url 并使用 i18n ruby​​ 删除 en 参数。任何帮助表示赞赏。谢谢!

这是我的代码

this is my application_controller.rb file

private

  def default_url_options
    { locale: I18n.locale }
  end


  def set_locale
    I18n.locale = extract_locale || I18n.default_locale
  end

  def extract_locale
    parsed_locale = params[:locale]
    I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale.to_sym : nil
  end```

This is my route.rb file

  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
    get 'careers' => 'pages#careers', :as => :careers
end

标签: rubyinternationalization

解决方案


推荐阅读