While integrating the WordPress REST API into a multilingual web application that my team is working on, we realized we needed a way to find out if there were translations of a specific page available, and if so, some basic details about it. The WordPress installation is running the WPML plugin to manage translations. Google wasn’t quickly giving us any solutions to this, so I decided just to add the functionality myself. Open Source for the win!
When querying the REST API, each post (or page, or custom post type) also returns the locale associated with that object, along with the Post ID, Permalink (URL), Post Title, and locale code for each available translation.
Today I’ve pulled that code out of our project, and released it as an isolated plugin.
Interested? For now, you can download the WPML REST API plugin from GitHub. It’s been submitted to the WordPress plugin repository, and is awaiting approval from the wonderful volunteers there.
As always, bug reports and pull requests are welcome.