{"id":14793,"date":"2012-02-13T08:54:16","date_gmt":"2012-02-13T13:54:16","guid":{"rendered":"http:\/\/info.template-help.com\/?p=14793"},"modified":"2017-02-22T04:42:07","modified_gmt":"2017-02-22T09:42:07","slug":"wordpress-template-localization","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/wordpress-template-localization.html","title":{"rendered":"WordPress. Template localization"},"content":{"rendered":"<p>\r\n<p>This tutorial shows how to create a multilingual Word Press template and how to change WordPress theme language. <\/p>\r\n<p><!--more--><\/p>\r\n<h3>Define language files root<\/h3>\r\n<p>First of all we need to load the textdomain. In other words we need to define the directory with the language files. <\/p>\r\n<p>In your WordPress installation directory go to the folder<strong> &quot;\/wp-content\/themes\/your_theme\/&quot; <\/strong> and open <strong>&quot;functions.php&quot;<\/strong> file. <\/p>\r\n<p>Add new function:<\/p>\r\n<pre class=\"brush:php\">\r\n\tload_theme_textdomain( 'theme_name', TEMPLATEPATH . '\/languages' );\r\n<\/pre>\r\n<p>Where:<\/p>\r\n<ul class=\"post-list\">\r\n<li><strong>theme_name<\/strong> &#8211; the name of the directory with your theme files (wp-content\/theme_name);<\/li>\r\n<li><strong>TEMPLATEPATH<\/strong> &#8211; root to the template files. Global variable, no need to change it.<\/li>\r\n<li><strong>\/languages<\/strong> &#8211; name of the directory with the language files. It is located in your theme folder. <\/li>\r\n<\/ul>\r\n<h3>Using language variables<\/h3>\r\n<p>If you want to insert some text content directly into your theme files please use the following rules<\/p>\r\n<p>Do NOT use construction as follows: <\/p>\r\n<pre class=\"brush:php\">\r\n&lt;?php echo 'your_text'; ?&gt;\r\n<\/pre>\r\n<p>for text content.\r\n<\/p>\r\n<p>To add multilingual content into your template files please use the following construction:<\/p>\r\n<pre class=\"brush:php\">\r\n&lt;?php _ e('your_text', 'theme_name'); ?&gt;\r\n<\/pre>\r\n<p>You can also use the following one<\/p>\r\n<pre class=\"brush:php\">\r\n&lt;?php echo '&lt;h2&gt;' . __('your_text', 'theme_name') . '&lt;\/h2&gt;'; ?&gt;\r\n<\/pre>\r\n<p>Please pay attention to the parameter <strong>&#8216;theme_name&#8217;<\/strong> in the language strings. It is the same parameter that has been used in the <strong>&#8216;load_theme_textdomain&#8217;<\/strong> function<\/p>\r\n<h3>Creating language files<\/h3>\r\n<p>Now we need to create the language <strong>.MO<\/strong> and <strong>.PO<\/strong> files. <\/p>\r\n<p>The easiest way to create these files is the <strong>PoEdit<\/strong> application. It can be downloaded from the official website at <a href=\"http:\/\/www.poedit.net\/download.php\" target=\"_blank\">www.poedit.net<\/a><\/p>\r\n<p>Download the PoEdit application and open it. From the top menu click <strong>File > New Catalog <\/strong><\/p>\r\n<ol>\r\n<li>At the <strong>&#8216;Project&#8217;<\/strong> tab input your project details<\/li>\r\n<li>At the <strong>&#8216;Path&#8217;<\/strong> tab input <strong>.\/<\/strong> into the the <strong>&#8216;Base path&#8217;<\/strong>\r\n<p><a href=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2012\/02\/wp-translate-1.jpg\"><img loading=\"lazy\" src=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2012\/02\/wp-translate-1-300x257.jpg\" alt=\"\" title=\"wp-translate-1\" width=\"300\" height=\"257\" class=\"aligncenter size-medium wp-image-14794\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2012\/02\/wp-translate-1-300x257.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2012\/02\/wp-translate-1.jpg 381w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>\r\n<\/li>\r\n<li>At the &#8216;Keywords&#8217; tab add new keywords <strong>&#8216;__&#8217;<\/strong> and <strong>&#8216;_e&#8217;<\/strong><br \/>\r\n<a href=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2012\/02\/wp-translate-2.jpg\"><img loading=\"lazy\" src=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2012\/02\/wp-translate-2-300x257.jpg\" alt=\"\" title=\"wp-translate-2\" width=\"300\" height=\"257\" class=\"aligncenter size-medium wp-image-14795\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2012\/02\/wp-translate-2-300x257.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2012\/02\/wp-translate-2.jpg 381w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>\r\n<\/li>\r\n<\/ol>\r\n<p>Click <strong>OK<\/strong>. PoEdit will automatically scan files in your theme directory, and list all strings. Your work now is just translate them. After that, save file in format language.po (ie. pt_BR.po, de_DE.po, etc.) in the \/lang\/ directory.<\/p>\r\n<h3>Set Default WordPress language<\/h3>\r\n<p>There are two ways of setting default language for your WordPress installation. <\/p>\r\n<p>1. The first way of settings the default WordPress language is download the localized version<\/p>\r\n<p>2. Open <strong>wp-config.php<\/strong> file from the WordPress installation root and define the language:<\/p>\r\n<pre class=\"brush:php\">\r\ndefine ('WPLANG', 'en_US');\r\n<\/pre>\r\n<h3>How to change theme localization<\/h3>\r\n<p>1. Open WordPress installation directory<\/p>\r\n<p>2. Go to <strong>&#8216;wp-content\/themes\/your_theme\/languages&#8217;<\/strong> folder<\/p>\r\n<p>3. Rename the existing files to the localization name listed in <strong>wp-config.php <\/strong>file. <\/p>\r\n<p><strong>For example<\/strong> if your<strong> wp-config.php<\/strong> file contains <strong>define (&#8216;WPLANG&#8217;, &#8216;en_US&#8217;);<\/strong> language definition. Your language files should be called <strong>en_US.mo<\/strong> and <strong>en_US.po<\/strong><\/p>\r\n<p>4. Open the language files with PoEdit application<\/p>\r\n<p>5. Select the line you want to edit and in the bottom area input the line translation<\/p>\r\n<p><a href=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2012\/02\/wp-translate-3.jpg\"><img loading=\"lazy\" src=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2012\/02\/wp-translate-3-300x211.jpg\" alt=\"\" title=\"wp-translate-3\" width=\"300\" height=\"211\" class=\"aligncenter size-medium wp-image-14796\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2012\/02\/wp-translate-3-300x211.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2012\/02\/wp-translate-3.jpg 777w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\r\n<p>The language files can also be modified using the code editor like Notepad++ or Adobe Dreamweaver. <\/p>\r\n<p><strong>For example<\/strong> you opened the .mo file with notepad++, you can see the following:<\/p>\r\n<pre>#: ..\/archive.php:8\r\n  #, php-format\r\n  msgid &quot;Monthly Archives: &lt;span&gt;%s&lt;\/span&gt;&quot;\r\n  msgstr &quot;&quot;\r\n<\/pre>\r\n<p>To change the string translation type the translation value inside the <strong>msgstr<\/strong> quotes<\/p>\r\n<p>Save the file and refresh browser page to see your changes. <\/p>\r\n<p>Thank you for your attention. In case of any issues with our template feel free to contact our team using the online help desk at <em><strong>http:\/\/esupport.template-help.com\/index.php?_m=tickets&amp;_a=submit<\/strong><\/em><strong><\/strong><\/p>\r\n<\/p>\r\n<p><!--more--> <\/p>\r\n<p><!--more--><\/p>\r\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create a multilingual Word Press template and how to change WordPress theme language.<\/p>\n","protected":false},"author":2,"featured_media":14797,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[728],"tags":[2564,540,702,911,767,766,2405],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/14793"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=14793"}],"version-history":[{"count":0,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/14793\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media\/14797"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=14793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=14793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=14793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}