We translated our WooCommerce store via Weglot and everything worked fine. Unfortunately, some words on the home page were not translated.
It is the section on the home page where the categories are displayed inside the image. The names of the categories even actually have a DIV with class and still it is not recognized by Weglot:
<div >Kleider</div>
According to the HTML source code, the strings of the titles are not directly included in the code.
So I tried an official hook from Weglot (https://developers.weglot.com/wordpress/filters/translations-filters), which didn't help. That's the code I inserted in the functions.php:
<?php
add_filter( 'weglot_get_dom_checkers', 'custom_weglot_dom_check' );
function custom_weglot_dom_check( $dom_checkers ) { //$dom_checkers contains the
list of all the class we are checking by default
class Div_Slide_Title extends Weglot\Parser\Check\Dom\AbstractDomChecker {
const DOM = 'div'; //Type of tag you want to detect // CSS Selector
const PROPERTY = 'v-if'; //Name of the attribute in that tag uou want to detect
const WORD_TYPE = Weglot\Client\Api\Enum\WordType::TEXT; //Do not change unless it's not text but a media URL like a .pdf file for example.
}
$dom_checkers[] = '\Div_Slide_Title'; //You add your class to the list because you want the parser to also detect it
return $dom_checkers ;
}
Unfortunately, I don't have any other solution. Can someone here maybe help me?
Many thanks in advance.
CodePudding user response:
hope you're fine? I'm Edson from weglot. Sorry for the issue you're facing. You want to translate the word Kleider. The problem is that the attribute v-if you try to translate don't contain the word but a shortcode who's may be transform via js or ajax. You've to find where the word are store on your source code to translate them.
May you have an url of your page I can see to help you ?
Regards Edson
CodePudding user response:
thank you very much for your answer! I had already linked the store above at "Woocommerce Store". Here again the link:
We would like to translate not only the word "Kleider" but also all other categories. You can find the 5 categories right after the header under the title "Shop".
Regards, Anil
CodePudding user response:
thanks for your reply. Your categories are load via this url : https://ayen-label.com/en/wp-json/posts-grid-builder/v1/taxonomy-terms/?taxonomy=any&include=68,78,46,49,166&thumbnail_size=full&items_type=default
By default all the key from a json are not translate by weglot but with this filter it should works :
add_filter( 'weglot_add_json_keys', 'custom_weglot_add_json_keys' );
function custom_weglot_add_json_keys( $keys ){ //$keys already contains "name" and "description"
$keys[] = 'term_title';
$keys[] = 'term_slug';
$keys[] = 'message';
$keys[] = 'term_taxonomy';
return $keys;
}
Hope it's help Regards