Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Last active August 29, 2017 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salsalabs/dbe8fe77f10955d36d166b61abed14f7 to your computer and use it in GitHub Desktop.
Save salsalabs/dbe8fe77f10955d36d166b61abed14f7 to your computer and use it in GitHub Desktop.
Scripts to translate miscellaneous Spanish phrases to English in Salsa pages. This is a workaround until Salsa modifies the translation tables.
<!-- Spanish version of the recurring "what is this" text. Steps to install:
1. Create a blank template.
2. Create a custom content page.
3. Assign the blank template to the custom content page.
4. Put the translated text (below) into the custom content page.
5. Modify the onclick script for the "What's this" link to remove the current popup page and replace it with the custom content page.
-->
<p><style type="text/css">
body, font, td {font-family : verdana, arial, sans-serif; font-size : 11px; line-height: 13px;}
</style></p>
<table width="450" cellspacing="5" cellpadding="2" border="0">
<tbody>
<tr>
<td>
<div align="right"><a href="javascript:close()">Cierra esta ventana</a></div>
<br />
<b>Contribución recurrente</b><br />
<p>Al elegir hacer una contribución recurrente, te estás registrando para hacer una donación con tu tarjeta de crédito una vez al mes, una vez cada tres meses, una vez cada seis meses o una vez al año. Tras tu primera donación, las donaciones futuras se realizarán de forma automática. Por ejemplo, si eliges hacer una contribución recurrente mensual de $10.00, tu próxima donación de $10.00 se cargará automáticamente en tu cuenta bancaria dentro de un mes.</p>
<p></p>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
(function() {
// Script to translate English phrases to Spanish in Salsa pages.
// Function to translate field names in an error block.
function translateErrors() {
var error = document.querySelectorAll('.error');
if (error.length != 0) {
var newOhNo = "Vaya, parece que ha habido un problema con los datos de pago. Por favor, revisa tus datos personales y la información de pago e inténtalo de nuevo.";
var phrases = {
"A credit card number": "Número de Tarjeta",
Country: "País",
"A CVV2 code": "Código de seguridad",
"Please provide a valid Email address[\.]*": "Introduce una dirección de correo electrónico válida",
Email: "Correo electrónico",
State: "Estado",
"is required[\.]*": "requerido"
}
Array.from(error).forEach(function(e) {
var text = e.innerHTML;
for (var key in phrases) {
text = text.replace(RegExp(key, "gmi"), phrases[key]);
}
e.innerHTML = text;
});
}
}
// Function to translate donation page phrases.
function translateDonationFields() {
$('#donation_pay_periods option').each(function(){
return $(this).html((function(){
switch ($(this).val()) {
case 'MONT': return 'Mensual';
case 'WEEK': return 'Semanal';
case 'QTER': return 'Trimestral';
case 'SMYR': return 'Semestral';
case 'YEAR': return 'Anual';
}
}.call(this)));
});
$('option:contains("Unlimited")').html('ilimitado');
var e = $('label:contains("Recurring contribution")');
if (e.length > 0) {
e.html(e.html().replace('Recurring contribution', 'Contribución recurrente'));
}
$('label:contains("Comments")').text('Comentarios');
$('#recurring_options label:contains("for")').remove();
$("#honorof legend").html("Esta donación es...");
$('label[for="currency"]').html('Por favor elige una moneda:');
}
// Script to change the URL for the "What is this" popup to a Spanish
// version kindly provided by the amazing Alba Sanchez.
// TODO: You must replace the URL in "replace" with a URL from your Salsa HQ!
function fixRecurringWhatIsThis() {
var replacement = "http://salsa4.salsalabs.com/o/50748/p/salsa/web/common/public/content?content_item_KEY=15233";
var onclick = function() { window.open(replacement, 'pop1', 'toolbar=no,menubar=no,scrollbars=no,,width=500,height=200');};
$("a.link-help").unbind('click').removeAttr('onclick').click(onclick);
}
// Translate the "Oh, no" message to Spanish. Note that the the list of error fields gets
// removed -- no one wants it.
function translateOhNo() {
var translation = "Vaya, parece que ha habido un problema con los datos de pago. Por favor, revisa tus datos personales y la información de pago e inténtalo de nuevo."
var e= $('.error');
if (e.length > 0 && e.html().indexOf("Oh no") != -1) {
e.html(translation);
}
}
// Handle a page.
$(document).ready(function () {
if (document.location.href.indexOf('/l/spa/') != -1) {
fixRecurringWhatIsThis();
translateDonationFields();
translateErrors();
translateOhNo();
}
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment