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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter McGinnis
2010-Nov-23 02:53 UTC
Re: How do I internationalize/localize my rails plugin?
Hi, Here''s some example code from a Rails engine: https://github.com/kete/external_search_sources/blob/master/init.rb You''ll note that it follows the Rails convention of having a config and config/locales directory. Hope that helps, Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Paul Schreiber
2010-Nov-26 17:27 UTC
Re: How do I internationalize/localize my rails plugin?
On Nov 22, 9:53 pm, Walter McGinnis <walter.mcgin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here''s some example code from a Rails engine: > > https://github.com/kete/external_search_sources/blob/master/init.rb > > You''ll note that it follows the Rails convention of having a config > and config/locales directory. > > Hope that helps,Unfortunately, it does not. I tried this layout: validates_word_count/ init.rb lib/ validates_word_count.rb config locales/ en.yml And I still get the "translation missing" error. Paul -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter McGinnis
2010-Nov-26 18:44 UTC
Re: Re: How do I internationalize/localize my rails plugin?
Yes, but did you add your locales directory to the load path as in init.rb file I linked to? That part is the missing step. Using the convention of Rails is not enough, you have to tell Rails to include files in the directory. Cheers, Walter On Sat, Nov 27, 2010 at 6:27 AM, Paul Schreiber <paulschreiber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 22, 9:53 pm, Walter McGinnis <walter.mcgin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Here''s some example code from a Rails engine: >> >> https://github.com/kete/external_search_sources/blob/master/init.rb >> >> You''ll note that it follows the Rails convention of having a config >> and config/locales directory. >> >> Hope that helps, > > Unfortunately, it does not. I tried this layout: > > validates_word_count/ > init.rb > lib/ > validates_word_count.rb > config > locales/ > en.yml > > And I still get the "translation missing" error. > > > Paul > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter McGinnis
2010-Nov-27 01:25 UTC
Re: Re: How do I internationalize/localize my rails plugin?
Success. I heard back from Paul that that last bit did the trick. Cheers, Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.