我已经能够使用下面的代码翻译网站上的大部分内容,但不能翻译 3 个字段。
“美元” “/月” “/月 1 个月”。
我想让它说一些不同的东西,这样以后翻译起来会更容易。
function wc_billing_field_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case '/ Month' :
$translated_text = __( 'Monthly-Cycle', 'woocommerce' );
break;
case '/ Month for 1 Month For' :
$translated_text = __( 'Monthly-Cycle for a Month', 'woocommerce' );
break;
case 'USD' :
$translated_text = __( 'US-Dollar', 'woocommerce' );
break;
case 'First renewal' :
$translated_text = __( 'First-Cycle', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );
最好尝试使用以下内容:
add_filter( 'woocommerce_subscriptions_product_price_string', 'subscr_price_string_replacement', 10 );
add_filter( 'woocommerce_subscription_price_string', 'subscr_price_string_replacement', 10 );
function subscr_price_string_replacement( $price_string ){
$original_string1 = "/ Month for 1 Month For";
$original_string2 = "/ Month";
$original_string3 = "USD";
if ( strpos($subscription_string, $original_string1) !== false ) {
$replacement_string = __( "Monthly-Cycle for a Month", 'woocommerce' );
$price_string = str_replace( $original_string1, $replacement_string, $subscription_string );
}
if ( strpos($subscription_string, $original_string2) !== false ) {
$replacement_string = __( "Monthly-Cycle", 'woocommerce' );
$price_string = str_replace( $original_string2, $replacement_string, $subscription_string );
}
if ( strpos($subscription_string, $original_string3) !== false ) {
$replacement_string = __( "US-Dollar", 'woocommerce' );
$price_string = str_replace( $original_string3, $replacement_string, $subscription_string );
}
return $price_string;
}
对于“第一次续订”字符串更好地使用:
add_filter( 'gettext', 'subscr_string_replacement', 20, 3 );
function subscr_string_replacement( $translated_text, $original_text, $domain ) {
if ( $original_text === 'First renewal: %s' ) {
$translated_text = __( 'First-Cycle: %s', 'woocommerce' );
}
return $translated_text;
}
代码位于子主题的functions.php 文件中(或插件中)。应该可以。