Translate text in .val()

I have this line code:

$('#ss_account_submit').val('Create Account!');

So the .val() has a text within it. I wonder dow do I get to translate with qTranslate (WordPress plugin) a text within .js code like the line above:

Read More

The qTranslate allow to use quick shortcodes or regular shortcodes such as:

[:pt] For Brazilian Portuguese Language
[:en] For English Language
<!--:pt--><!--:--> For Brazilian Portuguese Language
<!--:en--><!--:--> For English Language

I tried a lot of things with my low knowledge in PHP/JS that didn’t work, such as:

$('#ss_account_submit').val('[:pt]Crie uma conta![:en]Create Account!');

$('#ss_account_submit').val('<--:pt-->Crie uma conta!<--:--><--:en-->Create Account!<--:pt-->');

$('#ss_account_submit').val __(('<--:pt-->Crie uma conta!<--:--><--:en-->Create Account!<--:pt-->'));

$('#ss_account_submit').val (<?php __('<--:pt-->Crie uma conta!<--:--><--:en-->Create Account!<--:pt-->') ?>);

Another way to make translation works is by using this kind of codes:

<?php echo __('<--:pt-->Crie uma conta!<--:--><--:en-->Create Account!<--:pt-->') ?>

OR

(__('[:pt]Crie uma conta![:en]Create Account!'))

Any idea what could work for this original line?

$('#ss_account_submit').val('Create Account!');

Related posts

Leave a Reply

2 comments

  1. Your formatting looks a little off. Have you tried:

    <?php _e("<!--:pt-->Crie uma conta<!--:--><!--:en-->Create Account<!--:-->"); ?>
    

    Note: that will not work inside a standard .js file.

  2. Though its very late. But I see none answered it the right way.

    When you are using _() or __() or gettext() or _e() or _x() or _ex() or _n() or _nx() methods you are supposed to enclose only a single language inside it. See the full guide of i18n

    What the below line means is:

    $('#ss_account_submit').val('<?php __('Create Account!')?>');
    
    

    It would add the val in the current language of the site when executed.

    You’d have to run a PoEdit on your template and get these lines with __() into the .po and translate them.

    Alternatively,

    You’d have to write conditional php section to select the right language.

            $lingo = qtrans_getLanguage();
            if ( 'en' == $lingo )
                echo "$('#ss_account_submit').val('Create Account!')";
            if ( 'pt' == $lingo )
                echo "$('#ss_account_submit').val('Crie uma conta!');";