I18n support for recaptcha

There’s a nice plugin which adds helper for the reCAPTCHA. The downside is that it doesn’t support I18n at the moment.
This is a straight forward approach patch that adds this functionality. (I don’t know what will be the fate of I18n in Rails 3, thus the simple check for version).
The error message path then will be:
activerecord.errors.models.model_name.captcha

diff --git a/lib/recaptcha.rb b/lib/recaptcha.rb
index 87c26e9..44413bc 100644
--- a/lib/recaptcha.rb
+++ b/lib/recaptcha.rb
@@ -65,7 +65,11 @@ module Ambethia
             session[:recaptcha_error] = error
             if model = options[:model]
               model.valid?
-              model.errors.add_to_base "Captcha response is incorrect, please try again."
+              if Rails::VERSION::MAJOR >= 2 and Rails::VERSION::MINOR >= 2
+                model.errors.add_to_base I18n.translate("#{model.class.name.underscore}.captcha", :scope => %w(activerecord errors models), :default => "Captcha response is incorrect, please try again.")
+              else
+                model.errors.add_to_base "Captcha response is incorrect, please try again."
+              end
             end
             return false
           else

I wonder if this is the proper way of adding I18n support…
P.S. I reported this on lighthouse.

Leave a Reply

Pages

Adsense