【问题标题】:what is the actual parameter for the locale=I18nData.country_code(request.location.country)?locale=I18nData.country_code(request.location.country) 的实际参数是什么?
【发布时间】:2012-11-19 11:57:10
【问题描述】:

首先,安装 gem geocoder 和 gem i18n_data 来完成这项工作。

我对这个locale=I18nData.country_code(request.location.country) 进行了测试,稍作调整(出于测试目的)。这就是我实际所做的

@country=I18nData.country_code("Spain")

返回

@country="ES"

但是当我刚刚这样做时

@country=I18nData.country_code("spain")

它没有显示输出。很明显 spain 的字母需要大写 S 但是当 Web 应用程序上线时,@country=I18nData.country_code(request.location.country) 实际上会给出真正的参数,即“Spain”?

对此的任何帮助都将真正帮助我澄清这种困惑! 非常感谢

【问题讨论】:

    标签: ruby-on-rails ruby internationalization locale


    【解决方案1】:

    在这里和那里提出问题并经过测试后,答案是,上述方法提取“西班牙”并将语言环境明确设置为“ES”

    【讨论】:

    • 有趣,对我来说 request.location 在控制器方法中抛出 undefined method 'location' for #<ActionDispatch::Request:0x2230050>。你把这段代码放在哪里?
    • 首先,安装gem geocoder和gem i18n_data。将它们放在您的应用程序控制器中
    • 啊,好的。我认为您应该将其包含在您的问题中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    • 2019-12-05
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    • 2014-11-24
    • 2021-05-12
    相关资源
    最近更新 更多