{"id":15050,"date":"2011-09-25T22:21:58","date_gmt":"2011-09-25T22:21:58","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/wpml-json-api\/"},"modified":"2012-12-12T19:52:14","modified_gmt":"2012-12-12T19:52:14","slug":"wpml-json-api","status":"publish","type":"plugin","link":"https:\/\/kk.wordpress.org\/plugins\/wpml-json-api\/","author":8369143,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"0.1.3","stable_tag":"0.1.4","tested":"3.4.2","requires":"2.8","requires_php":"","requires_plugins":"","header_name":"WPML JSON-API","header_author":"Daniel Duvall","header_description":"","assets_banners_color":"","last_updated":"2012-12-12 19:52:14","external_support_url":"","external_repository_url":"","donate_link":"https:\/\/store.lettersandlight.org","header_plugin_uri":"","header_author_uri":"http:\/\/mutual.io","rating":0,"author_block_rating":0,"active_installs":10,"downloads":5381,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":0},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["0.1.0","0.1.1","0.1.2","0.1.4"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[1556,225,104,1118,103],"plugin_category":[48],"plugin_contributors":[89255],"plugin_business_model":[],"class_list":["post-15050","plugin","type-plugin","status-publish","hentry","plugin_tags-api","plugin_tags-cms","plugin_tags-i18n","plugin_tags-json","plugin_tags-wpml","plugin_category-language-tools","plugin_contributors-dzachary","plugin_committers-dzachary"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/wpml-json-api.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin filters the response content of requests made to the WordPress <a href=\"http:\/\/wordpress.org\/extend\/plugins\/json-api\">JSON-API<\/a> to include data for translations created through the <a href=\"http:\/\/wpml.org\">WPML Multilingual CMS<\/a> plugin. One may also request the translation of response objects to a supported target language.<\/p>\n\n<p><a href=\"http:\/\/www.lettersandlight.org\">The Office of Letters and Light<\/a> uses this plugin to integrate WordPress and <a href=\"http:\/\/wpml.org\">WPML<\/a> with its Rails-built <a href=\"http:\/\/www.nanowrimo.org\">National Novel Writing Month<\/a> event-site application. We use WordPress to manage all back-end site content and our <a href=\"http:\/\/github.com\/lettersandlight\/kiosk\">Kiosk Ruby gem<\/a> for consuming, caching, searching, and serving the content through Rails. This could not have been so easily accomplished without the well-built and extensible <a href=\"http:\/\/wordpress.org\/extend\/plugins\/json-api\">JSON-API<\/a> for which we are grateful. And without the <a href=\"http:\/\/wpml.org\">WPML<\/a> plugin, we would not have such an intuitive and capable CMS i18n interface.<\/p>\n\n<h3>Usage<\/h3>\n\n<p>Please be familiar with the\n<a href=\"http:\/\/wordpress.org\/extend\/plugins\/json-api\">JSON-API<\/a>.<\/p>\n\n<ol>\n<li>Augmented response objects\n\n<ul>\n<li>1.1. Language<\/li>\n<li>1.2. Translations<\/li>\n<\/ul><\/li>\n<li>Filtering response objects by language\n\n<ul>\n<li>2.1. Specifying the language<\/li>\n<li>2.2. Filtered results<\/li>\n<\/ul><\/li>\n<li>Response object translation\n\n<ul>\n<li>3.1 Specifying the target language<\/li>\n<li>3.2 Translated results<\/li>\n<li>3.3 Translatable objects and properties<\/li>\n<\/ul><\/li>\n<\/ol>\n\n<h3>1. Augmented response objects<\/h3>\n\n<h3>1.1. Language<\/h3>\n\n<p>After enabling the WPML JSON-API plugin, response objects will contain the\nlanguage in which the object content was written.<\/p>\n\n<p>Let's take a look at an example response to a request made to <code>http:\/\/wordpress.site.example\/api\/get_page\/?dev=1&amp;id=127<\/code>.<\/p>\n\n<pre><code>{\n  \"status\": \"ok\",\n  \"page\": {\n    \"id\": 127,\n    \"type\": \"page\",\n    \"slug\": \"the-best-page\",\n    \"url\": \"http:\\\/\\\/wordpress.site.example\\\/the-best-page\\\/\",\n    \"status\": \"publish\",\n    \"title\": \"The Best Page\",\n    \"title_plain\": \"The Best Page\",\n    \"content\": \"&lt;p&gt;This is the best page ever created.&lt;\\\/p&gt;\\n&lt;blockquote&gt;&lt;p&gt;Best damn page ever. &#8211; Dan&lt;\\\/p&gt;&lt;\\\/blockquote&gt;\\n\",\n    \"excerpt\": \"This is the best page ever created. Best damn page ever. &#8211; Dan\",\n    \"date\": \"2011-09-22 18:48:09\",\n    \"modified\": \"2011-09-22 18:54:55\",\n    \"categories\": [],\n    \"tags\": [],\n    \"author\": {\n      \"id\": 4,\n      \"slug\": \"dzachary\",\n      \"name\": \"Daniel Duvall\",\n      \"first_name\": \"Daniel\",\n      \"last_name\": \"Duvall\",\n      \"nickname\": \"Daniel Duvall\",\n      \"url\": \"\",\n      \"description\": \"\"\n    },\n    \"comments\": [],\n    \"attachments\": [],\n    \"comment_count\": 0,\n    \"comment_status\": \"open\",\n    \"translations\": {\n      \"en\": {\n        \"post_title\": \"The Best Page\",\n        \"post_status\": \"publish\",\n        \"id\": 21,\n        \"language_code\": \"en\",\n        \"is_original\": true,\n        \"resource_id\": 127\n      },\n      \"es\": {\n        \"post_title\": \"La P\\u00e1gina Mejor\",\n        \"post_status\": \"publish\",\n        \"id\": 22,\n        \"language_code\": \"es\",\n        \"is_original\": false,\n        \"resource_id\": 131\n      }\n    },\n    \"language\": \"en\"\n  }\n}\n<\/code><\/pre>\n\n<p>The <code>language<\/code> property specifies the code of the language in which the page\nwas written\u2014pretty simple.<\/p>\n\n<h3>1.2. Translations<\/h3>\n\n<p>The <code>translations<\/code> objects of the same example response given in Section 1.1.\ninclude data for each <em>published<\/em> resource that comprises a translation of\nits parent object.<\/p>\n\n<pre><code>\"translations\": {\n  \"en\": {\n    \"post_title\": \"The Best Page\",\n    \"post_status\": \"publish\",\n    \"id\": 21,\n    \"language_code\": \"en\",\n    \"is_original\": true,\n    \"resource_id\": 127\n  },\n  \"es\": {\n    \"post_title\": \"La P\\u00e1gina Mejor\",\n    \"post_status\": \"publish\",\n    \"id\": 22,\n    \"language_code\": \"es\",\n    \"is_original\": false,\n    \"resource_id\": 131\n  }\n<\/code><\/pre>\n\n<p>Properties included in each member of the <code>translations<\/code> object depend on the\ntype of parent object.<\/p>\n\n<p>All <code>post<\/code> and <code>page<\/code> objects will include the following.<\/p>\n\n<ul>\n<li><code>id<\/code> - The ID of the translation object.<\/li>\n<li><code>language_code<\/code> - The code of the language in which the translation is written. Each translation object is also keyed by this value.<\/li>\n<li><code>is_original<\/code> - Specifies whether the language of this translation is the language in which the original work was written.<\/li>\n<li><code>resource_id<\/code> - The ID of the translated version of the parent object.<\/li>\n<li><code>post_title<\/code> - The title of the translated post\/page.<\/li>\n<li><code>post_status<\/code> - The status of the translated post\/page. Always 'publish'.<\/li>\n<li><code>post_id<\/code> - Redundancy of <code>resource_id<\/code>.<\/li>\n<\/ul>\n\n<p>All <code>category<\/code> objects will include the following.<\/p>\n\n<ul>\n<li><code>id<\/code> - The ID of the translation object.<\/li>\n<li><code>language_code<\/code> - The code of the language to which the category was translated.<\/li>\n<li><code>is_original<\/code> - Specifies whether the language of this translation is the language of the original category.<\/li>\n<li><code>resource_id<\/code> - The ID of the translated version of the parent object.<\/li>\n<li><code>name<\/code> - The translated category name.<\/li>\n<li><code>term_id<\/code> - Redundancy of <code>resource_id<\/code>.<\/li>\n<li><code>post_count<\/code> - The number of posts tagged with the translated category.<\/li>\n<\/ul>\n\n<h3>2. Filtering response objects by language<\/h3>\n\n<p>You may tell the API to only return objects for a specific language by using\nthe <code>language<\/code> parameter.<\/p>\n\n<h3>2.1. Specifying the language<\/h3>\n\n<p>The <code>language<\/code> parameter should be one of the supported language codes.<\/p>\n\n<p>Example:<\/p>\n\n<ul>\n<li><code>http:\/\/wordpress.site.example\/api\/get_category_index\/?language=es&amp;dev=1<\/code><\/li>\n<\/ul>\n\n<h3>2.2. Filtered results<\/h3>\n\n<p>Following is a example response to the example request in Section 2.1.<\/p>\n\n<pre><code>{\n  \"status\": \"ok\",\n  \"count\": 2,\n  \"categories\": [\n    {\n      \"id\": 13,\n      \"slug\": \"noticias-de-ultima-hora-2\",\n      \"title\": \"Noticias de \\u00daltima Hora\",\n      \"description\": \"\",\n      \"parent\": 0,\n      \"post_count\": 1,\n      \"translations\": {\n        \"en\": {\n          \"name\": \"Breaking News\",\n          \"term_id\": 4,\n          \"post_count\": 2,\n          \"id\": 9,\n          \"language_code\": \"en\",\n          \"is_original\": true,\n          \"resource_id\": 4\n        },\n        \"es\": {\n          \"name\": \"Noticias de \\u00daltima Hora\",\n          \"term_id\": 13,\n          \"post_count\": 1,\n          \"id\": 26,\n          \"language_code\": \"es\",\n          \"is_original\": false,\n          \"resource_id\": 13\n        }\n      },\n      \"language\": \"es\"\n    }\n  ]\n}&lt;h3&gt;3. Response object translation&lt;\/h3&gt;\n<\/code><\/pre>\n\n<p>You can request objects to be translated before they are returned. This may\nsave you some requests if you have the slug or ID and just need the object in\na specific language.<\/p>\n\n<h3>3.1. Specifying the target language<\/h3>\n\n<p>The target language can be specified by passing a <code>to_language<\/code> parameter. The\nvalue should be one of the supported language codes.<\/p>\n\n<p>Example:<\/p>\n\n<ul>\n<li><code>http:\/\/wordpress.site.example\/api\/get_page\/?slug=the-best-page&amp;to_language=es&amp;dev=1<\/code><\/li>\n<\/ul>\n\n<h3>3.2. Translated results<\/h3>\n\n<p>Following is an example response to the example request in Section 3.1.<\/p>\n\n<pre><code>{\n  \"status\": \"ok\",\n  \"page\": {\n    \"id\": 127,\n    \"type\": \"page\",\n    \"slug\": \"la-pagina-mejor\",\n    \"url\": \"http:\\\/\\\/wordpress.site.example\\\/the-best-page\\\/\",\n    \"status\": \"publish\",\n    \"title\": \"La P\\u00e1gina Mejor\",\n    \"title_plain\": \"La P\\u00e1gina Mejor\",\n    \"content\": \"&lt;p&gt;Esta es la p\\u00e1gina mejor se haya creado.&lt;\\\/p&gt;\\n&lt;blockquote&gt;&lt;p&gt;Best damn page ever. &#8211; Dan&lt;\\\/p&gt;&lt;\\\/blockquote&gt;\\n\",\n    \"excerpt\": \"Esta es la p\\u00e1gina mejor se haya creado. Best damn page ever. &#8211; Dan\",\n    \"date\": \"2011-09-22 18:48:09\",\n    \"modified\": \"2011-09-22 18:54:55\",\n    \"categories\": [],\n    \"tags\": [],\n    \"author\": {\n      \"id\": 4,\n      \"slug\": \"dzachary\",\n      \"name\": \"Daniel Duvall\",\n      \"first_name\": \"Daniel\",\n      \"last_name\": \"Duvall\",\n      \"nickname\": \"Daniel Duvall\",\n      \"url\": \"\",\n      \"description\": \"\"\n    },\n    \"comments\": [],\n    \"attachments\": [],\n    \"comment_count\": 0,\n    \"comment_status\": \"open\",\n    \"translations\": {\n      \"en\": {\n        \"post_id\": 127,\n        \"post_title\": \"The Best Page\",\n        \"post_status\": \"publish\",\n        \"id\": 21,\n        \"language_code\": \"en\",\n        \"is_original\": true,\n        \"resource_id\": 127\n      },\n      \"es\": {\n        \"post_id\": 131,\n        \"post_title\": \"La P\\u00e1gina Mejor\",\n        \"post_status\": \"publish\",\n        \"id\": 22,\n        \"language_code\": \"es\",\n        \"is_original\": false,\n        \"resource_id\": 131\n      }\n    },\n    \"language\": \"es\",\n    \"translated\": true,\n    \"original_slug\": \"the-best-page\",\n    \"original_title\": \"The Best Page\",\n    \"original_title_plain\": \"The Best Page\"\n  }\n}\n<\/code><\/pre>\n\n<p>As you can see the <code>slug<\/code>, <code>title<\/code>, <code>title_plain<\/code>, <code>excerpt<\/code>, and <code>content<\/code>\nproperties have been rewritten with the Spanish translation. In addition, the\noriginal properties have been prefixed with <code>original_<\/code>. This is always the\ncase for all properties except for <code>excerpt<\/code> and <code>content<\/code>. In an effort to\nsave on response size, the latter have been omitted.<\/p>\n\n<h3>3.3. Translatable objects and properties<\/h3>\n\n<p>Here are all of the translatable object types and their translatable\nproperties, those that can be rewritten as described in Section 3.2.<\/p>\n\n<p>Objects <code>post<\/code> and <code>page<\/code>:<\/p>\n\n<ul>\n<li><code>slug<\/code><\/li>\n<li><code>title<\/code><\/li>\n<li><code>title_plain<\/code><\/li>\n<li><code>excerpt<\/code><\/li>\n<li><code>content<\/code><\/li>\n<\/ul>\n\n<p>Objects <code>tag<\/code> and <code>category<\/code>:<\/p>\n\n<ul>\n<li><code>slug<\/code><\/li>\n<li><code>title<\/code><\/li>\n<li><code>description<\/code><\/li>\n<\/ul>\n\n<!--section=installation-->\n<ol>\n<li>Upload the <code>wpml-json-api<\/code> folder to the <code>\/wp-content\/plugins\/<\/code> directory or install directly through the plugin installer.<\/li>\n<li>Activate the plugin through the 'Plugins' menu in WordPress or by using the link provided by the plugin installer.<\/li>\n<\/ol>\n\n<!--section=changelog-->\n<p>Please see the <a href=\"https:\/\/github.com\/marxarelli\/wpml-json-api\">GitHub project page<\/a> for a comprehensive list of changes.<\/p>","raw_excerpt":"An extension to JSON-API for sites using the WPML Multilingual CMS plugin.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/15050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=15050"}],"author":[{"embeddable":true,"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/dzachary"}],"wp:attachment":[{"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=15050"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=15050"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=15050"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=15050"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=15050"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/kk.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=15050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}