Skip to content

Commit

Permalink
[added] temporary solution to the lang issue
Browse files Browse the repository at this point in the history
- Letting configure the language from an external global variable
- Updated the readme with the instructions to set the language

fixes #17
  • Loading branch information
iranreyes authored and dozoisch committed May 3, 2016
1 parent 073a3f0 commit 50e770f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ render(
ref="recaptcha"
sitekey="Your client site key"
onChange={onChange}
/>,
/>,
document.body
);
```
Expand All @@ -58,6 +58,14 @@ Other properties can be used to customised the rendering.
| onExpired | func | *optional* callback when the challenge is expired and has to be redone by user. By default it will call the onChange with null to signify expired callback. |
| stoken | string | *optional* set the stoken parameter, which allows the captcha to be used from different domains, see [reCAPTCHA secure-token] |

In order to translate the reCaptcha widget you should create a global variable configuring the desire language, if you don't provide it reCaptcha will pick up the user's interface language.

```
window.recaptchaOptions = {
lang: 'fr'
}
```

## Component API

The component also has some utility functions that can be called.
Expand Down Expand Up @@ -86,7 +94,7 @@ render(
sitekey="Your client site key"
onChange={onChange}
grecaptcha={grecaptchaObject}
/>,
/>,
document.body
);
```
Expand Down
5 changes: 4 additions & 1 deletion src/recaptcha-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import ReCAPTCHA from "./recaptcha";
import makeAsyncScriptLoader from "react-async-script";

const callbackName = "onloadcallback";
const URL = `https://www.google.com/recaptcha/api.js?onload=${callbackName}&render=explicit`;
const lang = typeof window !== "undefined" && (window.recaptchaOptions && window.recaptchaOptions.lang) ?
"&hl=" + window.recaptchaOptions.lang :
"";
const URL = `https://www.google.com/recaptcha/api.js?onload=${callbackName}&render=explicit${lang}`;
const globalName = "grecaptcha";

export default makeAsyncScriptLoader(ReCAPTCHA, URL, {
Expand Down

0 comments on commit 50e770f

Please sign in to comment.