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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题