April becomes Aprileeeeeeee

Questions & AnswersApril becomes Aprileeeeeeee
Benjamin asked 2 years ago

Hi team, 
I’m using the code in my SQSP site https://hotyogatrieste.com . I have inserted the additional footer code to change some hard coded text from ENG to ITA, mostly days and dates for blog posts.  All was well until April came.  All my months translate and display fine, but April comes up as Aprile at first and then ‘e’s keep being added at the end, without the page reloading, they just magically appear one after another, until it ends up as Aprileeeeeeee (roughly).  I’ve changed the code so April = April so if you go to the site now you won’t see the issue, but I’m happy to reimplement it for a time if someone needs to double check it.  Super weird…please help!
jQuery(‘a,time’).replaceText(/April/ig, “Aprile”);
Ben

1 Answers
Best Answer
Dave Hilditch Staff answered 2 years ago

Hah good one – it’s seeing April inside Aprile and changing it to Aprile therefore the word keeps growing in size…
To remedy this, alter your replace to the following which will ensure it matches a whole word only (puncuation or space before/after the word):
jQuery(‘a,time’).replaceText(/\bApril\b/ig, “Aprile”);
The \b means ‘word boundary’ so putting that before and after the word you are searching for ensures it only matches whole words and not part of a word.

Benjamin replied 2 years ago

Thanks Dave, that nailed it. I’ve added that adjustment to my previous post which contains my hard coded Italian footer thus far. Excellent product and service!