Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 881
auralbee Avatar asked Mar 22 '11 13:03

auralbee


2 Answers

use __FILE__

Dir.glob( File.dirname(__FILE__) + "lib/locales/*.{rb,yml}" ) 
like image 127
fl00r Avatar answered Nov 02 '22 03:11

fl00r


For the record, if you put your locales in <GEM_ROOT>/config/locales, they will be picked up automatically.

like image 24
nathanvda Avatar answered Nov 02 '22 03:11

nathanvda