• Resolved job

    (@jobmoll)


    Hi,

    I have the problem that my Rest API requests are not translated. In this case, I tried to get my products from the WooCommerce Rest API.
    https://example.com/wp-json/wc/v3/products?status=publish
    https://example.com/de/wp-json/wc/v3/products?status=publish

    These both return products with the same “name”, “slug” & “description” in the main language. The “permalink” is correctly translated though and includes the permalink with /de/ & the correct slug.

    When I navigate to the product on my site the product title & description are correctly translated.

    I have disabled all my plugins except TranslatePress & WooCommerce and this issue continued to occur.

    Regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hey there,

    Thank you for reaching out to us!

    Would you mind sending us a link to your website so we can check this for ourselves?

    In theory this should work, please check if the title appears the same in the front end of your website as it does in the back end, also make sure it does not contain any separators such as “book-separator”.

    Best Regards,

    Thread Starter job

    (@jobmoll)

    Hi,

    The Woocommerce endpoints needs authorization so I can’t share the url and credentials here.

    The title is correct and the same in both the backend and the frontend. Only in the rest API it returns the wrong title.

    Regards, Job

    Thread Starter job

    (@jobmoll)

    Hi,

    This is still an issue for me. I have tried it on a new installation and putting /de/ before wp-json doesn’t seem to do anything.

    This is the solution I wrote for now, but this only includes the product name.

    function rijcew__add_translated_name_to_woo($response, $post, $request)
    {
        if (get_locale() == 'DE_de_formal') {
            $original_string = $response->data['name'];
    
            // Global WordPress database access class
            global $wpdb;
    
            // Table name with correct prefix
            $table_name = $wpdb->prefix . 'trp_dictionary_en_us_de_de_formal';
    
            // Prepare and execute SQL query to retrieve the translation
            $query = $wpdb->prepare(
                "SELECT translated
            FROM $table_name
            WHERE original = %s",
                $original_string
            );
    
            $translated_string = $wpdb->get_var($query);
    
            if ($translated_string !== null) {
                $response->data['name'] = $translated_string;
            }
        }
    
        $response->data['name'] = $response->data['name'];
        return $response;
    }
    add_filter('woocommerce_rest_prepare_product_object', 'rijcew__add_translated_name_to_woo', 10, 3);

    Could you help me further with this issue? I also need the description & slug translated as I expect it.

    Hey there,

    We deeply apologize for the delayed response.

    There has been a great load on our support team in the past few days, but such a long reply time is very uncommon.

    I have to reach out to our team about this and you can expect an answer on this topic on Monday!

    Thank you for your patience and apologies for the waiting time!

    Hello there,

    This is indeed a bug from our side. Thank you very much for the detailed description for this, I made a bug report for our development team and I will be letting you know as soon as there is any development made in this direction.

    Best Regards,

    Thread Starter job

    (@jobmoll)

    Awesome perfect. Let’s hope it gets fixed soon.
    Other things like search also return only the results in the main language. That will also probably be fixed once this issue is resolved.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Rest API response not translated.’ is closed to new replies.