• Resolved rigwald

    (@rigwald)


    I am using the Weglot plugin to translate our Woocommerce site Site Being Built. 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>

    Weglot support even had me add the following code snippet to try to exclude the script’s data from being translated.

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

    For some reason, the only data being translated is the product name. A member of Stack Overflow said that the script is related to WC_Structured_Data Class.

    Any thoughts on why that one item is being translated and how to exclude it (based on how Weglot allows you to exclude things from translation?

    Thanks in advance! ??

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Phil

    (@fullysupportedphil)

    Automattic Happiness Engineer

    Hey @rigwald,

    These forums are intended for support with the default functionality of WooCommerce, not for coding support or customizations. As such, there isn’t as much of a developer presence here.

    For this type of coding questions, you’re more likely to get input by asking in the WooCommerce Developer Slack or Advanced WooCommerce Facebook group. As those communities are both frequented by developers (including our own).

    Since you are already working with the developers of your translation plugin, I’d recommend pointing them to the developer slack community. If they find something that they believe to be a bug in WooCommerce, or something that would help to make WooCommerce more universally compatible – they can add that to the open source project here:
    https://github.com/woocommerce/woocommerce/issues

    I hope that helps to get them pointed in the right direction ??

    If Stack Overflow is correct and it’s the Structured Data, it looks like the product name is defined by $product->get_name() so the translation may be happening in the product class.

    You could try filtering woocommerce_structured_data_product to make the name $product->get_name('edit') which should (in theory) not pass through any filters.

    A snippet like this may help, but please know that I am just spitballing here:

    
    /**
     * Filter Product structured data.
     *
     * @param array      $markup The array of structured data.
     * @param WC_Product $product Product data (default: null).
     * @return array
     */
    function kia_woocommerce_structured_data_product( $markup, $product ) {
    	$markup['name'] = $product->get_name( 'edit' );
    }
    add_filter( 'woocommerce_structured_data_product', 'kia_woocommerce_structured_data_product', 10, 2 );
    
    Thread Starter rigwald

    (@rigwald)

    @helgatheviking

    Thank you for your reply (and I appreciate you trying). It worked at first, but I didn’t celebrate too soon. I tried going in and out of the page, turned translation on and off and eventually it was translated again when I viewed the page source.

    <script type="application/ld+json">{"@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 (Ozdoby Choinkowe)","@id":"https:\/\/store.dolina.org\/product-category\/christmas-ornaments-ozdoby-choinkowe\/"}},{"@type":"ListItem","position":3,"item":{"name":"Diamond Pendant","@id":"https:\/\/store.dolina.org\/product\/diamond-pendant\/"}}]}</script>
    <div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <script type="application/ld+json">{"@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 (Ozdoby Choinkowe)","@id":"https:\/\/store.dolina.org\/product-category\/christmas-ornaments-ozdoby-choinkowe\/"}},{"@type":"ListItem","position":3,"item":{"name":"Diamentowy wisiorek","@id":"https:\/\/store.dolina.org\/product\/diamond-pendant\/"}}]}</script>
    <div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    I haven’t gotten any replies on Slack, but I did receive a reply on the WordPress Stack Exchange that I forwarded to the plugin developer.

    You’re welcome. I did say it was just a guess. ?? I think you are out of my depth now as I’m not familiar with weglot at all. Good luck!

    Plugin Support Tseten a11n

    (@tibetanitech)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Woocommerce script causing issues with Weglot translation plugin’ is closed to new replies.