# How do I internationalize/localize my rails plugin?

**URL:** <https://www.ruby-forum.com/t/how-do-i-internationalize-localize-my-rails-plugin/199505>\
**Category:** Rails I18n\
**Created:** [November 23, 2010, 12:24am UTC](https://www.ruby-forum.com/t/how-do-i-internationalize-localize-my-rails-plugin/199505 "2010-11-23T00:24:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 23, 2010, 12:24am UTC](https://www.ruby-forum.com/t/how-do-i-internationalize-localize-my-rails-plugin/199505/1 "2010-11-23T00:24:55Z")

</div>

I wrote a validates\_word\_count plugin. I would like to store the error  
messages in a YAML file so they can be easily translated.

Full source:  
[GitHub - paulschreiber/validates\_word\_count: rails validation plugin. validates word count for a block of text.](https://github.com/paulschreiber/validates_word_count/)

My plugin’s file layout looks like this:  
validates\_word\_count/  
init.rb  
lib/  
validates\_word\_count.rb  
locale/  
en.yml

My YAML file looks like this:  
en:  
validates\_word\_count:  
errors:  
messages:  
too\_few\_words: “has too few words (minimum is %d words)”  
too\_many\_words: "has too many words (maximum is %d words)

However, if I call  
I18n.translate(‘validates\_word\_count.errors.messages.too\_few\_words’),  
I get this error:  
translation missing: en, validates\_word\_count, errors, messages,  
too\_few\_words

How can I set up my plugin / locale so I18n.translate() works?

Paul

---

<div class="post-metadata">

**Author:** ![Paul\_Schreiber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/53a042/32.png) [@Paul\_Schreiber](https://www.ruby-forum.com/u/Paul_Schreiber)\
**Post date:** [November 27, 2010, 1:28pm UTC](https://www.ruby-forum.com/t/how-do-i-internationalize-localize-my-rails-plugin/199505/2 "2010-11-27T13:28:19Z")

</div>

Hi Paul,

You have to add the file to the I18n load path. If you have a Railtie  
file, that would be the place to add it. By heart, it should be  
something like:

class Railtie \< ::Rails::Railtie  
ActiveSupport.before\_configuration do |config|  
config.i18n.load\_path += “your file”  
end  
end

For Rails 2, I don’t know. Probably just call I18n somewhere. As an  
example: devise has a generator that copies a locale file to the  
config/locale directory of the app.

Hope this helps,  
iain
