Easiest way to create localization POT file for WordPress theme?

On my themes I’m starting to get a lot of requests for localization capabilities… and because I’m just a silly American that only speaks English, it’s never occurred to me to learn how to do it. I’ve been reading about it on a bunch of different websites (WordPress Codex, neettuts, and a bunch of other stuff I found on Google) and I’m getting a little confused.

I have gone through my entire theme and made all outputted strings that the users see like this: __(“Text here…”).

But now I’m having trouble figuring out how to create a POT file, which is the final step now if I understand correctly?

I’ve found many different ways of creating POT files and I’m not having much luck. Do you guys have any tips on this? What is the easiest way to create a POT file for your theme? How do you guys do it?

Probably you know about it, but this sounds pretty easy and straightforward, what doesn’t work out for you?

Hi themeblvd! Check this Hope this will help.

Ah yes I really want to know this too! I’ve done the same thing as you, making all my outputted strings __(“stuff”) compatible. I just want to know an easy way to convert the rest of the (static) text in my themes. Anyone have any tips or tuts?

Thanks! :slight_smile:

Hi themeblvd! Check this Hope this will help.

Thanks man! Really useful! :slight_smile:

Hi themeblvd! Check this Hope this will help.

Ahw great! Thanks for the link :slight_smile:

This also helped me:

http://www.deluxeblogtips.com/2010/04/how-to-localize-themes-in-wordpress.html

This also helped me:

http://www.deluxeblogtips.com/2010/04/how-to-localize-themes-in-wordpress.html

:slight_smile: this is the same man. Only one notice guys use TEMPLATEPATH instead of TEMPLATE_PATH. For me TEMPLATE_PATH doesn’t work

This also helped me:

http://www.deluxeblogtips.com/2010/04/how-to-localize-themes-in-wordpress.html

:slight_smile: this is the same man. Only one notice guys use TEMPLATEPATH instead of TEMPLATE_PATH. For me TEMPLATE_PATH doesn’t work

I use my own themepath just because that problem, the get_template_directory() is relative to the PARENT theme.

So on functions:

define('THEME_PATH', get_template_directory());

load_theme_textdomain( ‘my_theme’, THEME_PATH . ‘/languages’ );

$locale = get_locale();

$locale_file = THEME_PATH . “/languages/$locale.php”;

if ( is_readable( $locale_file ) ) require_once( $locale_file );

Then i use poedit for the .po and .mo files.

This also helped me:

http://www.deluxeblogtips.com/2010/04/how-to-localize-themes-in-wordpress.html

:slight_smile: this is the same man. Only one notice guys use TEMPLATEPATH instead of TEMPLATE_PATH. For me TEMPLATE_PATH doesn’t work

Oh, didn’t noticed :D! Sorry…

Thanks for all the responses… So this is what I’m having some issues with…

In reading different resources online (including the link your guys shared), there seems to be a confusion between translating a WordPress theme and getting a theme ready to be translated.

I think the link you guys are sharing is more for someone who is translating a theme into a language… even though the author writes as he intended it to be a theme author selling a theme. So this is a little confusing…

When you use the Poedit software, .mo and .po files are generated for you. I downloaded one of Kailoon’s themes to see how he does it as an example, and he includes the .mo file and .po file in his theme (which are the same as what Poedit software are generating for me).

BUT, looking at WordPress’s twenty-ten theme, there is a single .pot file included (and NO .po or .mo files). So, now I’m wondering what exactly is the different between a .po and a .pot file is?

I found this link which states that:

POT – Portable Object Template. This is the file that you get when you extract texts from the application. Normally, you send this file to your translators.

PO – Portable Object. This is the file that you receive back from the translators. It’s a text file that includes the original texts and the translations.

If I’m understanding correctly, the .pot file is what I should be including with my theme, so a translator can then take that into their software and translate the theme.

So, to me this backs up further that I want to do it the way twenty-ten theme does and I should have a .pot file, but I can’t figure out how to create that with the Poedit software? Or what the best way to create that is?

In looking through the twenty-ten theme’s .pot file, it seems that it’s formatted the same as the .po file I’m generating from Poedit sofware. So, I’m wondering if I can simply rename the .po file to .pot?

Don't worry about .pot or .po. Just wrap all your theme's translation messages into _e() or __(), as applicable. Next, copy your theme into poedit/bin/ directory.

Next, run poedit > Choose New Catalog > Configure project Info. In "Paths", choose ./ as base path and ..(double dot) as Paths. Next inside "Keywords", delete available ones and add _e and __(two underscores).

Your .po file will be created with ../ as base directory. Assuming that you will put your .mo file in themes/yourtheme/languages folder. Once you save the file, a .mo file will be created upon compilation. For now, this .mo file will be of no use to your buyers. BUT, when they will open your .po file > translate the messages > compile them into .mo file. THAT .mo file will be useful for them.

To summarize, you just need to provide a .po file. Users will rename then according to their language.. say en_US or de_DE and compile them with their messages.

Edit: By the way, congrats on getting FEATURED :) :)

SaurabhSharma said

Don't worry about .pot or .po. Just wrap all your theme's translation messages into _e() or __(), as applicable. Next, copy your theme into poedit/bin/ directory.

Next, run poedit > Choose New Catalog > Configure project Info. In "Paths", choose ./ as base path and ..(double dot) as Paths. Next inside "Keywords", delete available ones and add _e and __(two underscores).

Your .po file will be created with ../ as base directory. Assuming that you will put your .mo file in themes/yourtheme/languages folder. Once you save the file, a .mo file will be created upon compilation. For now, this .mo file will be of no use to your buyers. BUT, when they will open your .po file > translate the messages > compile them into .mo file. THAT .mo file will be useful for them.

