{"id":14910,"date":"2015-05-20T05:01:36","date_gmt":"2015-05-19T19:01:36","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=14910"},"modified":"2015-05-20T14:54:12","modified_gmt":"2015-05-20T04:54:12","slug":"php-gettext-internationalization-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-gettext-internationalization-primer-tutorial\/","title":{"rendered":"PHP Gettext Internationalization Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/gettext\/locale\/de_DE\/LC_MESSAGES\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Gettext Internationalization Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/gettext\/locale\/de_DE\/LC_MESSAGES\/gettext-81of.jpg\" title=\"PHP Gettext Internationalization Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Gettext Internationalization Primer Tutorial<\/p><\/div>\n<p>Our (Mac OS X laptop) local <a target=_blank href='https:\/\/www.mamp.info\/' title='MAMP Apache\/PHP\/MySql web server landing page'>MAMP<\/a> web server is an Apache\/PHP\/MySql web server.  In this environment you can find out a lot with some PHP code as per &#8230;<\/p>\n<p><code>&lt;?php <a target=_blank href='http:\/\/php.net\/manual\/en\/function.phpinfo.php' title='PHP phpinfo() method information'>phpinfo();<\/a> ?&gt;<\/code><\/p>\n<p> &#8230; and if, in doing this, you find a reference to the <a target=_blank href='http:\/\/php.net\/manual\/en\/book.gettext.php' title='Human Language and Character Encoding Support'>&#8220;gettext&#8221;<\/a> Human Language and Character Encoding Support functionality existing, you are a lucky candidate to introduce some language translation internationalization logic to your PHP code.<\/p>\n<p>We followed a lot of the advice of the very useful <a target=_blank title='Localizing PHP web sites using gettext' href='http:\/\/mel.melaxis.com\/devblog\/2005\/08\/06\/localizing-php-web-sites-using-gettext\/'>link<\/a> (thanks) to create two pieces of PHP called &#8230;<\/p>\n<ul>\n<li><a target=_blank title='localization.php' href='http:\/\/www.rjmprogramming.com.au\/PHP\/gettext\/locale\/de_DE\/LC_MESSAGES\/localization.php_GETME'>localization.php<\/a><\/li>\n<li><a target=_blank title='get_text.php' href='http:\/\/www.rjmprogramming.com.au\/PHP\/gettext\/locale\/de_DE\/LC_MESSAGES\/get_text.php_GETME'>get_text.php<\/a><\/li>\n<\/ul>\n<p> &#8230; that combined, along with the installation of the <a target=_blank title='Poedit' href='http:\/\/www.macupdate.com\/app\/mac\/22905\/poedit'>Poedit<\/a> (for our Mac laptop) application that you can use to create (or clone, like we did with an existant WordPress *.po file) the ascii *.po files that get &#8220;compiled&#8221; into *.mo files facilitating the translation pairs used to map words from the local language to the language you translate to &#8230; in our case de_DE (German for Germany), as per (the incomplete) <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/gettext\/locale\/de_DE\/LC_MESSAGES\/messages.po_GETME\" title=\"messages.po\">messages.po<\/a>.<\/p>\n<p>Lo and behold our word &#8220;Home&#8221; (in <a target=_blank title='get_text.php' href='http:\/\/www.rjmprogramming.com.au\/PHP\/gettext\/locale\/de_DE\/LC_MESSAGES\/get_text.php_GETME'>get_text.php<\/a>) got translated to &#8220;Startseite&#8221; (as the best suggestion by &#8220;Poedit&#8221;) via the *.po excerpt &#8230;<\/p>\n<p><code><br \/>\n# ...<br \/>\n#: wp-includes\/post-template.php:1148<br \/>\nmsgid \"Home\"<br \/>\nmsgstr \"Startseite\"<br \/>\n# ...<br \/>\n<\/code><\/p>\n<p> &#8230; so that, with this thinking under your belt, you can concentrate on translations and *.po editing via &#8220;Poedit&#8221; to create internationalization functionality for your PHP websites.  Sounds great to me, and if you haven&#8217;t clicked the picture above here to view the tutorial slides go for it <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/gettext\/locale\/de_DE\/LC_MESSAGES\/\" title='Click picture'>here<\/a>!<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d14910' onclick='var dv=document.getElementById(\"d14910\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=internationalization\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d14910' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Our (Mac OS X laptop) local MAMP web server is an Apache\/PHP\/MySql web server. In this environment you can find out a lot with some PHP code as per &#8230; &lt;?php phpinfo(); ?&gt; &#8230; and if, in doing this, you &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-gettext-internationalization-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[85,1557,620,1560,1562,725,744,1561,932,1558,1559,997,1301,1319,1456],"class_list":["post-14910","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-apache","tag-gettext","tag-internationalization","tag-language","tag-locale","tag-mac-os-x","tag-mamp","tag-nac","tag-php","tag-phpinfo","tag-poedit","tag-programming","tag-translation","tag-tutorial","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/14910"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=14910"}],"version-history":[{"count":10,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/14910\/revisions"}],"predecessor-version":[{"id":14922,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/14910\/revisions\/14922"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=14910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=14910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=14910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}