Theme’s text domain & language.PO file not working

After inspecting your theme, this is what I came up with. I’ve taken the liberty to include Ruben’s solution as well to make this answer as complete as possible.

There are several problems here:

Number 1. load_theme_textdomain( 'transparent', get_template_directory_uri() .'/languages' );

should be:

    function transparent_theme_setup() {
    load_theme_textdomain( 'transparent', get_template_directory() . '/languages' );

    $locale = get_locale();
    $locale_file = get_template_directory() . "/languages/$locale.php";

    if ( is_readable( $locale_file ) ) {
        require_once( $locale_file );
    }
}
add_action( 'after_setup_theme', 'transparent_theme_setup' );

Language files must always be called in the after_setup_theme hook.

Also get_template_directory_uri()

should be

get_template_directory().

Number 2. <?php echo __("thanks-for-visiting", 'transparent'); ?>.

is totally wrong. Firstly, never ever use " in a translation string. The translator doesn’t recognize it and will skip that string. Always use '. Secondly, don’t echo a string with echo. _e should be used in this case. So your string should look like this:
<?php _e('thanks-for-visiting', 'transparent'); ?>.

Number 3. There is no text domain set in your stylesheet’s header. Add Text Domain: transparent just above the closing */ in your header. So your header should look like this:

/*
Theme Name: Transparent
Theme URI: http://websitetechnology.com.au/category/themes/transparent/
Description: Transparent responsive two-column theme.
Tags: green, two-columns, right-sidebar
Author:Steven Doig
Author URI:http://tech.doig.com.au
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Version:1.2
Text Domain: transparent
*/

Number 4. The naming for your po file is wrong, so should your mo file be. somename-en_US.po and somename-en_US.mo is only used by plugins. Themes use only the filenames en_US.po and en_US.mo

Number 5. Your po file is wrongly created. To create a po file with poedit, follow the following steps. Please note that my poedit is in Afrikaans.

Open poedit and select the option to create a catalogue. The following screen will appear

image1.

Fill in the required fields as shown.

Now click “Sources paths” tab and complete as shown. Use . in the “Paths” field if your language file is in the main directory, and use .. if the language file is in a folder like language

image2

Now click the “Sources keywords” tab and fill in as shown.

image3

Now save the poedit file as en_US.po in your languages file. It is important that you save the po file directly in the location where it must be, otherwise it will not work. Poedit will now search and add all strings for translation to your po file. A mo file is automatically created when the po file is saved.

At the end, your po header should look like this

 msgid ""
msgstr ""
"Project-Id-Version: Transparent v1.2\n"
"POT-Creation-Date: 2014-03-12 16:25+0200\n"
"PO-Revision-Date: 2014-03-12 16:28+0200\n"
"Last-Translator: Pieter Goosen <[email protected]>\n"
"Language-Team: Transparent <[email protected]>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.5\n"
"X-Poedit-KeywordsList: gettext;gettext_noop;__;_e;_n:1,2;_x:1,2c;_ex:1,2c\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: ..\n"

For further reading, check this tutorial. It really helped me when I started on translations. Hope this helps.

Leave a Comment

tech