How do I add I18n locale dictionaries from gem to Rails Application
I have a gem that makes use of I18n locale dictionaries that reside in lib/locales/*.yml inside my gems folder.
When the gem is initialized I want to load these dictionaries into my rails application, but I cannot figure out how:
This is what I tried:
I18n.load_path += Dir.glob("lib/locales/*.{rb,yml}")
Unfortunately this does not work when the gem 开发者_如何学编程is loaded inside my Rails App. When I call I18n.t("foo")
I get "translation missing: en, foo"
.
I will probably have to provide the full path to the locales when invoking I18n.load_path, but I cannot figure out how.
Any hints?
use __FILE__
Dir.glob( File.dirname(__FILE__) + "lib/locales/*.{rb,yml}" )
For the record, if you put your locales in <GEM_ROOT>/config/locales
, they will be picked up automatically.
精彩评论