{"id":1183,"date":"2014-09-14T16:45:50","date_gmt":"2014-09-14T16:45:50","guid":{"rendered":"https:\/\/keithdevon.com\/?p=1183"},"modified":"2014-09-14T16:45:50","modified_gmt":"2014-09-14T16:45:50","slug":"using-variables-wordpress-translation-functions","status":"publish","type":"post","link":"https:\/\/keithdevon.com\/using-variables-wordpress-translation-functions\/","title":{"rendered":"Using variables with WordPress translation functions"},"content":{"rendered":"<p>Today I wanted to be able to pass a custom field variable to the WordPress localization (l10n) functions. The custom field is a select field, so all the possible outputs are known.<\/p>\n<p>WordPress uses PO and MO files for translations. These are generated by scanning the site for <code>__()<\/code> and <code>_e()<\/code> functions, with a programme such as Poedit, to generate the list of translatable strings.<\/p>\n<p>Using variables in these functions, like <code>_e($output, 'text-domain')<\/code>, causes a problem. When the scan is done, there is no string to add to the PO file.<\/p>\n<p>In my case, because the outputs are known, I created a file called <code>manual-translations.php<\/code>, included it from my <code>functions.php<\/code> file and added the translatable strings like:<\/p>\n<p>[code]__( &#8216;String one&#8217;, &#8216;text-domain&#8217; );<br \/>\n__( &#8216;Second string&#8217;, &#8216;text-domain&#8217; );<br \/>\n__( &#8216;Stringy cheese&#8217;, &#8216;text-domain&#8217; );[\/code]<\/p>\n<p>Now when the site is scanned it picks these up and I can now add the translations in Poedit.<\/p>\n<p>Hope that helps someone out there!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I wanted to be able to pass a custom field variable to the WordPress localization (l10n) functions. The custom field is a select field, so all the possible outputs are known. WordPress uses PO and MO files for translations. These are generated by scanning the site for __() and _e() functions, with a programme [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[81,12],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/posts\/1183"}],"collection":[{"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/comments?post=1183"}],"version-history":[{"count":0,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/posts\/1183\/revisions"}],"wp:attachment":[{"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/media?parent=1183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/categories?post=1183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/keithdevon.com\/wp-json\/wp\/v2\/tags?post=1183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}