{"id":2575,"date":"2015-03-25T12:27:37","date_gmt":"2015-03-25T12:27:37","guid":{"rendered":"http:\/\/wiki.davelevy.info\/?p=2575"},"modified":"2022-04-14T06:39:48","modified_gmt":"2022-04-14T06:39:48","slug":"auto-translating-a-web-page","status":"publish","type":"post","link":"https:\/\/davelevy.info\/wiki\/auto-translating-a-web-page\/","title":{"rendered":"Auto-translating a web page"},"content":{"rendered":"<p>This page was originally set up in 2015 when looking at using REST to invoke web site translations. My original code is still available on <a href=\"http:\/\/test.davelevy.info\/\">the test web site<\/a> and below but Google &amp; Babelfish have changed their APIs. I decided to refactor the page in 2022. The changes in the google API have been significant and my ambitions of including popular first languages in the UK led me to <a href=\"https:\/\/davelevy.info\/wiki\/translation-on-this-site\/\">implement<\/a> the gtranslate widget in 2022. This post has some use if you want to copy the version 2 code, but I have marked the page as &#8216;deprecated&#8217;.<br \/>\n<!--more--><\/p>\n<h3>Translation<\/h3>\n<p>This section of the post is in three parts. The original\u00a0 post, when I updated it to add some more popular languages in use in the UK and thirdly about implementing the plugin\/widget. These are documented in the following order, the recent hand crafted solution, shown on <a href=\"http:\/\/test.davelevy.info\/\">one of my test sites<\/a>, my searching for a widget, and then the old code, which you can hide, as it uses a retired google translate API.<\/p>\n<h4>Version 2<\/h4>\n<p>I made some changes today in the translation code, you&#8217;ll need to check the code; it moves the site to a google domain and translates the URL too, even when a domain changes.<\/p>\n<p>Here is the current Polish code;<\/p>\n<p class=\"scroll-box\" style=\"background-color: ivory; padding: 6px; font-family: monaco;\">&lt;A HREF=&#8221;https:\/\/test-davelevy-info.translate.goog\/?_x_tr_sch=http&amp;_x_tr_sl=en&amp;_x_tr_tl=pl&amp;_x_tr_hl=en-US&amp;_x_tr_pto=wapp&#8221;<br \/>\nTITLE=&#8221;polski, t\u0142umaczenie Google&#8221;&gt;&lt;IMG SRC=&#8221;images\/pl.png&#8221; ALT=&#8221;Polish&#8221; WIDTH=&#8221;16&#8243; HEIGHT=&#8221;11&#8243; BORDER=&#8221;0&#8243;&gt;&lt;\/A&gt;<\/p>\n<p>I developed this by hand, and the test site now has an extra four translation buttons, which is a bit of a pain. So I had a look to see if there are any plugins,<\/p>\n<h4>Plugins<\/h4>\n<p>I found these articles,<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><a href=\"https:\/\/www.wpbeginner.com\/showcase\/9-best-translation-plugins-for-wordpress-websites\/\">9 Best WordPress Translation Plugins for Multilingual Websites<\/a>\u00a0from wpbeginner, who have always been good in the past.<\/li>\n<li><a href=\"https:\/\/blog.hubspot.com\/website\/best-language-translation-plugins-for-wordpress\">https:\/\/blog.hubspot.com\/website\/best-language-translation-plugins-for-wordpress<\/a>, from blog.hubspot.com by Amanda Sellars, she does 11, but repeats the popular ones from wpbeginner.<\/li>\n<li><a href=\"https:\/\/wordpress.org\/plugins\/gtranslate\/\">gtranslate, a wordpress plugin<\/a>, 5 Stars, 300,000+ installs and over 2300 reviews, and is recommended by wpbeginner<\/li>\n<li><a href=\"https:\/\/wordpress.org\/plugins\/google-website-translator\/\">Google website translator<\/a> also looks interesting; a one off fee published by someone, or a collective called prisna.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><script> function maxdisplay() {\n  var x = document.getElementById(\"questions\");\n  if (x.style.display === \"none\") {\n    x.style.display = \"block\";\n  } else {\n    x.style.display = \"none\";\n  }\n}\n<\/script><br \/>\n<button  onclick=\"maxdisplay()\">Show Old Code<\/button><\/p>\n<div id=\"questions\" style=\"display: none;\">\n<h4>Version 1<\/h4>\n<p>Here is code (old) to implement a page translation to French by Google Translate<\/p>\n<pre>...\r\n&lt;A HREF=\"http:\/\/www.google.com\/translate_c?hl=en&amp;langpair=en%7Cfr&amp;u=http:\/\/test.davelevy.info\/index.html\"\r\n\u00a0\u00a0 TITLE=\"Fran\u00e7ais, la traduction par Google\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;IMG SRC=\"images\/fr.png\" ALT=\"France:\" \r\n        WIDTH=\"16\" HEIGHT=\"11\" BORDER=\"0\"&gt;\r\n&lt;\/A&gt;\r\n<\/pre>\n<p>And Babelfish does Italian, &#8230;.<\/p>\n<pre id=\"line1\">&lt;<span class=\"start-tag\">A <\/span><span class=\"attribute-name\">HREF<\/span>=\"http:\/\/66.163.168.225\/babelfish\/translate_url_content?.intl=us<span class=\"error\" title=\"\u201c&amp;\u201d did not start a character reference. (\u201c&amp;\u201d probably should have been escaped as \u201c&amp;amp;\u201d.)\">&amp;<\/span>lp=en_it<span class=\"error\" title=\"\u201c&amp;\u201d did not start a character reference. (\u201c&amp;\u201d probably should have been escaped as \u201c&amp;amp;\u201d.)\">&amp;<\/span>trurl=http%3A%2F%2Ftest.davelevy.info%2F\"\r\n<span id=\"line94\"><\/span>     <span class=\"attribute-name\">TITLE<\/span>=\"Italiano, traduzione da babelfish\"&gt;\r\n     &lt;<span class=\"start-tag\">IMG<\/span> <span class=\"attribute-name\">SRC<\/span>=\"images\/it.png\"\r\n          <span id=\"line95\"><\/span><span class=\"attribute-name\">ALT<\/span>=\"Italian\" <span class=\"attribute-name\">WIDTH<\/span>=\"16\" <span class=\"attribute-name\">HEIGHT<\/span>=\"11\" <span class=\"attribute-name\">BORDER<\/span>=\"0\"&gt;\r\n&lt;\/<span class=\"end-tag\">A<\/span>&gt;<\/pre>\n<p>Babelfish&#8217;s website, that I use has gone away and the web site interface is too hard to find, however here&#8217;s the implementation of the old test site code, the Italian one don&#8217;t work. However this code could be implemented in the footer of single.php, or maybe in a menu.<\/p>\n<\/div>\n<hr \/>\n<h3>Stylist<\/h3>\n<p>The stylist implementation just involved capturing some of the bullet item i.e. list item within a class name, so that the local stylist rules could be applied. I was looking at Stylist because the of the Neverwinter Vault but that&#8217;s gone now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page was originally set up in 2015 when looking at using REST to invoke web site translations. My original code is still available on the test web site and below but Google &amp; Babelfish have changed their APIs. I decided to refactor the page in 2022. The changes in the google API have been&#8230;<\/p>\n","protected":false},"author":1,"featured_media":6416,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_share_on_mastodon":"0"},"categories":[111,3],"tags":[851,112,1184,850,911,849],"class_list":["post-2575","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud","category-technology","tag-babelfish","tag-cloud-2","tag-deprecated","tag-google-translate","tag-technology","tag-webdesign"],"share_on_mastodon":{"url":"","error":""},"jetpack_featured_media_url":"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2022\/03\/flags-w1024.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/2575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/comments?post=2575"}],"version-history":[{"count":2,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/2575\/revisions"}],"predecessor-version":[{"id":2578,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/2575\/revisions\/2578"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media\/6416"}],"wp:attachment":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media?parent=2575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/categories?post=2575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/tags?post=2575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}