Skip to content

Commit

Permalink
Add lang prop.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasjunior committed Jul 3, 2020
1 parent 428eb92 commit f4cd912
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class App extends Component {

|Name|Value|Default|Description|
|-|-|-|-|
|lang|`string`||[Language code](https://developers.google.com/recaptcha/docs/language).|
|siteKey|`string`||Your sitekey.|
|baseUrl|`string`||The URL (domain) configured in the reCAPTCHA setup. (ex. http://my.domain.com)|
|headerComponent|`React Element`||A component to render on top of Modal.|
Expand All @@ -75,14 +76,16 @@ class App extends Component {
|onError|`function(error)`||A callback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. If you specify a function here, you are responsible for informing the user that they should retry.|
|onClose|`function()`|| A callback function, executed when the Modal is closed.|

Note: If `lang` is not set, then device language is used.

## Methods

|Name|Type|Description|
|-|-|-|-|
|open|`function`|Open the reCAPTCHA Modal.|
|close|`function`|Close the reCAPTCHA Modal.|

Note: If using `size="invisible"`, then the challange will be called automatically when the Modal is opened.
Note: If using `size="invisible"`, then challange run automatically when `open` is called.

## reCAPTCHA v2 docs

Expand Down
3 changes: 2 additions & 1 deletion Sample/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ const App = () => {
</View>

<Recaptcha
headerComponent={<Button title="Fechar" onPress={handleClosePress} />}
ref={$recaptcha}
lang="en"
headerComponent={<Button title="Fechar" onPress={handleClosePress} />}
siteKey="6LejsqwZAAAAAGsmSDWH5g09dOyNoGMcanBllKPF"
baseUrl="http://127.0.0.1"
size={size}
Expand Down
6 changes: 4 additions & 2 deletions src/Recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const Recaptcha = forwardRef(
size,
siteKey,
baseUrl,
lang,
},
$ref,
) => {
Expand All @@ -84,9 +85,10 @@ const Recaptcha = forwardRef(
return getTemplate({
siteKey,
size,
theme
theme,
lang,
});
}, [siteKey, size, theme]);
}, [siteKey, size, theme, lang]);

const handleLoad = useCallback(
(...args) => {
Expand Down
8 changes: 4 additions & 4 deletions src/get-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
const getTemplate = (params) => {
let template = `
<!DOCTYPE html>
<html lang="en">
<html lang="{{lang}}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script src="https://www.google.com/recaptcha/api.js?hl={{lang}}" async defer></script>
<script>
const siteKey = '{{siteKey}}';
const theme = '{{theme}}';
Expand Down Expand Up @@ -175,8 +175,8 @@ const getTemplate = (params) => {

Object.entries(params)
.forEach(([key, value]) => {
template = template.replace(`{{${key}}}`, value);
})
template = template.replace(new RegExp(`{{${key}}}`, 'img'), value);
});

return template;
};
Expand Down
4 changes: 2 additions & 2 deletions template/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<html lang="{{lang}}">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script src="https://www.google.com/recaptcha/api.js?hl={{lang}}" async defer></script>
<script>
const sitekey = '{{site-key}}';
const theme = '{{theme}}';
Expand Down

0 comments on commit f4cd912

Please sign in to comment.