Skip to content

Commit a41a6c5

Browse files
committed
Change lang to be used in props only
- old parameters is still used as as a default is no prop is sent
1 parent f376dc3 commit a41a6c5

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ ReactDOM.render(
114114

115115
#### Global properties used by reCaptcha
116116

117-
__lang__: By default google reCaptcha infers the user's interface language. In order to overwrite the language and update the translation for the reCaptcha widget, you can create a global variable configuring the desired language via `lang`.
117+
__lang__: *DEPRECATED* By default google reCaptcha infers the user's interface language. In order to overwrite the language and update the translation for the reCaptcha widget, you can create a global variable configuring the desired language via `lang`.
118+
119+
*Instead use props.hl* reCaptcha now supports an hl property to be passed at render. The global lang parameter is no longer need and will be removed.
118120

119121
__useRecaptchaNet__: If google.com is blocked, you can set `useRecaptchaNet` to `true` so that the component uses recaptcha.net instead.
120122

121-
__removeOnUnmount__: If you plan to change the lang dynamically, `removeOnUnmount` should probably be `true`. This unloads the google recaptcha script on `componetWillUnmount` to allow for a new google recaptcha script to load next time the reCAPTCHA component is used to facilitate a new language if needed.
123+
__removeOnUnmount__: *REMOVED* This was only useful for the lang changes. Lang is now changed through
122124

123125
Example global properties:
124126
```js
125127
window.recaptchaOptions = {
126-
lang: 'fr',
127128
useRecaptchaNet: true,
128-
removeOnUnmount: false,
129129
};
130130
```
131131

src/recaptcha-wrapper.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
import ReCAPTCHA from "./recaptcha";
1+
import ReCAPTCHA, { getOptions } from "./recaptcha";
22
import makeAsyncScriptLoader from "react-async-script";
33

4-
function getOptions() {
5-
return (typeof window !== "undefined" && window.recaptchaOptions) || {};
6-
}
4+
const callbackName = "onloadcallback";
5+
const globalName = "grecaptcha";
6+
77
function getURL() {
88
const dynamicOptions = getOptions();
9-
const lang = dynamicOptions.lang ? `&hl=${dynamicOptions.lang}` : "";
109
const hostname = dynamicOptions.useRecaptchaNet ? "recaptcha.net" : "www.google.com";
11-
return `https://${hostname}/recaptcha/api.js?onload=${callbackName}&render=explicit${lang}`;
10+
return `https://${hostname}/recaptcha/api.js?onload=${callbackName}&render=explicit`;
1211
}
1312

14-
const callbackName = "onloadcallback";
15-
const globalName = "grecaptcha";
16-
const initialOptions = getOptions();
17-
1813
export default makeAsyncScriptLoader(getURL, {
1914
callbackName,
2015
globalName,
21-
removeOnUnmount: initialOptions.removeOnUnmount || false,
2216
})(ReCAPTCHA);

src/recaptcha.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33

4+
export function getOptions() {
5+
return (typeof window !== "undefined" && window.recaptchaOptions) || {};
6+
}
7+
48
export default class ReCAPTCHA extends React.Component {
59
constructor() {
610
super();
@@ -53,6 +57,8 @@ export default class ReCAPTCHA extends React.Component {
5357

5458
explicitRender() {
5559
if (this.props.grecaptcha && this.props.grecaptcha.render && this._widgetId === undefined) {
60+
const hl = this.props.hl || getOptions().lang || undefined;
61+
5662
const wrapper = document.createElement("div");
5763
this._widgetId = this.props.grecaptcha.render(wrapper, {
5864
sitekey: this.props.sitekey,
@@ -64,7 +70,7 @@ export default class ReCAPTCHA extends React.Component {
6470
"error-callback": this.handleErrored,
6571
size: this.props.size,
6672
stoken: this.props.stoken,
67-
hl: this.props.hl,
73+
hl,
6874
badge: this.props.badge,
6975
});
7076
this.captcha.appendChild(wrapper);

0 commit comments

Comments
 (0)