{"id":417285,"date":"2025-01-07T08:00:00","date_gmt":"2025-01-07T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/yard-deepl\/"},"modified":"2025-01-31T16:43:00","modified_gmt":"2025-01-31T16:43:00","slug":"yard-deepl","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/yard-deepl\/","title":{"rendered":"Yard DeepL"},"content":{"rendered":"<p>This plugin registers secure API endpoints that allow you to request translations directly from DeepL without exposing your Deepl API-key. These endpoints are only accessible when a valid nonce is provided. When providing translations to website visitors, you can configure which languages are supported for translation.<\/p>\n<h3>Caching Mechanism<\/h3>\n<p>Each object that is translated will store its cached translation in the <code>wp_postmeta<\/code> table within the database. This caching mechanism ensures that translations are efficiently reused, reducing unnecessary API requests to DeepL and saving costs.<\/p>\n<ul>\n<li>Serving Cached Translations: If a cached translation is newer than the <code>post_modified<\/code> date of the object, the cached version is served.<\/li>\n<li>Fetching New Translations: When the <code>post_modified<\/code> date of the object is more recent than the cached translation, a new translation is fetched from DeepL. Once retrieved, this translation is immediately cached for future use.<\/li>\n<\/ul>\n<p>This approach minimizes the number of API calls to DeepL, ensuring translations are kept up to date only when necessary.<\/p>\n<h3>External Services<\/h3>\n<p>This plugin connects to the DeepL API to provide translations for content.<\/p>\n<ul>\n<li><strong>Service:<\/strong> DeepL API (https:\/\/www.deepl.com)<\/li>\n<li><strong>Purpose:<\/strong> To translate text from one language to another based on the provided target language.<\/li>\n<li><strong>Data Sent:<\/strong> Text content for translation, the target language code, and the DeepL API key (handled securely and never exposed to users).<\/li>\n<li><strong>Conditions:<\/strong> Data is sent when a request for translation is initiated.<\/li>\n<li><strong>Privacy Policy:<\/strong> <a href=\"https:\/\/www.deepl.com\/privacy\" rel=\"nofollow ugc\">DeepL Privacy Policy<\/a><\/li>\n<li><strong>Terms of Service:<\/strong> <a href=\"https:\/\/www.deepl.com\/pro-license\" rel=\"nofollow ugc\">DeepL Terms of Service<\/a><\/li>\n<\/ul>\n<h3>Usage<\/h3>\n<h3>Security<\/h3>\n<p>The API endpoints registered by this plugin are secured using a WordPress nonce. The nonce is passed to the front-end using the <code>wp_localize_script<\/code> function and is stored in a global JavaScript object <code>ydpl<\/code> which contains the following properties:<\/p>\n<ul>\n<li><code>ydpl_translate_post_id<\/code>: The ID of the post to be translated.<\/li>\n<li><code>ydpl_rest_translate_url<\/code>: The URL of the API endpoint for translation requests.<\/li>\n<li><code>ydpl_supported_languages<\/code>: The list of languages supported for translation.<\/li>\n<li><code>ydpl_api_request_nonce<\/code>: The nonce used for API validation.<\/li>\n<\/ul>\n<p>When making requests to the API, ensure that the nonce is included in the request headers. The header should be named <code>nonce<\/code>, and it should contain the value of <code>ydpl_api_request_nonce<\/code>.<\/p>\n<h3>Example<\/h3>\n<h3>Request<\/h3>\n<pre><code>var xhr = new XMLHttpRequest();\nxhr.open('POST', ydpl.ydpl_rest_translate_url, true);\n\n\/\/ Set request headers\nxhr.setRequestHeader('Content-Type', 'application\/json');\nxhr.setRequestHeader('nonce', ydpl.ydpl_api_request_nonce);\n\n\/\/ Handle response\nxhr.onreadystatechange = function () {\n    if (xhr.readyState === 4 && xhr.status === 200) {\n        console.log('Translation:', JSON.parse(xhr.responseText));\n    } else if (xhr.readyState === 4) {\n        console.error('Error:', xhr.statusText);\n    }\n};\n\n\/\/ Prepare and send the request body\nvar data = JSON.stringify({\n    text: [\"Look another test\"],\n    target_lang: \"DE\"\n});\n\nxhr.send(data);\n<\/code><\/pre>\n<h3>Response<\/h3>\n<pre><code>[\n    {\n        \"text\": \"Look another test!\",\n        \"translation\": \"Sehen Sie sich einen weiteren Test an!\"\n    }\n]\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This plugin registers secure API endpoints that allow you to request translations directly from DeepL without exposing your DeepL API-key.<\/p>\n","protected":false},"author":65,"featured_media":417286,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Yard DeepL - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"This plugin registers secure API endpoints that allow you to request translations directly from DeepL without exposing your DeepL API-key."},"footnotes":""},"categories":[1],"tags":[29970,30,29971],"class_list":["post-417285","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-deepl","tag-secure","tag-translating"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/417285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=417285"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/417285\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/417286"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=417285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=417285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=417285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}