I18n :: InvalidLocale::en不是有效的语言环境 [英] I18n::InvalidLocale: :en is not a valid locale

查看:219
本文介绍了I18n :: InvalidLocale::en不是有效的语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用I18n.transliterate对带有重音字符的某些文本进行规范化",以便我可以将其与不同的语言进行分析和比较.

I am trying to use I18n.transliterate to "normalize" some text with accented characters so I can analyze and compare it with different languages.

但是,使用此方法时,会弹出以下错误消息

However, when using this method the following error pops out

I18n::InvalidLocale: :en is not a valid locale
    from /home/xxx/.rvm/gems/ruby-2.1.5/gems/i18n-0.7.0/lib/i18n.rb:284:in `enforce_available_locales!'
    from /home/xxx/.rvm/gems/ruby-2.1.5/gems/i18n-0.7.0/lib/i18n.rb:235:in `transliterate'
    from (irb):2
    from /home/xxx/.rvm/rubies/ruby-2.1.5/bin/irb:11:in `<main>'

我已经对这个问题进行了一些搜索,但是我只找到了与Rails配置有关的解决方案.我只是在Ruby文件中使用它,与Rails无关,所以...该怎么办?

I have made some searches for this problem and I only found solutions related to Rails configuration. I am just using this in a Ruby file, nothing related to Rails, so... What can I do?

推荐答案

我似乎也遇到了类似的问题,我通过检查与错误相关的源代码来解决了该问题.

I seem to have a similar problem which I resolved by inspecting the source code associated with the error.

我发现我必须像这样显式设置可用的语言环境:

I found I have to explicitly set the available locales like so:

I18n.config.available_locales = :en

我不确定这是否是正确的方法,我还发现以下方法可以达到相同的效果,并且可能更健壮.

I'm not sure if this is the correct approach, I see also that the following achieves the same effect and is likely more robust.

这篇关于I18n :: InvalidLocale::en不是有效的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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