I'm translating the "days ago" text that appears in every activity stream. The format in Spanish won't be "# days ago" but rather "hace # días". It seems this can't be done with liquid replace filters, so I'm using javascript.
My Code:
$(window).load(function(){
$('.timeago').prepend('hace ');
$('.timeago').append('días');
$('.timeago').each(function(){
$(this).html($(this).html().split("days ago").join(""));
});
});
The problem:
While this code works for 60 seconds, the text then reverts to the original English. It seems this div refreshes every minute (presumably so someone who sits on that page for days on end will still see an up-to-date "days ago" count).
Question:
Question:
Is there a way to prevent the update from taking place every 60 seconds?
Alternatively, is there a way to run my translation function every minute when the "time ago" div updates?
Thanks a lot in advance.
Official response from Taylor Pineiro
Please see below!
Share this post
Showing 3 reactions
Sign in with
CampaignNOW - Advocacy tool for supporters to contact your campaign target
Freshhold Consulting
Code Nation
Code Nation
Certified Agency
Certified Architect
Certified Developer
$(window).load(function(){
$(‘.timeago’).prepend(‘hace ’);
$(’.timeago’).each(function(){
$(this).html($(this).html().split(“ago”).join(""));
$(this).html($(this).html().split("minute “).join(”minuto"));
$(this).html($(this).html().split("minutes “).join(”minutos"));
$(this).html($(this).html().split("hour “).join(”hora"));
$(this).html($(this).html().split("hours “).join(”horas"));
$(this).html($(this).html().split("day “).join(”día"));
$(this).html($(this).html().split("days “).join(”días"));
$(this).html($(this).html().split("month “).join(”mes"));
$(this).html($(this).html().split("months “).join(”meses"));
$(this).html($(this).html().split("year “).join(”año"));
$(this).html($(this).html().split("years “).join(”años"));
});
$(‘.timeago’).removeAttr(“title”);
});
CampaignNOW - Advocacy tool for supporters to contact your campaign target
Freshhold Consulting
Code Nation
Code Nation
Certified Agency
Certified Architect
Certified Developer
$(‘.timeago’).removeAttr(“title”);
That seems to allow the translated text to remain unchanged. Hope it’s useful to someone else too :)
Full code snippet:
$(window).load(function(){
$(‘.timeago’).prepend(‘hace ’);
$(’.timeago’).append(‘días’);
$(‘.timeago’).each(function(){
$(this).html($(this).html().split(“days ago”).join(""));
});
$(‘.timeago’).removeAttr(“title”);
});