{"id":1149,"date":"2007-05-23T17:58:04","date_gmt":"2007-05-23T14:58:04","guid":{"rendered":"http:\/\/www.mummila.net\/nuudelisoppa\/index.php\/?p=1149"},"modified":"2011-07-28T17:03:30","modified_gmt":"2011-07-28T14:03:30","slug":"language-changing-quicktag-for-wordpress","status":"publish","type":"post","link":"https:\/\/mummila.net\/nuudelisoppa\/2007\/05\/23\/language-changing-quicktag-for-wordpress\/","title":{"rendered":"Language changing quicktag for WordPress"},"content":{"rendered":"<p>I&#8217;ve modified my quicktags.js to include a button for fast adding of <code>&lt;span lang=\"<i>language of choice<\/i>\"&gt;...&lt;\/span&gt;<\/code> pairs. Gotta keep those 0.03 voice browser users happy, you know! (All right, I pulled that figure out of my hat. Truth is, I don&#8217;t know if any of my blogs have any readers using text-to-speech synthesizers. But I&#8217;m opting on the safe side and trying to make most of my content accessible for such users by tagging it with the appropriate lang= parameters.)<\/p>\n<p>I was hoping to whip these modifications up into a plugin to be dropped into any modern WordPress installation, but it seems that documentation on how to make plugins add quicktags is non-existent, and I couldn&#8217;t make it work on my own. Every plugin author seems to have their own way of doing it and yet I was unable to find anything that would work for me.<\/p>\n<p>So I&#8217;ll have to settle for making my changes to quicktags.js known here.<\/p>\n<p>I begin by adding these lines into quicktags.js:<\/p>\n<blockquote>\n<pre><code>edButtons[edButtons.length] =\r\nnew edButton('ed_lang'\r\n,'lang='\r\n,''\r\n,'&lt;\/span&gt;'\r\n,'l'\r\n);\r\n\r\nfunction edSpanLang(myField, i) {\r\n\tlangSelect = document.getElementById('edLang');\r\n\tlangLang = langSelect.options[langSelect.selectedIndex].value;\r\n\tif (!edCheckOpenTags(i)) {\r\n\t\tedButtons[i].tagStart = '&lt;span lang=\"' + langLang + '\"&gt;';\r\n\t\tedInsertTag(myField, i);\r\n\t}\r\n\telse {\r\n\t\tedInsertTag(myField, i);\r\n\t}\r\n}<\/pre>\n<p><\/code><\/p><\/blockquote>\n<p>Next, I change the edShowButton() function to include one additional <code>else if<\/code> -branch, like so:<\/p>\n<blockquote><p><code><\/p>\n<pre>else if (button.id == 'ed_lang') {\r\n  document.write('&lt;input type=\"button\" id=\"' + button.id\r\n  + '\" accesskey=\"' + button.access + '\" class=\"ed_button\"\r\n  onclick=\"edSpanLang(edCanvas, ' + i + ');\" value=\"'\r\n  + button.display + '\" \/&gt;\\\\n&lt;form&gt;\\\\n&lt;select id=\"edLang\"&gt;\\\\n&lt;option\r\n  value=\"en\"&gt;en: English&lt;\/option&gt;\\\\n&lt;option value=\"de\"&gt;de:\r\n  German&lt;\/option&gt;\\\\n&lt;option value=\"fi\"&gt;fi: Finnish&lt;\/option&gt;\\\\n&lt;option\r\n  value=\"sv\"&gt;sv: Swedish&lt;\/option&gt;\\\\n&lt;\/select&gt;\\\\n&lt;\/form&gt;');\r\n}<\/pre>\n<p><\/code><\/p><\/blockquote>\n<p>(Sheesh, it's a pain to try and format code inside a WordPress post. I tried to make sure there are no typos but if something breaks after applying these changes, I probably missed one or two. You'll have to use your own eyes and skillz in that case.)<\/p>\n<p>Adding further languages into the drop down list is as easy as adding another <code>&lt;option value=\"<i>your two-letter <a href=\"http:\/\/www.loc.gov\/standards\/iso639-2\/php\/code_list.php\">language code<\/a> of choice<\/i>\"&gt;<i>your two-letter language code again<\/i>: <i>your plain English language name<\/i>&lt;\/option&gt;\\n<\/code> pair in between the <code>&lt;form&gt;...&lt;\/form&gt;<\/code> block. As a Finn, I find the four languages listed in my example to be sufficient for most cases. (Now that I've said it, I realize that I should add French there as well. There's at least as much use for it as there is for German.)<\/p>\n<p>Here's my current (<del datetime=\"2007-06-22T08:06:33+00:00\">24.5.2007<\/del> <del datetime=\"2007-10-19T12:23:06+00:00\">22.6.2007<\/del> 19.10.2007) <a href='http:\/\/mummila.net\/nuudelisoppa\/files\/2007\/05\/quicktags.js'>quicktags.js<\/a> for reference. Note that it has three buttons for my <a href=\"http:\/\/mummila.net\/nuudelisoppa\/index.php\/?page_id=682\">Post Changelog Plugin<\/a>: history, edit and at. Without the plugin, the code they produce will not work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve modified my quicktags.js to include a button for fast adding of &lt;span lang=&#8221;language of choice&#8221;&gt;&#8230;&lt;\/span&gt; pairs. Gotta keep those 0.03 voice browser users happy, you know! (All right, I pulled that figure out of my hat. Truth is, I don&#8217;t know if any of my blogs have any readers using text-to-speech synthesizers. But I&#8217;m [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9387,29],"class_list":["post-1149","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-blog","tag-hacks-tweaks"],"_links":{"self":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/1149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/comments?post=1149"}],"version-history":[{"count":2,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/1149\/revisions"}],"predecessor-version":[{"id":3008,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/1149\/revisions\/3008"}],"wp:attachment":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/media?parent=1149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/categories?post=1149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/tags?post=1149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}