• Resolved michalrama

    (@michalrama)


    Hello,

    I’m solving a problem with disabling text translation. As I found on the plugin forum, just add the notranslate class to the element.

    However, I add the title and tagline of the site using a theme, so I have to add the class using code.

    $("div.site-info-wrap").children().addClass("notranslate");

    The problem is, what if I want to translate only part of the text? The content of the page can be edited as HTML, I could split the text there, but it doesn’t work for the header.

    Please help.

    Thank you

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author edo888

    (@edo888)

    Hi,

    You can wrap the text which you do not want to be translated inside some HTML element with notranslate class. There is no need to use javascript. Here is an example:

    Long text with a lot of information.

    Long text with <span class="notranslate">a lot of information.</span>

    This will make sure that “a lot of information.” is not translated.

    Thanks! ??

    Thread Starter michalrama

    (@michalrama)

    Hello @edo888 ,

    I apologize for the delayed response. The theme allows you to put only text in the header, no html elements (probably no theme allows it)

    That’s why you have to do it with code. I found a solution by deleting the part of the text I didn’t want to translate and using this code.

    $("p.site-description").append($('<span />').addClass('notranslate').html(' \"no translate text\"'));

    The problem is that with this procedure, the text isn’t complete there for a fraction of a second (if you don’t have super fast internet, you can’t miss it)

    It would be better to write the whole text and use JS to paste part of it into the span with the required class. This would make the text complete when the page loads. But I don’t know exactly how to do it. Probably using the replace function, but I couldn’t write it correctly.

    Please help

    Thank you

    Plugin Author edo888

    (@edo888)

    Hi,

    I believe the best way is to modify your theme files if you have no way to do a direct input through web interface.

    If you use our paid version our live chat agents can configure it for you from our GTranslate user dashboard, which has more flexible options for skipping text: https://gtranslate.io/#pricing

    Thanks! ??

    Thread Starter michalrama

    (@michalrama)

    Hello,

    Again, I apologize for the late reply.

    I’ve already solved it. Thank you anyway.

    var text = $("p.site-description").html();
    var re = new RegExp(text.substr(text.indexOf('\"') - 1));
    var new_text = text.replace(re, '<span class="notranslate">$&</span>')
    $("p.site-description").html(new_text);
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to disable translation of only part of an element?’ is closed to new replies.