marcAntoine
marcAntoine

Reputation: 678

Using translation with jquery in prestashop

I'm trying to translate some terms when I'm using jQuery inside a smarty file. This is my jQuery code:

else {
    $("#message").val("{l s='Please try to be clear.'}");

This phrase appears exactly as {l s='Please try to be clear.'} in my web page and doesn't take into consideration the translation mode.

I know that i can use js=1 when i'm inside a javascript code but it doesn't work for me neither. Does anyone have an idea about how to use the translation in a jQuery function?

Upvotes: 0

Views: 2035

Answers (2)

gskema
gskema

Reputation: 3221

It's good practice to use {literal} tags around JS blocks:

{literal}
<script>
/...
</script>
{/literal}

But when you need to insert some smarty into JS block, it won't work; To make it work you have to do the close and reopen tags (looks like a little bit of a hack :)

{literal}
<script>
   var txt = '{/literal}{l s='Some text'}{literal}'
</script>
{/literal}

Also in PrestaShop templates you'll find;

{strip}
{addJsDefL name=translation_6}{l s='Not found' js=1}{/addJsDefL}
{/strip}

Which will create

var translation_6 = 'Not found';

in your body, which will you be able to use

Upvotes: 1

Maxim Lazarev
Maxim Lazarev

Reputation: 1254

Maybe enclosing your JS script in literal will help:

{literal}

//JS code

{/literal}

Upvotes: 1

Related Questions