How to avoid adding the default Locale in generated URLs?

前端 未结 4 630
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 14:36

If you follow the I18N Rails Guide, all generated links contain the locale parameter (localhost/en/about, localhost/fr/about). This is because we use the method defaul

4条回答
  •  忘掉有多难
    2020-12-25 15:35

    Rails 4 + https://github.com/svenfuchs/routing-filter

    def set_locale
      I18n.locale = params[:locale] || I18n.default_locale
    end
    
    def default_url_options(options = {})
      (I18n.locale.to_sym.eql?(I18n.default_locale.to_sym) ? {} : {locale: I18n.locale}).merge options
    end
    

提交回复
热议问题