Change reCaptcha language dynamically in Angular
How to setup reCaptcha in Angular using PrimeNg
This article is the continuation of an article I wrote on reCaptcha.
There I used ng-recaptcha
library to setup recaptcha
. This libraray
is great, but the issue with it is that, the reCaptcha
language change does not work all the time.
Recently I found reCaptcha
support is present in Primeng
library.
PrimeNg
makes it very simple to setup reCaptcha
.
Steps to setup reCaptcha
using PrimeNg
-
Install
primeNg
using below commands,npm install primeng --save npm install primeicons --save
-
Add below style in
angular.json
as below,"styles": [ "node_modules/primeicons/primeicons.css", "node_modules/primeng/resources/themes/lara-light-blue/theme.css", "node_modules/primeng/resources/primeng.min.css", ... ]
-
Once
primeNg
is installed we need can addreCaptcha
,-
Import below module in your
component.ts
fileimport {CaptchaModule} from 'primeng/captcha';
-
Add
reCaptcha
tag in your component html file<p-captcha siteKey="YOUR_SITE_KEY" (onResponse)="showResponse($event)"></p-captcha>
-
Add below script in index.html file
<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=initRecaptcha" async defer></script>
-
The generated
reCaptcha
code will be available inshowResponse
method. This code needs to sent to your backend API to complete therecaptcha
security. -
We can change language easily by using
language
attribute as shown below,<p-captcha siteKey="YOUR_SITE_KEY" language="en" (onResponse)="showResponse($event)"></p-captcha>
That’s it!. That’s how easy it is to setup
reCaptcha
usingPrimeNg
For more information on
PrimeNg reCaptcha
refer documentation at http://primefaces.org/primeng/captcha -