donglan6967 2019-05-22 06:55
浏览 115
已采纳

使用php过滤器翻译Wordpress(WooCommerce插件)

I am trying to translate my WooCommerce page to my native language using php filterss (add_filter() function). I got one example where I took a hook of the page and used it to easily translate a button without any issue.

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" is a translation to my native language of "Place bid".

Problem is when I want to translate part right in front of the button which says "Bid Value"

This is WooCommerce source code:

            <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>

I have already tried using same method as I used above:

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');
}

But I cant get this to work since theres not a specific hook to use. Thanks to any replies or solutions in advance.

  • 写回答

1条回答 默认 最新

  • dongpengqin3898 2019-05-22 07:14
    关注

    You could use gettext filter

    add_filter( 'gettext', function( $translated_text, $text, $domain ){
    
        if ( $text == 'Bid Value' )
            $translated_text = 'Příhoz';
    
        return $translated_text;
    
    }, 10, 3 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?