Jump to content

Recommended Posts

Posted

I have a javascript animation similar to this codepen here: https://codepen.io/Anthony-Osceola/pen/YPPXwJw
My version requires that the string is contained in a const variable. This is what I've tried:

.....
..........
const paragraphs = [
<?=__("Here is some text.")?>,
<?=__("Here is some more text")?>
];

function buildParagraph(text) {..........

While I've managed to translate the rest of the page, I'm having trouble getting text within javascript tags to work. They show in the admin but the translated text won't display for the JS animation. 

Would I be better off just creating another template for this translated page? I thought that doing so could be bad for SEO if it's counted as duplicate content. Any advice appreciated.
 

Posted

Well that was quick! 😅
Wrapping with json_encode() worked for me. Gsap text animation now works:

const paragraphs = [
<?=json_encode(__("Here is some text"))?>,
<?=json_encode(__("Here is some more text"))?>
];


 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...