我正在尝试将 Woocommerce 产品排序从原始英文版本翻译为我国的语言。
不幸的是,它只能部分工作,“排序依据”文本无法翻译。
我认为最好的选择是,我决定使用 Avada 主题中的
functions.php
文件来编辑文本。
正如我提到的,即使我使用相同的方法,也只有一部分工作代码(您可以在下面找到它)。
function woosuite_change_cart_totals_text( $translated_text, $text, $domain ) {
if ( $text === 'Default Order' ) {
$translated_text = 'Výchozí';
}
if ( $text === 'Name' ) {
$translated_text = 'Jméno';
}
if ( $text === 'Popularity' ) {
$translated_text = 'Oblíbené';
}
if ( $text === 'Sort by ' ) {
$translated_text = 'Řadit dle ';
}
return $translated_text;
}
add_filter( 'gettext', 'woosuite_change_cart_totals_text', 20, 3 );
在此屏幕截图中可以看到此后翻译的内容。文本“排序依据”包含一个空格,但我试图在没有空格的情况下进行更改,但仍然无法正常工作。它将翻译所有内容,而无需文本“排序依据”。
我尝试过的另一种尝试也在下面(也不起作用):
add_filter('woocommerce_catalog_orderby', 'wc_customize_product_sorting');
function wc_customize_product_sorting($sorting_options){
$sorting_options = array(
'menu_order' => __( 'Řazení', 'woocommerce' ),
'popularity' => __( 'Oblíbenost', 'woocommerce' ),
'price' => __( 'Cena: od nejnižší', 'woocommerce' ),
'price-desc' => __( 'Cena: od nejvyšší', 'woocommerce' ),
);
return $sorting_options;
}
相同的情况与显示的产品编号(分页)。
感谢您的帮助!
您可以使用以下代码替换来翻译排序选项:
add_filter( 'woocommerce_catalog_orderby', 'translate_catalog_orderby_strings' );
function translate_catalog_orderby_strings( $orderby ) {
$orderby['menu_order'] = 'Výchozí řazení'; // 'Default sorting'
$orderby['popularity'] = 'Řadit dle oblíbené'; // 'Sort by popularity'
$orderby['rating'] = 'Řadit dle průměrné hodnocení'; // 'Sort by average rating'
$orderby['date'] = 'Řadit dle nejnovější'; // 'Sort by latest'
$orderby['price'] = 'Řadit dle cena: nízká až vysoká'; // 'Sort by price: low to high'
$orderby['price-desc'] = 'Řadit dle cena: vysoká až nízká'; // 'Sort by price: high to low'
return $orderby;
}
代码位于子主题的functions.php 文件中(或插件中)。已测试并有效。