XML-RPC language interface
Some applications use XML-RPC to edit WordPress sites. Most notably are the WordPress iPhone and BlackBerry applications.
Language custom fields
WPML allows controlling post and page languages via custom fields.
- _wpml_language (R/W): The short ISO language code. For example, ‘en’, ‘es’, ‘fr’, ‘de’.
- _wpml_trid (R/W): The translation group ID. Items with the same trid are considered as translations for one another.
- _wpml_translations (R): A serialized array containing the translations for a post or page.
WPML adds the language custom fields to these XML-RPC calls:
Writing
- metaWeblog.newPost or wp.newPage
- metaWeblog.editPost or wp.editPage
Reading
- wp.getPage
- metaWeblog.getPost
- metaWeblog.getRecentPosts
When a page/post is read, WPML sets the trid and language attributes. The actual values for these are stored in WPML’s translations table and the values are copied to the custom field when the RPC is called.
When writing, WPML monitors for the presence of these custom fields and will update the translations table according to them.
Usage
1. Get language information
icanlocalize.get_languages_list
This will return a list of all available languages for the site. This list should be used to display languages and translation options for posts, pages, tags and categories.
Accepts one (optional) parameter: language code. Besides the English and native names, languages will be returned in this language as well.
1. Create a new page (or post)
wp.newPage
In the application, include a drop-down window that allows selecting the language of the page.
Add the _wpml_language custom field to tell WPML the language of this new page.
2. Read a page from WordPress and display it (with translation controls)
wp.getPage
This will return _wpml_language, _wpml_trid and _wpml_translations.
_wpml_translations needs to be unserialized. It will contain an array of language codes and the IDs of translations for this page. Any existing translation will be greater than zero. Languages with no translations will get an ID of zero.
The application can now display the language of the page and all existing translations and allow adding new translations or editing existing translations.
The trid value is kept, but doesn’t need to be displayed anywhere.
3. Add translation to a page
wp.newPage
Include both _wpml_language and _wpml_trid. The trid value is the same as for the page we’re adding translation to. The language must be unique to the trid.
Exceptions
Two posts or pages cannot have the same trid and language values. All elements in the same trid must have unique languages.
If you edit an existing page or try to create a new page which causes the translation group to have two elements with the same number, the RPC will fail, returning an error.
For more information on WPML’s internals, have a look at the table structure.
English