Home›Support›English Support›[Waiting for user confirmation] Feature request: translation estimate report
[Waiting for user confirmation] Feature request: translation estimate report
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Our wait time is higher than usual, please make sure you are meeting the minimum requirement - https://wpml.org/home/minimum-requirements before you report issues, and if you can take a look at current Known Issues - https://wpml.org/known-issues/. Thank you.
Background of the issue:
I am a web designer and I would like to be able to create a CSV file with an estimate of the number of words that needs to be translated, so I can send it to the customer for approval. At the moment I create a screenshot (attached) with the Word count from the Translation Dashboard, but that sometimes needs multiple screenshots from multiple sections and that looks unprofessional.
I would like the report to have a list with the following columns, example attached:
- selected item
- item type (ie each page)
- the word count of the item
I want this to be in a CSV file, so I can use it in Excel to add a calculations of the expected costs for each language (depending on the translation engine or translation service).
Symptoms:
There is no direct feature in WPML to generate a CSV file with word count estimates for translation.
Questions:
How can I generate a CSV file with a list of selected items, item types, and word counts for translation estimates?
Our second-tier supporter suggests the following: You can write simple PHP code that will take the value of ID, Title, and the number of words in the post meta _wpml_word_count and output it to a CSV file. Here is a sample code generated by ChatGPT.
function export_word_count_to_csv() {
// Adjust your query args as needed
$args = array(
'post_type' => 'post', // Change to your desired post type
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'ASC',
);
$query = new WP_Query($args);
if ($query->have_posts()) {
// Set headers to force download CSV
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=word-count-export.csv');
$output = fopen('<em><u>hidden link</u></em>', 'w');
// Output header row
fputcsv($output, array('ID', 'Title', 'Word Count'));
// Loop through posts
while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
$title = get_the_title();
$word_count = get_post_meta($post_id, '_wpml_word_count', true);
// If no value, fallback to 0
if (!$word_count) {
$word_count = 0;
}
fputcsv($output, array($post_id, $title, $word_count));
}
fclose($output);
exit; // stop script after CSV output
} else {
echo 'No posts found.';
}
wp_reset_postdata();
}
// You can call this function via a custom admin page, WP-CLI command,
// or hook it to an action like 'init' with a conditional check for a URL param
// Example: <em><u>hidden link</u></em>
add_action('init', function () {
if (is_admin() || !isset($_GET['export_word_count'])) {
return;
}
export_word_count_to_csv();
});
The following are the steps you need to follow.
1. Add this code to your theme's functions.php file or in a custom plugin.
2. Visit your site with the ?export_word_count=1 query string in the URL (e.g., hidden link).
3. A CSV download should start with the structure:
I tried it on my test, and it works for posts.
Please note that you may need to add other post types to adjust it to your needs.