Skip to content

Commit

Permalink
hCaptcha default language change (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
3Dgoo authored Jan 10, 2024
1 parent 2aa5c75 commit a9ef6c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ X3dgoo\HCaptcha\Forms\HCaptchaField:
We generate our site key and secret key at https://www.hcaptcha.com/
The language of the captcha can be changed by setting the language_code variable to any of the
[available hCaptacha languages](https://docs.hcaptcha.com/languages/):
The default language of the captcha will be set to the site language. This can be changed by setting
the language_code variable to any of the
[available hCaptacha languages](https://docs.hcaptcha.com/languages/). If not set this will default
to the current site locale:
```yml
X3dgoo\HCaptcha\Forms\HCaptchaField:
Expand Down
8 changes: 5 additions & 3 deletions src/Forms/HCaptchaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\Validator;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\Requirements;

Expand Down Expand Up @@ -59,9 +60,8 @@ class HCaptchaField extends FormField
/**
* Captcha language code
* @var string
* @default en
*/
private static $language_code = 'en';
private static $language_code;

/**
* Creates a new HCaptcha field.
Expand Down Expand Up @@ -95,8 +95,10 @@ public function Field($properties = [])
);
}

$languageCode = self::config()->language_code ?? i18n::getData()->langFromLocale(i18n::get_locale());

Requirements::javascript(
'https://hcaptcha.com/1/api.js?hl=' . self::config()->language_code
'https://hcaptcha.com/1/api.js?hl=' . $languageCode
);

return parent::Field($properties);
Expand Down

0 comments on commit a9ef6c3

Please sign in to comment.