• Hi,

    I have a mobile app that uses WooCommerce Json Api to fetch translated entities.
    Most endpoints work exactly as expected using query parameter “lang” to translate strings in the response.

    There is on endpoint that behaves differently, the Product Attributes API API docs

    Below is an example request and response made with finnish (lang=fi) query parameter to fetch product attributes. The attribute terms and options are translated correctly (“Gluteeniton”), but the attribute label is always “Food Allergies”, when the translation is “Ruoka-allergiat”. On the web page

    Example request:
    /wp-json/wc/v3/products/attributes?lang=fi

    Example response:

    
    [
     0: {
       id: 6
       name: "Food Allergies"
       options: [
         name: "Gluteeniton"
         taxonomy: "pa_food-allergies"
         ...
       ]
       ...
      }
    ]
    

    Other info:
    – The site uses “Language URL format” option “Different languages in directories” ({URL}/{language}/…).
    – In the web store, all product attribute labels are properly translated, both as search filters and on product details.
    – Another endpoint, the products JSON API, has the same issue where attribute label is not translated but options are.

    What I have tried that had no effect:
    – Changing the “Language URL format” (prefix,suffix, query parameter) in WPML
    – Hooking into “woocommerce_rest_prepare_product_attribute” filter
    – Filter “wpml_translate_single_string” to manually translate the label
    – Filter “wpml_object_id” on product attribute id
    – Searching in database for the values

    I can find the translated values in the database, but I don’t exactly understand how the WC/WPML/WCML plugins are integrated.

    My questions are currently:
    1. Is the product attribute label translated by WooCommerce Multilingual in the JSON API, or is it restricted to product attribute terms/options only?
    2. How could I go about finding the cause of this issue?
    3. Could I manually translate the product attribute labels using the “woocommerce_rest_prepare_product_attribute” filter hook?

    Installation:
    WordPress 5.8.3
    PHP 7.3.33
    WooCommerce 6.0.0
    WooCommerce Multilingual 4.12.1
    WPML Multilingual CMS 4.4.12
    WPML String Translation 3.1.10
    WPML Translation Management 2.10.8
    (+ many other plugins)

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support diegootgs

    (@diegootgs)

    Hello @jonasblb,

    Is it possible to reproduce this issue on a clean install? If so, could you please reproduce it on this test website? https://brown-clarinete.sandbox.otgs.work/?auto=3jn6TODeIlxqYDWaOnBnwA9anGOh5wWK

    Regards,
    Diego

    Thread Starter jonasblb

    (@jonasblb)

    Hi, thank you for the fast response and the sandbox.

    It seems I managed to reproduce similar behaviour on the sandbox install.

    I added a test attribute, a test value of that attribute, as well as published a product with the test value. I added translations to all of these in the second language (spanish), and WooCommerce Multilingual Status page shows translations are complete.

    Then using Postman I made some requests (with consumer key and secret as query parameters, omitted from below urls).

    First, the product attributes endpoint on /wp-json/wc/v3/products/attributes did not translate the attribute label regardless of “lang” parameter “es” or “en”. It was always default (english).
    Secondary observation: On this endpoint attribute options were not included in the response. On the production install I am working on they are always included, but may be unrelated.

    Second, to get the terms of the test attribute /wp-json/wc/v3/products/attributes/1/terms it was possible to use “lang” with both “es” and “en” to get the correct translated terms. Secondary observation: On this endpoint I observed some kind of caching behaviour, where if the “lang” parameter was omitted, results would be translated using lang parameter that was passed in any previous request to the API. In this case the previous endpoint was product attributes, meaning it does respect the “lang” parameter between requests, but it does not use it to translate product attribute labels.

    Third, I tried all products /wp-json/wc/v3/products and that provided the correct spanish translations when “lang” parameter was set to “es”. However, in the “attributes” array of the product, the product attribute label (name) was still in english, but the option was translated to spanish.

    From this I would guess that product attribute labels are never translated within the API, since the issue is exactly the same as on my production install.

    Is there anything in particular I could investigate?

    BR,
    Jonas

    Plugin Support diegootgs

    (@diegootgs)

    Hello @jonasblb,

    Thank you very much for the details! I confirmed the issue and escalated it to our developers.

    Regards,
    Diego

    Thread Starter jonasblb

    (@jonasblb)

    Hi,

    I see there are new versions of WooCommerce Multilingual (4.12.5). Is the attribute label translation issue working differently compared to 4.12.1?
    The revision notes specify exact changes and I have a hard time guessing if they affect this issue.

    Is there any chance that I could hack around this issue with a filter, or by modifying something?

    BR,
    Jonas

    Plugin Support diegootgs

    (@diegootgs)

    Hi there,

    I checked the status of this issue in our internal system and it’s not fixed yet. So it’s expected that the issue will continue in the new version.

    Unfortunately there is not workaround available at the moment.

    Regards,
    Diego

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Product attribute labels untranslated API’ is closed to new replies.