0

I am using the Weglot plugin to translate our Woocommerce site. Weglot allows you to exclude areas that you don’t want translated, to save from your quota of words.

Weglot says:

Excluded Blocks By default, everything is translated on a page but you can exclude a section of a page by entering the CSS selector or HTML block you want to exclude.

We have successfully blocked everything containing the product name/product title EXCEPT one thing. There is a script running that contains the product name/product title and Weglot is translating the data in the script, even though it is not displayed. I have been working with Weglot support for about a week trying to figure out how to exclude it, but nothing has worked. 🙁

Based on what Weglot said about, about excluding page sections, can you figure out a way to make the script able to be excluded? What is that script for and, if it isn’t important, is there a way to remove it or the product name/product title that it is pulling?

Here is the script from the page. The translated words are: “Diamentowy wisiorek” (originally “Diamond Pendant“)

> <script
> type="application/ld+json">{"@context":"https:\/\/schema.org\/","@graph":[{"@context":"https:\/\/schema.org\/","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"name":"Strona
> g\u0142\u00f3wna","@id":"https:\/\/store.dolina.org"}},{"@type":"ListItem","position":2,"item":{"name":"Christmas
> Ornaments (Bombki
> Choinkowe)","@id":"https:\/\/store.dolina.org\/product-category\/christmas-ornaments-bombki-choinkowe\/"}},{"@type":"ListItem","position":3,"item":{"name":"Diamentowy
> wisiorek","@id":"https:\/\/store.dolina.org\/product\/diamond-pendant\/"}}]},{"@context":"https:\/\/schema.org\/","@type":"Product","@id":"https:\/\/store.dolina.org\/product\/diamond-pendant\/#product","name":"Diamentowy
> wisiorek","url":"https:\/\/store.dolina.org\/product\/diamond-pendant\/","description":"Kr\u00f3tki
> opis","image":"https:\/\/store.dolina.org\/wp-content\/uploads\/2016\/02\/jewelry.jpg","sku":213,"offers":[{"@type":"Offer","price":"250.00","priceValidUntil":"2021-12-31","priceSpecification":{"price":"250.00","priceCurrency":"USD","valueAddedTaxIncluded":"false"},"priceCurrency":"USD","availability":"http:\/\/schema.org\/InStock","url":"https:\/\/store.dolina.org\/product\/diamond-pendant\/","seller":{"@type":"Organization","name":"Sklep
> wysy\u0142kowy Zespo\u0142u Pie\u015bni i Ta\u0144ca
> Dolina","url":"https:\/\/store.dolina.org"}}],"aggregateRating":{"@type":"AggregateRating","ratingValue":"4.00","reviewCount":1},"review":[{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":{"@type":"Person","name":"storesklep"},"reviewBody":"This
> is a test","datePublished":"2020-08-03T14:50:53-06:00"}]}]}</script>

I even tried adding around where I thought the scripts were being pulled in footer.php.

   </div> <!-- Page end -->
   <div id="No-Translate-Scripts">
   <?php wp_footer(); ?>
    </div> 
</body>
</html>

So far, I have only noticed it on the product page. A programmer said the script is for WC_Structured_Data Class. Any thoughts about where the script is coming from or how to get it excluded? Weglot support had me add the following code snippet, but it didn't work:

add_filter( 'weglot_add_json_keys',  'custom_weglot_add_json_keys' );
function custom_weglot_add_json_keys(  $keys  ){ 
    $keys  =  array('desc');
    return $keys;
}
0

You can change the line number 103 in the file /weglot/vendor/weglot/weglot-php/src/Parser/Check/RegexCheckerProvider.php

original code :

/* Add JSON LD checker */
    $this->addChecker(new RegexChecker("#<script type=('|\")application\/ld\+json('|\")([^\>]+?)?>(.*?)<\/script>#s" , SourceType::SOURCE_JSON, 4 , array( "description" ,  "name" , "headline" , "articleSection"  )));

To replace by :

/* Add JSON LD checker */
    $this->addChecker(new RegexChecker("#<script type=('|\")application\/ld\+json('|\")([^\>]+?)?>(.*?)<\/script>#s" , SourceType::SOURCE_JSON, 4 , array( "description" , "headline" , "articleSection"  )));

You must use FTP to make this change because this file is in a vendor folder.

Best

3
  • Merci! Just for clarification, I'll need to download the file via cPanel, edit it, and then send it back to the folder? (Sorry, I'm a trial and error person who has no coding / web training. Just naturally techie.)
    – Kazimierz
    Aug 10 '20 at 15:07
  • Merci! Ok, I went into cPanel, made a backup copy of the file and then replaced the line you suggested. It worked until I clicked on the "Reviews" tab (Translated as "Recenzja"). When I did that and reloaded the translated page, it translated it again. :(
    – Kazimierz
    Aug 10 '20 at 15:43
  • I tried with another browser and it translated it even without click on the reviews tab, so that might have just been a coincidence.
    – Kazimierz
    Aug 10 '20 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.