How do I internationalize/localize my rails plugin?

11 views
Skip to first unread message

Paul Schreiber

unread,
Nov 22, 2010, 6:14:16 PM11/22/10
to rails-i18n
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:
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

Iain Hecker

unread,
Nov 27, 2010, 7:26:46 AM11/27/10
to rails...@googlegroups.com
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

> --
> You received this message because you are subscribed to the Google Groups "rails-i18n" group.
> To post to this group, send email to rails...@googlegroups.com.
> To unsubscribe from this group, send email to rails-i18n+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rails-i18n?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages