Question

Current I have WP code like this. I need to make it translateable by poedit. How do I wrap the code to make it work? Im not sure which method is use for this case. Some thing like:

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

This is the code. I need to translate ["Sales amount"], ["Number of sales"]

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"] ));  }

Thank you for help

Was it helpful?

Solution

You have to use __('string','textdomain') to assign a translated string to some variable. And _e('string','textdomain') to echo a translated string. See I18n_for_WordPress_Developers.

Two observations:

$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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top