Archive for March, 2010

How to localize WordPress pages

Friday, March 12th, 2010

Sometimes I am surprised by the power of WordPress. To be honest, I don’t like the style of coding done in WordPress. All that global functions… bwah. But on the other hand, people managed it somehow to create a flexible and extensible product. I don’t know how it is to make huge projects with WordPress, but for my little own blog it gave me everything I need so far. This time I wanted to create localized pages, which have been served by PIWI before. In order to reduce the overhead for my website, I decided to use WordPress as one and only the system. It is updated in regular periods and PIWI is not. It has tons of plugins and PIWI not. However, PIWI is more to my taste of professional software and I will continue to use it on more enterprise developments.

Localization does not work out of the box in WordPress. But the concepts in WordPress allow to use a combination of custom fields and themes to make this work. I refused to translate all my blogposts and for only pages it is very straightforward.

First I created my pages in the wordpress pages section. In the Custom fields I used a new meta key named “language” and put as value “de” or “en” for german or english.

Custom fields for localization

I couldn’t use the Pages Widget, because I need to generate my navigation out of the selected language. Not to conflict with my current implementation I duplicated my current theme and used the preview function to work on it (on a live system, which is a really great feature :-) for prime time programming). I should mention that I created two pages, one for each language, only stating that the language has been changed.

Next step was to include the language flags in my theme (header.php in my case). I linked the flags to my newly created “language switched” pages. Additionally I have added the param language=de (or en for english) to the link. My complete link for the german language is as follows:

http://www.grobmeier.de/deine-sprache-wurde-umgestellt?language=de

Ok, I am now able to link between the languages. In my header.php I wrote this:

session_start();
include(TEMPLATEPATH . '/grobmeier-session.functions.php');

I started the session myself – it seems WordPress frontend doesn’t use session at all. In the included new php grobmeier-session.functions.php I create a function for storing my language key. This function has been stolen and modified from PIWI:

function grobmeier_getUserLanguage() {
    $supported[] = 'de';
    $supported[] = 'en';

   if (isset ($_GET['language'])) {
       if (in_array($_GET['language'], $supported)) {
            $_SESSION['language'] = $_GET['language'];
       }
    }

    if (!isset ($_SESSION['language'])) {
        $_SESSION['language'] = 'en';
    }
    return $_SESSION['language'];
}

Now I just need to generate the navigation. I’ll do this with a prepared function of wordpress. On the correct place in my header.php I wrote:

$args = array(
'meta_key' => 'language',
'meta_value' =>  grobmeier_getUserLanguage());
wp_list_pages( $args );

As you might see, the navigation is build on the user language setting. And that’s all – you’ll deliver localized versions of your pages from now on. I should mention this works with 2.9.2 and I think earlier versions too. You just need to create pages with the correct custom field setting.

Apache Log4PHP graduated!

Thursday, March 11th, 2010

Good news! The Apache Incubator Log4PHP project graduated as subproject to the Apache Logging project. This is really a big step forward! The next days I will try to push the real work behind a graduation forward, moving webpages and svn and such. After that move we’ll continue with a new small release. Cheers all!

New Java Magazin article

Friday, March 5th, 2010

Javamagazin 04 2010In the new Java Magazin is a printed version of my review of “Apache Geronimo 2.1: Quick Reference” available. It’s only a short entry to this Java Magazin, but for the sake of completeness I listed it also in my publications section. However, this one comes with a DVD – on it are all Java Magazines from 2009. Thats pretty nice to have, esspecially because I didn’t have the time to read all the issues last year.

Log4PHP tries to graduate to Apache Logging

Tuesday, March 2nd, 2010

The past year has been very well for Log4PHP. As you might have noticed, the Log4PHP 2.0.0 release is out. There has been some good feedback so far. Some users even contributed smaller bugfixes or the trace level which wasn’t in the API before. Besides that, there is a good activity on the mailinglist and there are at least 3 active committers. In other terms: time to graduate an bring out Log4PHP from the temporary incubator project :-)

Now Log4PHP needs to succeed 3 votes. One for the Log4PHP team to vote for graduating; one for Apache Logging to accept the podling as a subproject. And finally – after the first two have succeeded – a vote on the incubator list to release the podling to its final destination.

The first two votes are already running and it looks very good so far. Votes need to be open another day then the next step can be done. For those who are interested – there is a detailed document about graduation available.

Let’s see how it works out – I think everything could be in place in quite less time, maybe the next two or three weeks.

  • Recent Posts

  • Tags

  • Categories

  • Archives

  • Wave Notifications

    Download Adobe Wave now!

    This application requires Adobe® AIR™ to be installed for
    Mac OS or Windows.




Feeds