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

报告相同问题?

悬赏问题

  • ¥50 有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的
  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!