Skip Navigation

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.

Sun Mon Tue Wed Thu Fri Sat
10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 - -
16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 - -

Supporter timezone: Asia/Jerusalem (GMT+03:00)

This topic contains 0 replies, has 1 voice.

Last updated by Itamar 1 week ago.

Assisted by: Itamar.

Author Posts
March 25, 2025 at 11:55 am #16857178

John-Pierre Cornelissen

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?

» Feature request

March 27, 2025 at 9:13 am #16866986

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I've passed on your request to our second-tier supporters. When I have their reply, I'll update you.

I appreciate your patience.
Itamar.

March 30, 2025 at 2:21 pm #16876645

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

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.

Regards,
Itamar.

April 2, 2025 at 8:12 am #16885809

John-Pierre Cornelissen

Hi Itamar, sorry for the late reply, I never received a notification from your reply because somehow email notifications were disabled for this ticket.

Although the given solution would probably work, I wasn't really looking for a custom function to make this happen right now. It was meant as a feature request, to get a button in the translation dashboard to download a csv file for the *selected* records.

--
Reading back my original question. This is where your support question rewriting tool went all wrong. The 'question' it wrote wasn't the question I asked nor my intention.

I hate that support AI from the bottom of my heart. It always completely rewrites my carefully written question into something with less detail and something I didn't want. To avoid that I have to correct the AI by rewriting my question all over again, I simply copy my original text before submitting the ticket, after that I replace the AI summary with my own text and I can't be bothered with the AI symptoms and questions anymore.

I already asked several time to please please remove that rewriting AI. I have never seen anything good coming out of it. Or at least, keep the original input as a reference instead of removing it from the ticket all together.

April 2, 2025 at 2:20 pm #16887556

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Thanks for suggesting this feature request.

I can assure you that I passed it on to my superiors, and it is clearly a feature request. However, I can't promise it will be implemented. This is up to my supervisors to decide.

I am sorry for any inconvenience the AI support wizard caused you. You already expressed your dissatisfaction with it in a previous ticket, and I passed it on to our support manager.

https://wpml.org/forums/topic/link-to-release-notes-in-wp-repository/

I've added your last comment to our internal tracking about this case.

Regards,
Itamar.

April 2, 2025 at 2:46 pm #16887670

John-Pierre Cornelissen

Thank you Itamar.

April 2, 2025 at 4:35 pm #16888169

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

You are welcome.