php - 使用 <?php _e( 翻译 WordPress block

标签 php wordpress wordpress-theming gettext translate

我在我的 WordPress 主题中定制了一些 block 。我确实必须编辑 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 文件中?还是会自动添加?

谢谢:)

最佳答案

这是很好的代码(只需像这样插入 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

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

关于php - 使用 <?php _e( 翻译 WordPress block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36787516/

相关文章:

php - 服务器可以直接打客户端吗

php - 几次连接后mysql连接时间太长

php - 如何显示来自iOS编码的表情符号到php中?

css - 特定设备上页脚中的巨大白色区域

javascript - 从外部 URL 获取 URL 标题,无需加载整个网站

html - Wordpress 中的占位符图标 Contact Form 7

php - CakePHP:根据配置值全局更改所有模型的数据库连接

jquery - 在 chrome 上返回 AJAX 调用后,用于分页的 CSS 将无法工作

html - 如何仅在台式机/笔记本电脑上将 Rehub 主题中的主菜单居中?

wordpress - 带有子项列表(类别或页面)的自定义面包屑