Last active
August 29, 2015 14:27
-
-
Save ONTRAPORT-Frank/4bbc6ff6edad6904b17e to your computer and use it in GitHub Desktop.
ONTRAPORT Spanish Translation
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
/** | |
* @brief - ONTRAPORT Orderform Translation Script | |
* @author Ray Peters - <[email protected]> | |
*/ | |
;( function(){ | |
// TRANSLATION MAP | |
var TRANSLATIONS = { | |
"One-time payment of": "Pago por única vez de", | |
"monthly payments of": "pagos mensuales de", | |
"Item": "artículo", | |
"Payment Option": "Opciones De Pago", | |
"Today's Total": "Hoy total", | |
"Sub Total": "Subtotal", | |
"Enter Coupon Code": "Escribe Código De Cupón", | |
"Card Number": "Número De Tarjeta", | |
"Exp. Month": "Mes De Expiración", | |
"Exp. Year": "Vencimiento Año" | |
}; | |
// It's important to keep this one separate and small. This runs constantly looking for dynamic elements | |
// that get added to the page... such as error messages and tooltips, etc. | |
var ERROR_MESSAGE_TRANSLATIONS = { | |
"Please complete this mandatory field.": "Por favor, complete este campo obligatorio." | |
}; | |
// | |
// DO NOT EDIT ANYTHING BELOW THIS LINE | |
// | |
var waitForJquery = ( function() { | |
// Cache local reference to $( document ) | |
var $doc, | |
// Array of functions to execute after jQuery has loaded | |
fnCache = [], | |
// Collects functions inside the cache until jQuery is loaded | |
// and then gets overloaded to point to $( document ).ready | |
_handler = function( fn ) { | |
fnCache.push( fn ); | |
}; | |
function _poller(){ | |
if ( window.jQuery === undefined ) { | |
// Try again later | |
setTimeout( _poller, 50 ); | |
return; | |
} | |
// Cache a reference to the jQuery wrapped document | |
$doc = window.jQuery( document ); | |
// Overload the _handler function | |
_handler = $doc.ready; | |
// Attach all functions in the cache to the $( document ).ready handler | |
for ( var i = 0, l = fnCache.length; i < l; ++i ) { | |
_handler( fnCache.shift() ); | |
} | |
}; | |
// Activate the polling function | |
_poller(); | |
return function(){ | |
// Iterate over each argument | |
for ( var i = 0, l = arguments.length, arg; i < l; ++i ) { | |
arg = arguments[ i ]; | |
typeof arg === "function" && _handler( arg ); | |
} | |
}; | |
} )(); | |
waitForJquery( function(){ | |
$( document ).ready( function(){ | |
var translate = function( $elem, phraseMap ) { | |
var nodes = [], | |
root = $elem.get( 0 ), | |
node = root.childNodes[ 0 ], | |
whiteSpaceRegex = /\s{2,}/g; | |
// Collect all text nodes | |
while ( node != null ) { | |
if ( node.nodeType === 3 ) { | |
nodes.push( node ); | |
} | |
if ( node.hasChildNodes() ) { | |
node = node.firstChild; | |
} else { | |
while ( node != null && node.nextSibling == null && node != root ) { | |
node = node.parentNode; | |
} | |
node && ( node = node.nextSibling ); | |
} | |
} | |
var phrases = Object.keys( phraseMap ); | |
// Iterate through all text nodes | |
for ( var i = 0, l = nodes.length, j, k; i < l; ++i ) { | |
// Replace any of the translations | |
for ( j = 0, k = phrases.length; j < k; ++j ) { | |
nodes[ i ].nodeValue = nodes[ i ].nodeValue | |
.replace( whiteSpaceRegex, " " ) | |
.replace( phrases[ j ], phraseMap[ phrases[ j ] ] ); | |
} | |
} | |
}; | |
var translateElement = function( translateFn ) { | |
return function( elemSelector, phraseMap, alwaysOn ) { | |
// Cache some values | |
var updateAttempts = 0, | |
delayInterval = !alwaysOn ? 100 : 250; | |
setTimeout( function poller() { | |
var $elem, | |
continuePolling = false; | |
if ( !alwaysOn ) { | |
if ( ++updateAttempts > 250 ) { | |
return; | |
} | |
if ( ( updateAttempts % 25 ) === 0 ) { | |
delayInterval += 100; | |
} | |
} | |
$elem = $( elemSelector ); | |
if ( $elem.length === 0 ) { | |
continuePolling = true; | |
} else { | |
translate( $elem, phraseMap ); | |
} | |
if ( continuePolling || alwaysOn ) { | |
setTimeout( poller, delayInterval ); | |
} | |
}, delayInterval ); | |
}; | |
}( translate ); | |
// One time translations | |
translateElement( ".ontraport_grid_offer", TRANSLATIONS, false ); | |
translateElement( ".moonray-form-element-paymentmethod", TRANSLATIONS, false ); | |
// Dynamic translations for things like tooltips/popups | |
translateElement( "body > .moonray-form-error-message.moonray-form-state-error", ERROR_MESSAGE_TRANSLATIONS, true ); | |
} ); | |
} ); | |
} )(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ray Peters' translation script