Created
December 16, 2025 13:03
-
-
Save saifsultanc/10e6314050de52df4683dbefbfa52bfa to your computer and use it in GitHub Desktop.
gpqr-translate-qr-scanner-spanish.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Gravity Perks // GP QR Code // Translate QR Scanner Interface to Spanish | |
| * https://gravitywiz.com/documentation/gravity-forms-qr-code/ | |
| * | |
| * Instructions: | |
| * | |
| * 1. Install this snippet with our free Custom JavaScript plugin. | |
| * https://gravitywiz.com/gravity-forms-code-chest/ | |
| */ | |
| ( function( $ ) { | |
| const translations = new Map([ | |
| ["Request Camera Permissions", "Solicitar permisos de cámara"], | |
| ["Requesting camera permissions...", "Solicitando permisos de cámara..."], | |
| ["No camera found", "No se encontró ninguna cámara"], | |
| ["Stop Scanning", "Detener escaneo"], | |
| ["Start Scanning", "Iniciar escaneo"], | |
| ["Scan an Image File", "Escanear un archivo de imagen"], | |
| ["Scan using camera directly", "Escanear usando la cámara directamente"], | |
| ["Choose Image", "Elegir imagen"], | |
| ["Choose Another", "Elegir otra"], | |
| ["No image choosen", "Ninguna imagen seleccionada"], | |
| ["Or drop an image to scan", "O arrastra una imagen para escanear"], | |
| ["Camera based scan", "Escaneo basado en cámara"], | |
| ["Fule based scan", "Escaneo basado en archivo"], | |
| ["Powered by ", "Desarrollado por "], | |
| ["Report issues", "Informar de problemas"], | |
| ["Camera access is only supported in secure context like https or localhost.", "El acceso a la cámara solo está disponible en un entorno seguro como HTTPS o localhost."] | |
| ]); | |
| /** | |
| * Translate text inside a node | |
| */ | |
| function translateNode( node ) { | |
| // Text nodes | |
| if ( node.nodeType === Node.TEXT_NODE ) { | |
| const text = node.nodeValue.trim(); | |
| if ( translations.has( text ) ) { | |
| node.nodeValue = node.nodeValue.replace( text, translations.get( text ) ); | |
| } | |
| return; | |
| } | |
| if ( node.nodeType !== Node.ELEMENT_NODE ) { | |
| return; | |
| } | |
| // Translate common attributes | |
| ["placeholder", "aria-label", "title", "value"].forEach( attr => { | |
| if ( node.hasAttribute && node.hasAttribute( attr ) ) { | |
| const value = node.getAttribute( attr ); | |
| if ( translations.has( value ) ) { | |
| node.setAttribute( attr, translations.get( value ) ); | |
| } | |
| } | |
| }); | |
| // Translate direct text content (buttons, spans, divs) | |
| if ( node.childNodes && node.childNodes.length ) { | |
| node.childNodes.forEach( child => translateNode( child ) ); | |
| } | |
| } | |
| /** | |
| * Run translation on existing DOM | |
| */ | |
| function translateExistingDOM() { | |
| translateNode( document.body ); | |
| } | |
| /** | |
| * Observe dynamically added elements | |
| */ | |
| function observeDOM() { | |
| const observer = new MutationObserver( mutations => { | |
| mutations.forEach( mutation => { | |
| mutation.addedNodes.forEach( node => translateNode( node ) ); | |
| }); | |
| }); | |
| observer.observe( document.body, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| } | |
| /** | |
| * Init (works for Gravity Forms + dynamic popups) | |
| */ | |
| function initTranslator() { | |
| translateExistingDOM(); | |
| observeDOM(); | |
| } | |
| initTranslator(); | |
| }( jQuery )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment