diff --git a/lib/Captcha/reCAPTCHA/V2.pm b/lib/Captcha/reCAPTCHA/V2.pm index a45aaf1..1abe90f 100644 --- a/lib/Captcha/reCAPTCHA/V2.pm +++ b/lib/Captcha/reCAPTCHA/V2.pm @@ -41,14 +41,29 @@ web application. Creates a new instance of Captcha::reCAPTCHA::V2. - my $rc = Captcha::reCAPTCHA::V2->new; + my $rc = Captcha::reCAPTCHA::V2->new(hl => en); + +Parameters: + +=over 4 + +=item * C<$hl> + +Specific language to render widget. Default value is C<'en'>. +Language options see L. + +=back + +=back =cut sub new { - my $class = shift; + my ($class, %options) = @_; my $self = bless {}, $class; + my $hl = $options{hl} || 'en'; + # Initialize the user agent object $self->{ua} = HTTP::Tiny->new( agent => 'Captcha::reCAPTCHA::V2/'. @@ -56,7 +71,7 @@ sub new { ); $self->{widget_api} = 'https://www.google.com/recaptcha/api.js?'. - 'onload=onloadCallback&render=explicit'; + 'onload=onloadCallback&render=explicit&hl='.$hl; $self->{verify_api} = 'https://www.google.com/recaptcha/api/siteverify'; diff --git a/t/01-html.t b/t/01-html.t index 60ab9d7..25e0e59 100644 --- a/t/01-html.t +++ b/t/01-html.t @@ -31,8 +31,21 @@ my $html = $rc2->html( } ); -my $captcha_widget_html = $grecaptcha_script . q^
^; +my $captcha_widget_html = $grecaptcha_script . q^
^; is( $html, $captcha_widget_html, 'get correct html to render the widget' ); +like( $html, qr/hl=en/, 'get correct default display language is "en"' ); + +$rc2 = Captcha::reCAPTCHA::V2->new(hl => 'th'); +$html = $rc2->html( + 'ThisIsASitekey', + { + theme => 'light', + type => 'image', + size => 'normal', + } +); + +like( $html, qr/hl=th/, 'get specific language to render widget is "th"' ); done_testing \ No newline at end of file