Feb 02

What is the difference between a .po and .pot file?

Here’s a quote from the GNU gettext utilities page:

After preparing the sources, the programmer creates a PO template file. This section explains how to use xgettext for this purpose.

xgettext creates a file named domainname.po. You should then rename it to domainname.pot. (Why doesn’t xgettext create it under the name domainname.pot right away? The answer is: for historical reasons. When xgettext was specified, the distinction between a PO file and PO file template was fuzzy, and the suffix ‘.pot’ wasn’t in use at that time.)

So that’s it. It’s the same file, with a different name. Just thought I’d mention that, considering how much time I pissed off trying to find the answer!

[edit]
It looks like Wordpress sees this a little differently. the POT file, the “PO” Template, is the raw output from the xgettext, untranslated. the PO file is the text-editable and edited pot file with the translations. the MO file is built with msgfmt (among others) and is what is actually used by php’s gettext.

  • Facebook
  • Share/Bookmark
Jan 29

I’m beginning a new effort these days, that of internationalisation and localisation of the php coding I’ve been doing lately.

GNU ‘gettext’ Utilities

These docs for gettext are C-oriented, but the associated tools such as xgettext are easily used by PHP, so let’s not get too excited about the C.
And I’m going to assume you have installed GNU’s gettext on your system.  I’m pretty sure it arrives by default with your ubuntu or other linux installation.  Mac and Windows you’re going to have to find for yourself :-)

Edited:  download GetText for Windows here

There’s also a lot of emacs crap in this doc, which I’m also going to ignore.  We’re going to use tools like poedit, gtranslator for what we need … coming posts.

on my ubuntu 9.10 box the following command installs the php-gettext stuff in /usr/share/php/php-gettext

sudo apt-get install php-gettext

and includes these three files:

  • gettext.inc
  • gettext.php
  • streams.php

I’m not going to deal with the internals of these files here in this post.

What I do is copy these into my working project somewhere, say in a subdirectory named “library”, “lib”, “i18n” … etc. I’m going to call it ./library/i18n just for this.

.po, .pot, .mo files – what are these?

http://www.gnu.org/software/gettext/manual/gettext.html#Files

That’s about all for now, sorry I couldn’t be more helpful in this post.  This is just the setup stuff I’ve done for my new entry into this world of Internationalisation (i18n), Localisation (l10n), and Native Language Support (NLS) — see Concepts.

  • Facebook
  • Share/Bookmark
Dec 11

I’m learning how to write wordpress plugins, I’ve said that before here in my blog.  One of the ways I’m doing it is by downloading/installing existing plugins I see out there which may be interesting to me – they provide actions and capabilities to do things I want my plugin(s) to do … on a more general scale.

One thing I have noticed – almost all of these plugin authors do NOT use classes in their design.  Their .php files are full of functions, most of the time written without the

if (!function_exists('my_function')) {
  function my_function() {
    // and so on
  }
}

or

if (!function_exists('my_function')) :
  function my_function() {
    // and so on
  }
}
endif;

How do they expect to avoid naming collisions?  If they have to have a function by a certain name which probably exist in some other plugin developer’s file somewhere, then even if they use this !function_exists business they’ll end up getting the other author’s behavior for that function.

Why don’t these people just use classes! I know I’m coming at this from the java world where you have to use classes for everything, and there’s packaging to avoid naming collisions, but still – this seems like an obvious question to me. Do the modern php programmers have no experience with a real class-oriented language?

Here’s a silly example I’m doing. I have a plugin I’m developing to allow Zlatina’s web administrators to deal with their database of students and contacts. It’s called Bcc DBManager.
I created a subdirectory wp-content/plugins/bcc-dbmanager, with a file named bcc-dbmanager.php … duh. I want to hook into the activate_${plugin} (see this link for an explanation of that). Here’s a partial …

<?php
/*
Plugin Name: Bcc DBManager
Description: Blah blah
*/

$bccDBManager = new BCC_DBmanager();
add_action('activate_bcc-dbmanager/bcc-dbmanager.php',                  
         array(&$bccDBManager,'_activate'));

class BCC_DBmanager {  
  function _activate()  {    
    // do stuff    
    $this->very_common_function_name();
    // or this way
    BCC_DBmanager::very_common_function_name();
  }
  ## function with a very common name
 function very_common_function_name() {
    // do stuff
  }
}
?>

How hard is that? I certainly don’t know much about plugin development at this point. But I would have to describe the use of functions rather than class instances and methods as Code Smell.

[Edit] Since I wrote this post I found this link on Nerdaphernalia: Use Classes in your WordPress plugins to increase code portability and reduce name conflicts

  • Facebook
  • Share/Bookmark
Tagged with:
Dec 04

After you’ve installed apach2, php5, mysql, etc, you test it with http://localhost and all you get is this “It Works!” crap.  You can actually create an index.php page that looks like:

<?php
  phpinfo();
?>

and you can actually type in http://localhost/index.php and get your phpinfo page coming out.  But it seems nowhere in the docs can you find out how to get apache2 to recognize index.php as the first page to deliver.

So, I found out where, finally.  In your WAMP environment there’s only the http.conf file, you look for the DirectoryIndex, and move index.php or insert “index.php” to the front of the line.  In this ubuntu 9.10 LAMP setup, where the hell is the file?

/etc/apache2/mods-available/dir.conf

