Skip to content

Commit

Permalink
Add language enhancement for #8
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMeadows committed Jan 12, 2019
1 parent a2e80f7 commit 37caf51
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions reCAPTCHA.AspNetCore/Models/v2Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class v2Model
public Guid Uid { get; set; }
public string Method { get; set; }
public string Theme { get; set; }
public string Language { get; set; }
public RecaptchaSettings Settings { get; set; }
}
}
1 change: 1 addition & 0 deletions reCAPTCHA.AspNetCore/Models/v3Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class v3Model
{
public Guid Uid { get; set; }
public string Action { get; set; }
public string Language { get; set; }
public RecaptchaSettings Settings { get; set; }
}
}
11 changes: 7 additions & 4 deletions reCAPTCHA.AspNetCore/RecaptchaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class RecaptchaHelper
/// <param name="theme">Google Recaptcha theme default is light</param>
/// <param name="action">Google Recaptcha v3 <a href="https://developers.google.com/recaptcha/docs/v3#actions">Action</a></param>
/// <returns>HtmlString with Recaptcha elements</returns>
public static HtmlString Recaptcha(this IHtmlHelper helper, RecaptchaSettings settings, string theme = "light", string action = "homepage")
public static HtmlString Recaptcha(this IHtmlHelper helper, RecaptchaSettings settings, string theme = "light", string action = "homepage", string language = "en")
{
var uid = Guid.NewGuid();
var method = uid.ToString().Replace("-", "_");
Expand All @@ -31,22 +31,25 @@ public static HtmlString Recaptcha(this IHtmlHelper helper, RecaptchaSettings se
Settings = settings,
Uid = uid,
Method = method,
Theme = theme
Theme = theme,
Language = language
}).TransformText());
case "v2-invis":
return new HtmlString(new v2Invis(new v2Model()
{
Settings = settings,
Uid = uid,
Method = method,
Theme = theme
Theme = theme,
Language = language
}).TransformText());
case "v3":
return new HtmlString(new v3(new v3Model()
{
Settings = settings,
Uid = uid,
Action = action
Action = action,
Language = language
}).TransformText());
}
}
Expand Down
9 changes: 8 additions & 1 deletion reCAPTCHA.AspNetCore/Templates/v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ public virtual string TransformText()

#line default
#line hidden
this.Write("&render=explicit\" async defer></script>");
this.Write("&render=explicit&hl=");

#line 11 "C:\Repository\TimothyMeadows\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v2.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Model.Language));

#line default
#line hidden
this.Write("\" async defer></script>");
return this.GenerationEnvironment.ToString();
}
}
Expand Down
2 changes: 1 addition & 1 deletion reCAPTCHA.AspNetCore/Templates/v2.tt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
grecaptcha.render('<#= Model.Uid #>', {'sitekey' : '<#= Model.Settings.SiteKey #>', 'theme' : '<#= Model.Theme #>' })
}
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=_<#= Model.Method #>&render=explicit" async defer></script>
<script src="https://www.google.com/recaptcha/api.js?onload=_<#= Model.Method #>&render=explicit&hl=<#= Model.Language #>" async defer></script>
9 changes: 8 additions & 1 deletion reCAPTCHA.AspNetCore/Templates/v2Invis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ public virtual string TransformText()

#line default
#line hidden
this.Write("&render=explicit\" async defer>");
this.Write("&render=explicit&hl=");

#line 19 "C:\Repository\TimothyMeadows\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v2Invis.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Model.Language));

#line default
#line hidden
this.Write("\" async defer>");
return this.GenerationEnvironment.ToString();
}
}
Expand Down
2 changes: 1 addition & 1 deletion reCAPTCHA.AspNetCore/Templates/v2Invis.tt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
document.getElementById('g-recaptcha-response').value = token;
}
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=_<#= Model.Method #>&render=explicit" async defer>
<script src="https://www.google.com/recaptcha/api.js?onload=_<#= Model.Method #>&render=explicit&hl=<#= Model.Language #>" async defer>
15 changes: 11 additions & 4 deletions reCAPTCHA.AspNetCore/Templates/v3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace reCAPTCHA.AspNetCore.Templates
/// Class to produce the template output
/// </summary>

#line 1 "C:\Repository\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
#line 1 "C:\Repository\TimothyMeadows\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")]
public partial class v3 : v3Base
{
Expand All @@ -28,22 +28,29 @@ public virtual string TransformText()
this.Write("\r\n<input id=\"g-recaptcha-response\" name=\"g-recaptcha-response\" type=\"hidden\" valu" +
"e=\"\" />\r\n<script src=\"https://www.google.com/recaptcha/api.js?render=");

#line 5 "C:\Repository\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
#line 5 "C:\Repository\TimothyMeadows\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Model.Settings.SiteKey));

#line default
#line hidden
this.Write("&hl=");

#line 5 "C:\Repository\TimothyMeadows\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Model.Language));

#line default
#line hidden
this.Write("\"></script>\r\n<script>\r\n\tif (typeof grecaptcha !== \'undefined\') {\r\n\t\tgrecaptcha.re" +
"ady(function () {\r\n\t\t\tgrecaptcha.execute(\'");

#line 9 "C:\Repository\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
#line 9 "C:\Repository\TimothyMeadows\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Model.Settings.SiteKey));

#line default
#line hidden
this.Write("\', { \'action\': \'");

#line 9 "C:\Repository\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
#line 9 "C:\Repository\TimothyMeadows\reCAPTCHA.AspNetCore\reCAPTCHA.AspNetCore\Templates\v3.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Model.Action));

#line default
Expand Down
2 changes: 1 addition & 1 deletion reCAPTCHA.AspNetCore/Templates/v3.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<#@ assembly name="System.Core" #>

<input id="g-recaptcha-response" name="g-recaptcha-response" type="hidden" value="" />
<script src="https://www.google.com/recaptcha/api.js?render=<#= Model.Settings.SiteKey #>"></script>
<script src="https://www.google.com/recaptcha/api.js?render=<#= Model.Settings.SiteKey #>&hl=<#= Model.Language #>"></script>
<script>
if (typeof grecaptcha !== 'undefined') {
grecaptcha.ready(function () {
Expand Down

0 comments on commit 37caf51

Please sign in to comment.