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.

This topic contains 10 replies, has 2 voices.

Last updated by Raja Mohammed 3 years, 1 month ago.

Assisted by: Raja Mohammed.

Author Posts
February 3, 2021 at 5:26 pm #7999375

julienM-21

Hi,

I have some post i would like to translate with the REST API.

So basically, i have the ID of the main post, and i want :
- to create the translation via the API
- to link the translation with the main post

I try to find a way on your documentation, but i didn't find so much things.

The only interesting thing i found is this 2 posts :
- https://wpml.org/forums/topic/adding-translations-via-wpml-using-rest-api/
- https://wpml.org/forums/topic/adding-translations-via-wpml-using-rest-api-2/

But the user didn't explain how he did, and we are not sure he succeed.
As well, these 2 posts are a bit old.

Maybe now there is a documented way ?
Can you help me ? or give me some links to put me in the correct way ?

Thanks a lot

February 5, 2021 at 9:55 am #8014631

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi there,

I am afraid, Creating post and page translation using Rest API is not tightly integrated with WPML yet, You can use langauge parameter to create translation however it will still need some custom work to connect the translation with the original content of the post / page.

To put it simple this is not possible yet, I agree this should be a must have feature for latest plugin please send us a feature request so that this will be considered for future implementation https://wpml.org/suggest-a-new-feature-for-wpml/

Regards
Raja

February 5, 2021 at 1:50 pm #8017029

julienM-21

Thanks @raja-m

You said : "You can use langage parameter to create translation "

Do you mean like this
"language" : "en", for exemple ?
I try but seems that doesn't works. Is there a special endpoint i should use ?
Until now i try to do my post on domain.com/wp-json/wp/v2/customposttypename

For the rest i followed your advise and ask a feature request 🙂

February 5, 2021 at 2:07 pm #8017197

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Language parameters as mentioned by the client here https://wpml.org/forums/topic/adding-translations-via-wpml-using-rest-api/#post-4691557

In your case the urls would be

For default language
domain.com/wp-json/wp/v2/customposttypename

For English
domain.com/en/wp-json/wp/v2/customposttypename

February 5, 2021 at 5:13 pm #8018999

julienM-21

Thanks @raja-m

It works with this parameters directly in the URL.

I'm gonna wait for a reply of the WPML team about the link between both translation.

Thanks a lot !

February 8, 2021 at 5:39 am #8028597

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I hope your request will be addressed by a different team. I am afraid, There is nothing much I could do from my end on a feature request.

Regards
Raja

February 10, 2021 at 5:03 pm #8054789

julienM-21

Hi @raja-m

I didn't receive any confirmation message after publish my feature request.
How can i be sure that's in the pipe ?

Thanks

February 11, 2021 at 6:03 am #8058029

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

I checked with the team usually we reply to all the feature request submission, You might also have received an email from our end if not, Kindly wait for a couple of days to hear back from us as your request may still be in the discussion at our end.

As of now i can confirm your request is already received at our end.

Regards
Raja

February 11, 2021 at 1:03 pm #8061691

julienM-21

Thanks a lot @raja-m

If it's not possible to do this feature now (i understand this), i would love to have some advises that help me to code this by myself.
For exemple : a specific hook i can use, the file i should edit...
If one of the developper can "show me the way", it would save me 🙂

I need to go forward on this project and my client is waiting for me.

Thanks

February 12, 2021 at 2:48 pm #8071967

julienM-21

Finally i created a custom endpoint to link the 2 translations.

This is my code : hidden link

So the process is :
1- create the first post in language 1 (classic API POST call)
2- create the second post in language 2 (classic API POST call)
3- link both (custom endpoint)

Hope is gonna help people

February 12, 2021 at 5:12 pm #8073331

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You are awesome 🙂 Thanks for sharing the information, I will add that to the ticket summary so that it would be of help to others with similar issue.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.