That’s where it is.  open the file, it looks like this after your normal lamp setup in this environment

<ifmodule mod_dir.c>
 DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</ifmodule>

Notice the “index.php” somewhere in the DirectoryIndex list … move that to the front of the list as in

<ifmodule mod_dir.c>
 DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</ifmodule>
  • Facebook
  • Share/Bookmark
Tagged with:
Nov 28

ConfiguringNetBeansProjectForWordPress
Since I am working on wordpress plugins and themes, using a NetBeans environment on Ubuntu 9.10 … I just thought I’d pass along that link.  You can use this setup to debug your wordpress project without affecting your actual wordpress blog on your website – of course, we’re assuming you have your own server with your own ip address … whether remote hosted or on a server in your own home.

WordPress Plugin Development: Beginner’s Guide

I also purchased this eBook, for €19.99

Now remember, you want to be developing on localhost if you can.  You can always upload your “finished” plugin to your site wherever it is.  I have a windows box for www.hagelnx.com, I have a linux box for developing my plugins.  Do NOT waste your time trying to develop on windows if you can help it.  The apache2-php-mysql .. LAMP setup for ubuntu, just as an example, works really well with apt-get installing all the modules you need.  All the config files are updated without your having to edit them, both php ini files and apache2 ini files.

  • Facebook
  • Share/Bookmark
Nov 26

So I've cranked up the linux box for sandbox development of wordpress themes and plugins.  Sounds interesting, doesn't it? Well, for a hard-core java programmer moving back into PHP doesn't immediately seem like a step up, but here we are, eh dear reader?  And this may be where the business is in Bulgaria these days …. Wordpress is a perfectly good Content Management System (CMS), and It's likely that skills in this CMS will prove useful in this country at this time. I installed NetBeans, the latest version.  Installed apache2, php, all that good stuff with apt-get and aptitutude.  And finally I went to http://netbeans.org/kb/docs/php/wordpress-screencast.html for a quick tutorial on how to setup a wordpress plugin project. Good stuff, eh?  Let's see where this goes. If you're interested, I can write a post on the setup procedures which got me here.  Just try and get XDebug and all this running on windows, pee-yew.

  • Facebook
  • Share/Bookmark
Tagged with:
Nov 13

I’ve been getting an amazing number of comments on some of my blog entries coming from Russia – and they’re in the Russian language in Cyrillic.  I expect there’s some kind of rss-feed going on, I do have several subscribers to this blog who’s personal data indicates their home page is in .ru domain or their email address comes from a .ru domain.
Using the Vistor Maps and Who is Online plugin I’m able to see where my visitors are coming from, at least the country where their IP address is located.  Most of the .ru commentors are actually coming from Latvia … from Preili Latvia in particular.

Maybe they’ve put my site on some social networking location in Russia?  How is it they’re able to write comments to my blog without appearing in my google analytics report?  Why aren’t they writing comments in english, my language?  Are my blog entries being translated to Russian where these people are reading them, and if so how good a translation is it?

Since so many of the comments coming from Russia are spam I’ve had to place the .ru domain in my Aksimet filter, but just as many seem to be honest comments coming from regular people.  So I go through the comments flagged as spam this way, and on occasion will approve them for the post.  I go to translate.google.com to see what they are saying, and to have a look at the website they claim as home page.
Often some innocuous comment such as “good post” comes with a link to some porno or warez site, so I just delete those.

But a they are in Russian, I have to translate all of them this way.  So I’m going to try something new.  I’ve done a google search for “wordpress google translate plugin“, and have arrived at the following two plugins (links open in new window):

It looks like the Global Translator is more fully developed, and able to use 4 different translator engines (at least claimed on the plugin site), so this is the one I’m going to try.
There is a pro version available, but let’s see how well this plugin works on a site such as mine, with these Russian-language and cyrillic charset comments.
….
Ok, I’ve installed the global translator and I have to admit, it doesn’t do what I want in this case.  I only want to be able to translate the comments, not the entire website.  The Global Translator has lots of nice options, and it might be useful for my readers who come from those various countries to get a translation of my website in their language, but hey – than can do what I’ve been doing, go to translate.google.com and enter the URL and see the translation.
So I’m going to deactivate that plugin for now, and try the Google Ajax Translator.
….
Very nice.  This does what I want.  I’m not offering translation of entire pages or posts, I only want to see for myself what these Russian comments are saying.  So we’ll see how it works.

And if any of you commenting on my blog entries would like to tell me – where are you seeing my blog?  Are my entries translated into your language, is this why you’re writing comments in Russian?  I’d like to read your comments about these questions.

  • Facebook
  • Share/Bookmark
Tagged with:
Nov 04

How to send email in WordPress using Gmail’s SMTP server

I was googling around for a way to set up my php sendmail stuff to work, using my account at gmail.  This blogger at that link has found the answer for me!

I’m using a wampserver, so I had to be sure to have the php_openssl extension turned on.  I’ve used gmail’s smtp server settings for other email clients so I’m vaguely familiar with how to set that up.

I’m going to be developing a wordpress installation for Zlatina, for her school.  I’m looking for education-oriented themes, and I really needed a way for her to manage an email newsletter and notification kind of thing.  The first thing I needed was this plugin and this information.

Thanks very much to Sudar.

  • Facebook
  • Share/Bookmark
Tagged with:
preload preload preload