To summarize, you just need to provide a .po file. Users will rename then according to their language.. say en_US or de_DE and compile them with their messages.

Edit: By the way, congrats on getting FEATURED :) :)

I just released a theme following your steps exactly. Now, I have a few customers saying they can’t translate the theme. I tried doing it myself to test it, and I’m unable to translate it as well. I provided a .po file with my theme, and I thought that was all I was supposed to do, but maybe I missed something? How so I actually translate the .po file using poedit? Can you provide any info on this?

Thanks!

You’ll also need to include this in your functions.php, making sure to change the ‘contempo’ to your domain and the /lang to reflect your folder path.

// Localization Support
load_theme_textdomain( 'contempo', TEMPLATEPATH.'/lang' );
 
$locale = get_locale();
$locale_file = TEMPLATEPATH."/lang/$locale.php";
if ( is_readable($locale_file) )
    require_once($locale_file);

Then you’ll use snippets like this throughout:

<?php _e('Featured Property', 'contempo'); ?>
SaurabhSharma said

Don't worry about .pot or .po. Just wrap all your theme's translation messages into _e() or __(), as applicable. Next, copy your theme into poedit/bin/ directory.

Next, run poedit > Choose New Catalog > Configure project Info. In "Paths", choose ./ as base path and ..(double dot) as Paths. Next inside "Keywords", delete available ones and add _e and __(two underscores).

Your .po file will be created with ../ as base directory. Assuming that you will put your .mo file in themes/yourtheme/languages folder. Once you save the file, a .mo file will be created upon compilation. For now, this .mo file will be of no use to your buyers. BUT, when they will open your .po file > translate the messages > compile them into .mo file. THAT .mo file will be useful for them.

To summarize, you just need to provide a .po file. Users will rename then according to their language.. say en_US or de_DE and compile them with their messages.

Edit: By the way, congrats on getting FEATURED :) :)

Where’s the bin folder on a mac? I can’t figure out how to do this on a mac.

This first step in that explanation is not needed at all and makes the whole thing seem a little more complicated than it is.

Next, copy your theme into poedit/bin/ directory.

Don’t do that. Just leave your theme right where it is.

Here’s the steps with some screenshots as I do it.

  1. Open the poEdit program, and create a new Catalog.

  1. A dialog popup comes up. Enter in your theme info. I usually just put the name of the theme, but you can put as much info as you want.

  1. Click the “Paths” tab. Assuming you plan to save this in a folder called “lang” or “language” that’s one level deep in your theme, you’d put in “…/” for the path as I’ve done in the screenshot.

  1. Click the “Keywords” tab. You want to put it in just the two gettext elements we use in our WP themes, which I’ve done in the screenshot. “__” and “_e”

  1. So, now you’ve put in your project info, paths, and keywords. Click “okay” and poEdit will show you a save dialog box. Save the file directly in your theme’s “lang” folder (or whatever you called it). When you save it you can name it either theme-name.po or default.po or whatever.po.

Now that you’ve saved it there inside your theme on your computer, poEdit knows to take the relative path you entered in the “Paths” tab previously and apply it relatively to where you just saved the file.

  1. Right after you click “Save” poEdit should process for a second and return all the translatable strings from your theme to you like this:

  1. Now this is the part I always used to screw up because noone ever told me…

After you’re presented with this screen of all your translatable strings, hit “Save” again.

(The reason for this is because the first time you saved it, you were saving a blank file. Now poEdit has gone through and found all the strings, so you need to save again, or else you will be giving your buyers a blank file.)

ThemeBlvd said

This first step in that explanation is not needed at all and makes the whole thing seem a little more complicated than it is.

Next, copy your theme into poedit/bin/ directory.

Don’t do that. Just leave your theme right where it is.

That’s cool. Just tested it. :slight_smile:

All this time I had to copy files to the bin folder because I was using the base path as “.” and Paths as “…/”

Removing the Base path solves the problem of relative path.

theirs also glotpress which is a web interface to create them

also a commercial plugin called wpml, which you can translate via the wp admin panel, with no need to edit .po files

i have done all this steps… but --> :frowning: My face says it all

i understand i also need to add this line into the head ??

<?php load_theme_textdomain(my_theme_name);?>

i need to integrate a hebrew translation into my template.

  1. is there a need to to a “deafult” english .mo / .po
    or the one named he.po / he.mo should do it?

  2. where i can find a list of languages?

  3. any possible reason my text arnt being translated automaticly
    on a hebrew installation wordpress? have i forgot to define
    something?

p.s tried this in my functions:

// Localization Support
load_theme_textdomain( 'blue_article_demon', TEMPLATEPATH.'/lang' );

$locale = get_locale();
$locale_file = TEMPLATEPATH."/lang/$locale.php";
if ( is_readable($locale_file) )
    require_once($locale_file);

And also this

$lang = TEMPLATE_PATH . '/lang';
load_theme_textdomain('theme_textdomain', $lang);

help anyone ?

My Apologies for the re-post… got here to late to edit… i was missing
this for a plugin

$my_translator_domain   = MY_TEXT_DOMAIN;
$my_translator_is_setup = 0;
function fabfunc_setup(){
  global $my_translator_domain, $my_translator_is_setup;
  if($my_translator_is_setup) {
    return;
  }
  load_plugin_textdomain($my_translator_domain,
       PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)),
       dirname(plugin_basename(__FILE__)));
}

So i am all good… thanks for the gr8 info