用WordPress / poedit包装代码翻译?

时间:2013-09-17 15:00:40

标签: wordpress poedit

目前我有这样的WP代码。我需要通过poedit进行翻译。如何包装代码以使其工作?我不确定在这种情况下使用哪种方法。有点像:

<?php my_e( 'Total sales' ); ?> or __('Total sales', 'my')

这是代码。我需要翻译[“销售额”],[“销售数量”]

foreach ($results as $result) {
$date = $result->formatted_post_date;
$statistics[$date]["Sales amount"] += $wp_list_table->column_total_sales($result->ID);
$statistics[$date]["Number of sales"]++;
$statistics[$date]["date"] = $date;
$max_number_of_sales = max(array($max_number_of_sales,$statistics[$date]["Number of sales"] ));  }

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您必须使用__('string','textdomain')将已翻译的字符串分配给某个变量。并_e('string','textdomain')回显已翻译的字符串。请参阅I18n_for_WordPress_Developers

两个观察结果:

$sales_amount = 0;
$sales_number = 0;
foreach ($results as $result) {
    $sales_amount += $wp_list_table->column_total_sales($result->ID);
    $sales_number++;
    $date = $result->formatted_post_date;
    $statistics[$date]["sales_amount"] = $sales_amount;
    $statistics[$date]["sales_number"] = $sales_number;
}
echo __( 'Sales Amount', 'my' ) . $sales_amount;