|
20 | 20 | #solving = false; |
21 | 21 | #eventHandlers; |
22 | 22 |
|
| 23 | + getI18nText(key, defaultValue) { |
| 24 | + return this.getAttribute(`data-cap-i18n-${key}`) || defaultValue; |
| 25 | + } |
| 26 | + |
23 | 27 | static get observedAttributes() { |
24 | 28 | return [ |
25 | 29 | "onsolve", |
|
102 | 106 |
|
103 | 107 | try { |
104 | 108 | this.#solving = true; |
105 | | - this.updateUI("verifying", "Verifying...", true); |
| 109 | + this.updateUI("verifying", this.getI18nText("verifying-label", "Verifying..."), true); |
106 | 110 |
|
107 | 111 | this.dispatchEvent("progress", { progress: 0 }); |
108 | 112 |
|
|
226 | 230 | this.#div.setAttribute("role", "button"); |
227 | 231 | this.#div.setAttribute("tabindex", "0"); |
228 | 232 | this.#div.setAttribute("disabled", "true"); |
229 | | - this.#div.innerHTML = `<div class="checkbox"></div><p>I'm a human</p><a href="https://capjs.js.org/" class="credits" target="_blank" rel="follow noopener"><span>Secured by </span>Cap</a>`; |
| 233 | + this.#div.innerHTML = `<div class="checkbox"></div><p>${this.getI18nText("initial-state", "I'm a human")}</p><a href="https://capjs.js.org/" class="credits" target="_blank" rel="follow noopener"><span>Secured by </span>Cap</a>`; |
230 | 234 | this.#shadow.innerHTML = `<style>.captcha{background-color:var(--cap-background);border:1px solid var(--cap-border-color);border-radius:var(--cap-border-radius);width:var(--cap-widget-width);display:flex;align-items:center;padding:var(--cap-widget-padding);gap:var(--cap-gap);cursor:pointer;transition:filter var(--cap-transition-duration),transform var(--cap-transition-duration);position:relative;-webkit-tap-highlight-color:rgba(255,255,255,0);overflow:hidden;color:var(--cap-color)}.captcha:hover{filter:var(--cap-hover-filter)}.captcha:not([disabled]):active{transform:scale(var(--cap-active-scale))}.checkbox{width:var(--cap-checkbox-size);height:var(--cap-checkbox-size);border:var(--cap-checkbox-border);border-radius:var(--cap-checkbox-border-radius);background-color:var(--cap-checkbox-background);transition:opacity var(--cap-transition-duration);margin-top:var(--cap-checkbox-margin);margin-bottom:var(--cap-checkbox-margin)}.captcha *{font-family:var(--cap-font)}.captcha p{margin:0;font-weight:500;font-size:15px;user-select:none;transition:opacity var(--cap-transition-duration)}.captcha[data-state=verifying] .checkbox{background: none;display:flex;align-items:center;justify-content:center;transform: scale(1.1);border: none;border-radius: 50%;background: conic-gradient(var(--cap-spinner-color) 0%, var(--cap-spinner-color) var(--progress, 0%), var(--cap-spinner-background-color) var(--progress, 0%), var(--cap-spinner-background-color) 100%);position: relative;}.captcha[data-state=verifying] .checkbox::after {content: "";background-color: var(--cap-background);width: calc(100% - var(--cap-spinner-thickness));height: calc(100% - var(--cap-spinner-thickness));border-radius: 50%;margin:calc(var(--cap-spinner-thickness) / 2)}.captcha[data-state=done] .checkbox{border:1px solid transparent;background-image:var(--cap-checkmark);background-size:cover}.captcha[data-state=error] .checkbox{border:1px solid transparent;background-image:var(--cap-error-cross);background-size:cover}.captcha[disabled]{ |
231 | 235 | cursor:not-allowed}.captcha[disabled][data-state=verifying]{cursor:progress}.captcha[disabled][data-state=done]{cursor:default}.captcha .credits{position:absolute;bottom:10px;right:10px;font-size:var(--cap-credits-font-size);color:var(--cap-color);opacity:var(--cap-opacity-hover)}.captcha .credits span{display:none;text-decoration:underline}.captcha .credits:hover span{display:inline-block}</style>`; |
232 | 236 |
|
|
276 | 280 | this.#div |
277 | 281 | .querySelector(".checkbox") |
278 | 282 | .style.setProperty("--progress", `${event.detail.progress}%`); |
279 | | - progressElement.innerText = `Verifying... ${event.detail.progress}%`; |
| 283 | + progressElement.innerText = `${this.getI18nText( |
| 284 | + "verifying-label", |
| 285 | + "Verifying..." |
| 286 | + )} ${event.detail.progress}%`; |
280 | 287 | } |
281 | 288 | this.executeAttributeCode("onprogress", event); |
282 | 289 | } |
283 | 290 |
|
284 | 291 | handleSolve(event) { |
285 | | - this.updateUI("done", "You're a human", true); |
| 292 | + this.updateUI("done", this.getI18nText("solved-label", "You're a human"), true); |
286 | 293 | this.executeAttributeCode("onsolve", event); |
287 | 294 | } |
288 | 295 |
|
289 | 296 | handleError(event) { |
290 | | - this.updateUI("error", "Error. Try again."); |
| 297 | + this.updateUI("error", this.getI18nText("error-label", "Error. Try again.")); |
291 | 298 | this.executeAttributeCode("onerror", event); |
292 | 299 | } |
293 | 300 |
|
294 | 301 | handleReset(event) { |
295 | | - this.updateUI("", "I'm a human"); |
| 302 | + this.updateUI("", this.getI18nText("initial-state", "I'm a human")); |
296 | 303 | this.executeAttributeCode("onreset", event); |
297 | 304 | } |
298 | 305 |
|
|
0 commit comments