WC_STRUCTED_DATA类导致不必要的转换

时间:2020-08-07 作者:Kazimierz

我正在使用Weglot插件翻译我们的Woocommerce网站。Weglot允许您排除不希望翻译的区域,以从单词配额中节省。

Weglot说:

排除的块默认情况下,页面上的所有内容都会被翻译,但您可以通过输入要排除的CSS选择器或HTML块来排除页面的某个部分

我们已成功阻止所有包含产品名称/产品标题的内容,只有一个除外。正在运行的脚本包含产品名称/产品标题,Weglot正在翻译脚本中的数据,即使它没有显示出来。我与Weglot支持部门合作了大约一周,试图找出如何排除它,但没有任何效果。

根据Weglot所说的关于排除页面节的内容,您能想出一种方法来排除脚本吗?该脚本用于什么?如果它不重要,是否有方法删除它或它正在提取的产品名称/产品标题?

这是页面中的脚本。翻译的单词是:“Diamentowy wisiorek”(原“钻石吊坠”)

> <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>
我甚至尝试在我认为脚本被拉入页脚的地方添加。php。

   </div> <!-- Page end -->
   <div id="No-Translate-Scripts">
   <?php wp_footer(); ?>
    </div> 
</body>
</html>
到目前为止,我只在产品页面上注意到它。一位程序员说,该脚本是为WC\\u Structured\\u数据类编写的。关于脚本的来源或如何将其排除在外,您有什么想法吗?Weglot support让我添加了以下代码段,但没有成功:

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

1 个回复
SO网友:user192890

您可以更改文件/weglot/vendor/weglot/weglot-php/src/Parser/Check/RegexCheckerProvider中的行号103。php

原始代码:

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

/* Add JSON LD checker */
    $this->addChecker(new RegexChecker("#<script type=(\'|\\")application\\/ld\\+json(\'|\\")([^\\>]+?)?>(.*?)<\\/script>#s" , SourceType::SOURCE_JSON, 4 , array( "description" , "headline" , "articleSection"  )));
您必须使用FTP进行此更改,因为此文件位于供应商文件夹中。

最好的

相关推荐

从Yoast SEO中检索一个值,以用于设置默认的Twitter卡片图像以实现覆盖

所以Yoast SEO有一个问题,您无法定义全局默认的twitter卡图像。因此,我希望两者都设置一个默认的twitter卡图像,但允许在特定页面上的覆盖实际工作。我当前正在使用:$default_opengraph = \'https://website.com/image.png\'; function default_opengraph() { global $default_opengraph; return $default_opengraph; } ad