【问题标题】:My URLs have this "?locale=en" appended. Is that normal?我的 URL 附加了这个“?locale=en”。这正常吗?
【发布时间】:2013-04-04 15:07:36
【问题描述】:

我的大部分网站都在 locales(i18n) 下工作。但是,现在我在管理方面工作。这在任何本地都不起作用。我刚刚意识到,不在本地范围内的每个 URL 都有这个“?locale=en”附加到 URL 的末尾。

你可以看看这个网站。每个 URL 似乎都很好。但是,如果您转到带您返回根目录的左上角图标,则会在 URL 中添加该位。 http://hik-fyp.heroku.com

我猜是用某种语言显示根。但是,当涉及到管理部分(单语)时,它无处不在。

正常吗?这会以某种方式干扰网站吗?有没有办法摆脱它? 我花了一段时间在网上研究,但找不到类似的东西。提前谢谢...

这是来自 ApplicationController 的摘录

after_filter :store_location
  before_filter :set_locale




  def set_locale
    logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}"
    I18n.locale = params[:locale] || extract_locale_from_accept_language_header || I18n.default_locale
    logger.debug "* Locale set to '#{I18n.locale}'"
    if current_user
      current_user.locale = params[:locale]
      current_user.save
    end
    session[:locale] = I18n.locale
  end


  def default_url_options(options={})
    logger.debug "default_url_options is passed options: #{options.inspect}\n"
    { :locale => I18n.locale }
  end


  def store_location
    # store last url as long as it isn't a /users path
    session[:previous_url] = request.fullpath unless request.fullpath =~ /\/users/
  end

  def after_sign_in_path_for(resource)
    session[:previous_url] || root_path
  end

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 internationalization


    【解决方案1】:

    你定义了当你设置时发生的事情

    def default_url_options(options={})
      { :locale => I18n.locale }
    end
    

    这告诉 rails url_for 帮助器(它是 link_to 和许多其他的基础)自动包含语言环境参数。

    【讨论】:

      猜你喜欢
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 2014-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多