Posts Tagged ‘Wordpress’

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.

Wavediver: An Adobe Wave API

Friday, January 8th, 2010

Readers of my blog maybe have already noticed it: Jason found out, that somebody has taken my code, removed the copyright stuff and uploaded it to the WordPress directory. I was quite surprised – the content-thief is telling on his blog that he had two weeks holiday while he came across Wave and implemented this plugin. I mean, what the f***? Are people really thinking that nobody will notice that theft in the case of beta software? I just can say: don’t use tecinfor-wave. This is outdated code and the distributor didn’t write it – I doubt he can help in error cases.

But everything has its good sides. I decided to put my development on that plugin more into public and created a new google code project: Wavediver. You can find the original WordPress plugin there. I will try to update the API and make it more usable. At the moment it’s a little bit, well, ugly :-) Let’s hope that it will reach the status to be included in the PIWI framework later.

Already included is a cli.php file, which enables you to send Adobe Wave message from the command line, just with: php -f cli.php. That can help testing.

If there is anybody who wants to join up – don’t hesitate.

Adobe Wave WordPress Plugin finished

Tuesday, August 4th, 2009

Well, the term finished is a bit overrated. But I wrote a WordPress plugin which sends a message to your Adove Wave feed, after you have published a blog post. The message will contain the title of your post as text and is linked the latest blog post.

Installation is quite simple: just download the WordPress plugin, unpack it, and upload it via FTP to your blog. You need to store it in the wp-content/plugins folder. Then log into you wordpress installation, choose “Plugins” and activate the “Christian Grobmeier Wave Plugin”. Sorry for the name dudes, but WordPress usually needs something unique and I hadn’t had a name which sounds more cool. Well, you have to deal with it.
Once that is done you need to configure your plugin. This can be done in “Settings / Grobmeier Wave Plugin”. Please provide the topic you want to post to, your wave Username and your Wave password. If you don’t have such things, you’ll probably need a Adobe Publisher Account.

That’s all for the plugin. Once you finished the steps above, WordPress will send notifications to your users when ever you post something.

If you come into unexpected trouble, then please check if you are running WordPress with PHP5. I figured out this morning that my installation was running on PHP4 for a long time… this brought up several syntax exceptions. To be clear: you’ll need PHP5 to run this plugin.

Last thing beeing said: this is licensed with Apache License 2.0. No guarantees, use at own risk.

Your feedback is appreciated. If you have any more questions, drop me some lines too.

  • Categories

  • Recent Posts

  • Tags

  • Wave Notifications

    Download Adobe Wave now!

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




Feeds