使用 php 个过滤器翻译 Wordpress(WooCommerce 插件)
Translating Wordpress (WooCommerce plugin) using php filters
我正在尝试使用 php 过滤器(add_filter() 函数)将我的 WooCommerce 页面翻译成我的母语。
我得到了一个示例,其中我获取了页面的一个钩子并使用它轻松地翻译了一个按钮,没有任何问题。
add_filter('ultimate_woocommerce_auction_bid_button_text', 'woo_custom_bid_button_text');
function woo_custom_bid_button_text() {
return __( 'Přihodit', 'woo_ua' );
}
"Přihodit" 是 "Place bid" 的母语翻译。
问题是当我想翻译 "Bid Value"
按钮前面的部分时
这是 WooCommerce 源代码:
<div class="quantity buttons_added">
<label for="uwa_your_bid"><?php _e('Bid Value', 'woo_ua') ?>:</label>
<input type="number" name="uwa_bid_value" data-auction-id="<?php echo esc_attr( $product_id ); ?>"
value=""min="<?php echo $product->woo_ua_bid_value() ?>"
step="any" size="<?php echo strlen($product->get_woo_ua_current_bid())+2 ?>" title="bid" class="input-text qty bid text left">
</div>
我已经尝试过使用与上面相同的方法:
add_filter('ultimate_woocommerce_auction_before_bid_button', 'woo_custom_text_before_bid_input'`enter code here`);
function woo_custom_text_before_bid_input() {
return _e('Příhoz', 'woo_ua');
}
但是我无法让它工作,因为没有特定的钩子可以使用。感谢任何提前的回复或解决方案。
你可以使用 gettext filter
add_filter( 'gettext', function( $translated_text, $text, $domain ){
if ( $text == 'Bid Value' )
$translated_text = 'Příhoz';
return $translated_text;
}, 10, 3 );
我正在尝试使用 php 过滤器(add_filter() 函数)将我的 WooCommerce 页面翻译成我的母语。 我得到了一个示例,其中我获取了页面的一个钩子并使用它轻松地翻译了一个按钮,没有任何问题。
add_filter('ultimate_woocommerce_auction_bid_button_text', 'woo_custom_bid_button_text');
function woo_custom_bid_button_text() {
return __( 'Přihodit', 'woo_ua' );
}
"Přihodit" 是 "Place bid" 的母语翻译。
问题是当我想翻译 "Bid Value"
按钮前面的部分时这是 WooCommerce 源代码:
<div class="quantity buttons_added">
<label for="uwa_your_bid"><?php _e('Bid Value', 'woo_ua') ?>:</label>
<input type="number" name="uwa_bid_value" data-auction-id="<?php echo esc_attr( $product_id ); ?>"
value=""min="<?php echo $product->woo_ua_bid_value() ?>"
step="any" size="<?php echo strlen($product->get_woo_ua_current_bid())+2 ?>" title="bid" class="input-text qty bid text left">
</div>
我已经尝试过使用与上面相同的方法:
add_filter('ultimate_woocommerce_auction_before_bid_button', 'woo_custom_text_before_bid_input'`enter code here`);
function woo_custom_text_before_bid_input() {
return _e('Příhoz', 'woo_ua');
}
但是我无法让它工作,因为没有特定的钩子可以使用。感谢任何提前的回复或解决方案。
你可以使用 gettext filter
add_filter( 'gettext', function( $translated_text, $text, $domain ){
if ( $text == 'Bid Value' )
$translated_text = 'Příhoz';
return $translated_text;
}, 10, 3 );