在Rails中的ruby中自动设置语言环境 [英] set locale automatically in ruby on rails

查看:87
本文介绍了在Rails中的ruby中自动设置语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Rails上的红宝石上自动设置语言环境?例如,如果在西班牙打开了网页,则语言环境为es,在英国也是如此,那么语言环境是否为en或类似?

how to set locale automatically on ruby on rails? For instance, if the web pages is opened up in Spain then the locale=es, similarly if it is in united kingdom then the locale=en and alike?

请帮帮我.

推荐答案

尝试使用gem geocoder i18n_data gem 并使用before_filter转换为可以的方法

try using gem geocoder and i18n_data gem and have a before_filter to a method which does

def checklocale
  I18n.locale =  I18nData.country_code(request.location.country) 
end

这篇关于在Rails中的ruby中自动设置语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