【问题标题】:Translate Wordpress block with <?php _e(使用 <?php _e( 翻译 Wordpress 块
【发布时间】:2016-08-15 17:05:39
【问题描述】:

我在我的 wordpress 主题中做了一些自定义块。我确实必须编辑 shortcode.php 文件以添加价格表。我刚刚意识到的是,我需要通过我的主题的 .po 文件翻译这些词( From 、 /DAY 、 Book )。所以我尝试添加这一行来替换单词(例如“From”)。但是我有一个错误代码,我想我这里没有一个好的语法但找不到正确的。你能帮我吗?

这是原始代码

/*CUSTOM PRICE*/

}elseif($type === 'content_block_custom_price'){

$result = '<div class="featurecustom text-center">';

$result .=  '<div class="thumbnail">
              <img src="'.AUTORENT_IMAGE.''.$img.'" alt="">

             </div>

            <p class="titlecustom">'.$title.'</p> 
            <p class="fromprice"> From</p>           
            <span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="fromprice">/ DAY</span>  
            <hr>        
            <p class="customdescription">'.$des.'</p>

            <a href="'.$linktypebutton.'"> <div class="bookingbutton" style="vertical-align:middle"><span>BOOK </span></div> </a>

            ';

$result .= '</div>';


return $result;

/* CUSTOM PRICE*/

这是我试图翻译的错误代码

/*CUSTOM PRICE*/

}elseif($type === 'content_block_custom_price'){

$result = '<div class="featurecustom text-center">';

$result .=  '<div class="thumbnail">
              <img src="'.AUTORENT_IMAGE.''.$img.'" alt="">

             </div>

            <p class="titlecustom">'.$title.'</p> 
            <p class="fromprice"> <?php _e('From','themename'); ?></p>           
            <span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="fromprice"><?php _e('/DAY','themename'); ?></span>  
            <hr>        
            <p class="customdescription">'.$des.'</p>

            <a href="'.$linktypebutton.'"> <div class="bookingbutton" style="vertical-align:middle"><span><?php _e('Book','themename'); ?> </span></div> </a>

            ';

$result .= '</div>';


return $result;

/* CUSTOM PRICE*/

发布已解决的问题:一个我有新条目,例如“Book”、“FROM”和“/DAY”,我想我必须将它们创建到 poedit 文件中?还是会自动添加?

谢谢:)

【问题讨论】:

    标签: php wordpress wordpress-theming gettext translate


    【解决方案1】:

    这是好的代码(只需像这样插入gettex '. __("From","theme name").'

    /*CUSTOM PRICE*/
    
    }elseif($type === 'content_block_custom_price'){
    
    $result = '<div class="featurecustom text-center">';
    
    $result .=  '<div class="thumbnail">
                  <img src="'.AUTORENT_IMAGE.''.$img.'" alt="">
    
                 </div>
    
                <p class="titlecustom">'.$title.'</p> 
                <p class="fromprice"> '. __("From","theme name").'</p>           
                <span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="from price">'. __("/DAY","theme name") .'</span>  
                <hr>        
                <p class="customdescription">'.$des.'</p>
    
                <a href="'.$linktypebutton.'"> <div class="bookingbutton" style="vertical-align:middle"><span>'. __("Book","themename"); .' </span></div> </a>
    
                ';
    
    $result .= '</div>';
    
    
    return $result;
    
    /* CUSTOM PRICE*/
    

    对于主题和插件的翻译,有一个非常有效且简单的免费插件:Loco Translate

    此插件将扫描您的主题以查找要翻译的新项目……

    【讨论】:

    • 您好!感谢您的代码!当我为“FROM”添加此代码时

      '。 _e("From","theme name").'

      ,我有在块外多次显示的“from”单词,例如“fromfromfromfrom”
    • 尝试使用__("From","theme name"); 而不是_e(
    • 哈哈它的工作原理,你能解释一下_e(和__之间有什么区别
    • _e( 就像echo __(,但在这里你不需要回显,你只需要插入:)… 当' 已经用于插入时,不要使用'. __('From','theme name').'… 改用"。我将更新代码,以便其他可以看到这个问题/答案的人......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2015-02-14
    相关资源
    最近更新 更多