Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 98fba27

Browse files
committed
default language added (hl parameter)
1 parent 3b033d0 commit 98fba27

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

config/recaptcha.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,15 @@
6868
* @since v3.2.0
6969
*
7070
*/
71-
'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token')
71+
'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token'),
72+
73+
/**
74+
*
75+
* The default Google reCAPTCHA language code
76+
* It has no effect with v3
77+
* @see https://developers.google.com/recaptcha/docs/language
78+
* @since v3.6.0
79+
*
80+
*/
81+
'default_language' => env('RECAPTCHA_DEFAULT_LANGUAGE', null)
7282
];

src/ReCaptchaBuilder.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration =
214214
$html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>";
215215
break;
216216
default:
217-
$html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>";
217+
$language = config('recaptcha.default_language', null);
218+
$query = ($language) ? "?hl=" . $language : "";
219+
$html = "<script src=\"https://www.google.com/recaptcha/api.js" . $query . "\" async defer></script>";
218220
}
219221

220222
if ($this->version == 'invisible') {
@@ -350,6 +352,24 @@ public function validate($response) {
350352

351353
}
352354

355+
/**
356+
* @return string
357+
*/
358+
public function getApiSiteKey(): string
359+
{
360+
361+
return $this->api_site_key;
362+
}
363+
364+
/**
365+
* @return string
366+
*/
367+
public function getApiSecretKey(): string
368+
{
369+
370+
return $this->api_secret_key;
371+
}
372+
353373
/**
354374
* @return bool
355375
*/

tests/ReCaptchaLangTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2017 - present
4+
* LaravelGoogleRecaptcha - ReCaptchaLangTest.php
5+
* author: Roberto Belotti - [email protected]
6+
* web : robertobelotti.com, github.com/biscolab
7+
* Initial version created on: 7/8/2019
8+
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
9+
*/
10+
11+
namespace Biscolab\ReCaptcha\Tests;
12+
13+
use Biscolab\ReCaptcha\Facades\ReCaptcha;
14+
use Biscolab\ReCaptcha\ReCaptchaBuilderInvisible;
15+
use Biscolab\ReCaptcha\ReCaptchaBuilderV2;
16+
17+
class ReCaptchaLangTest extends TestCase
18+
{
19+
20+
/**
21+
* @var ReCaptchaBuilderInvisible
22+
*/
23+
protected $recaptcha_invisible;
24+
25+
/**
26+
* @var ReCaptchaBuilderV2
27+
*/
28+
protected $recaptcha_v2;
29+
30+
/**
31+
* @tests
32+
*/
33+
public function testHtmlScriptTagJsApiGetHtmlScriptWithHlParam()
34+
{
35+
36+
$r = ReCaptcha::htmlScriptTagJsApi();
37+
$this->assertEquals('<script src="https://www.google.com/recaptcha/api.js?hl=it" async defer></script>', $r);
38+
}
39+
40+
/**
41+
* Define environment setup.
42+
*
43+
* @param \Illuminate\Foundation\Application $app
44+
*
45+
* @return void
46+
*/
47+
protected function getEnvironmentSetUp($app)
48+
{
49+
50+
$app['config']->set('recaptcha.default_language', 'it');
51+
}
52+
53+
/**
54+
* Setup the test environment.
55+
*/
56+
protected function setUp(): void
57+
{
58+
59+
parent::setUp(); // TODO: Change the autogenerated stub
60+
61+
$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
62+
$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
63+
64+
}
65+
}

0 commit comments

Comments
 (0)