Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client needed a method to programmatically translate a large number of WooCommerce attribute labels using a third-party API, rather than manually translating each one.
Solution:
1. Create a fake product and assign all attributes to it.
2. Send the product for translation.
3. Once translated, delete the product.
This method avoids the need for custom scripts by utilizing existing WPML functionality to translate all attributes in bulk. For more details, refer to the documentation on translating taxonomy terms: https://wpml.org/faq/how-to-translate-all-taxonomy-terms-at-once/

If this solution does not apply to your case, or if it seems outdated, we recommend opening a new support ticket. Additionally, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. For further assistance, please visit our support forum: WPML Support Forum.

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.

Tagged: 

This topic contains 13 replies, has 2 voices.

Last updated by Ilyes 2 years, 11 months ago.

Assisted by: Ilyes.

Author Posts
April 26, 2023 at 11:16 am #13540539

amerE

Hello i want to translate the woocommerce attribute label programatically either in functions.php or in stand alone script, can you please guide me how to achieve it?

April 26, 2023 at 12:31 pm #13541189

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello Amer,

Thank you for your patience,

Apparently, we have a shortcut to translate all attributes and taxonomies in one go.

The idea is to create one fake product > assign all attributes to it > send product to translation > Then delete the product once translated

You could refer to this documentation : https://wpml.org/faq/how-to-translate-all-taxonomy-terms-at-once/

This way, you won't need to add any scripts to the existing code.

I hope this helped you,

Best,

April 26, 2023 at 5:58 pm #13544073

amerE

Hi, but we have to manually translate all the fields yes? Isnt there any way we can achieve it programmatically as i am receiving the translations from the third party api and i dont want manual job because there are more than 4000 attributes in the eshop.

April 27, 2023 at 2:05 pm #13550781

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

I totally agree, 4000+ is a huge amount.

We usually do not have such custom scripts, but I was able to find the following :

https://stackoverflow.com/questions/42113840/auto-add-all-product-attributes-when-adding-a-new-product-in-woocommerce

It's untested by us, and you should back up everything and run it on a staging area and adjust if needed.

I hope this helps,

Thanks,

April 27, 2023 at 5:38 pm #13552229

amerE

Hello,

I have added the attributes in greek language but now i need to add their translations in english and i believe the above code does not work because i only need to translate all the attributes as all products are already added .

Thanks!

April 28, 2023 at 8:10 am #13555387

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

You could actually use that snippet in the following way :

1- Backup your site
2- Add the script from Stackoverflow to your functions.php of your theme
3- Create a new product (if the script worked correctly, this new product will have all the attributes assigned to it)
4- Send that product for translation
5- Translator will get this product along with all the attributes
6- Confirm that everything got translated correctly
7- Delete the new product
8- Remove the Stackoverflow script

Is this method clearer to you now? The script will assign all attributes to your new product and that way you can send it to your translators, a shortcut to get all your attributes translated.

Best,

May 3, 2023 at 6:16 am #13574993

amerE

Hello,

Regarding the5th point "5- Translator will get this product along with all the attributes"

Here we have to translate it manually or it will be translated automatically?

May 3, 2023 at 8:29 am #13576203

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

You could translate manually or automatically, both should work.

If you want to translate it yourself, you should be able to do it from WooCommerce > WooCommerce Multilingual & Multicurrency > Products > Click on the + “plus” sign > Translate
You should then see all the attributes listed under the translation editor, similar to this case :
1- hidden link
2- hidden link

---

However, if you want a third party translation service to translate it, you could send it using WPML translation manager and select the product you want to send for translation : hidden link

Here is the entire workflow : https://wpml.org/documentation/translating-your-contents/page-builders/#sending-content-for-automatic-translation-in-bulk

Best,

May 4, 2023 at 12:22 pm #13586345

amerE

Hi we want to translate all attributes automatically via a script not via a translation module so how can we achieve it? Is that possible or not?

May 4, 2023 at 3:16 pm #13587735

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

I'm not aware of such method, could you please explain further on how you wish to translate your attributes?

We usually do not have custom scripts or codes,

Looking forward to your reply,

May 5, 2023 at 6:06 am #13590809

amerE

I have imported all the products through third party api using ICECAT and i have used woocommerce rest api to import products and you are aware that from woocommerce api we cant import the attributes names in secondary language according to this link hidden link https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual/ so i have imported the attribute name in primary language now i need to translate it in the secondary language using the same icecat api as this api provides the translation so i need a custom code or script or api like wooocommerce rest api which translates this attributes names.

Let me know if the above is not clear.

Thanks & Regards,

May 5, 2023 at 10:57 am #13593339

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello again,

I'm afraid we currently do not have this functionality, and it falls under custom coding,

If I'm not wrong, you are trying to avoid that step: "WooCommerce → WooCommerce Multilingual & Multicurrency. In the Attributes tab, scroll down to the Translations of taxonomy labels and slug section and add the translations."

I will ask our developers if this is possible,

Thank you for your patience,

May 5, 2023 at 12:09 pm #13594311

amerE

Yes please let us know

May 8, 2023 at 9:33 am #13603631

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

I have received an answer, We have a couple of hooks that might help you achieve such result :

- https://wpml.org/wpml-hook/wpml_set_element_language_details/
- To get the Trid https://wpml.org/wpml-hook/wpml_element_trid/
- All hooks https://wpml.org/wpml-hook

Please keep in mind that we do not offer custom codes as part of our support service.

I would suggest referring to one of our contractors if you want a professional help with this script : https://wpml.org/contractors/

Thank you for your comprehension!

Best,