Half Price Tuesdays

Half Price Tuesdays helps you find the best deals near you!

(or something like that, but for now that’ll be good enough)

If you’d like to help test the site please sign up here:

http://www.halfpricetuesdays.co.za/

that is all.

Advertisements

Not dead, just busy…

3 People have asked me in the last few hours if I was dead… Nope, I’m just busy…. but in the mean time please help me pick a logo. I’m not giving credit to the designers yet because I don’t want to bias the results.

Feel free to design a better one if you feel you can… Yes, that’s a challenge.

Microsoft Gold Certification means nothing…

Many years ago I worked for a company who was a Microsoft certified partner. This was a long long time ago and I must admit that back then I was quite impressed by the fact that they were Microsoft certified partners… until I started working there. Redmond hands out certifications like a crack whore hands out cheap tricks — indiscriminately and to anyone who’s willing to pay fifty bucks.

Needless to say, this morning I was reading my gmail when I saw an ad for a “Microsoft GOLD Certified Development Partner based in Cape Town” and being the sado-masochist I am I clicked on the link… it was one of those /showpage.aspx?page_id=36 sort of sites. Ugly, but not necessarily dodgy. I put an apostrophe in the page id to see if they were cleaning their inputs and behold:

Line 166: Octigon.Octane8.Containers.Page tempPage = this._page;
Line 167:
Line 168: while (tempPage.Id != 1)
Line 169: {
Line 170: if (tempPage.Parent.Id == 1)

This shows that the site is vulnerable to sql injection… which, while not necessarily implying that the site can be hacked, does imply that, given enough time, you probably could hack it or at least cause some damage. The page also pukes out all kinds of file paths and stuff that would be useful if you were trying to do them harm.

The point here is this. Why is a web development company who are obviously bad web developers Microsoft Gold Certified?

The answer can only be that Gold Certification means absolutely nothing.

L10n, gettext, php5 and Afrikaans

I’ve been playing with the concept of creating a multilingual site and after polling the experts I started toying with php’s implementation of gettext. What a ball-ache.

Ok, so some things you need to know before we start.

  • L10n stands for Localisation or Localization… the abbreviation is therefore obvious due to the words length and different spellings.
  • gettext is a GNU standard. I shouldn’t need to explain why standards are cool, but needless to say, there are plenty of tools to make using gettext a lot easier than a “roll-your-own” solution.
  • The PHP implementation of gettext is good when it’s working. But when it’s not working it’s like a scorned girlfriend — it will *not* tell you what is wrong. You have to figure it out yourself.
  • Your solution might not be *exactly* the same as mine because gettext relies on system locales, which in turn are structured differently on pretty much every linux distribution… having said that I’m sure the stuff you’ll read here will get you going.

Firstly, why gettext? Besides the fact that it’s a standard, gettext is good because:

  • gettext’s database files (.mo) are indexed and compiled.
  • PHP’s implementation is written in C or C++ by programmers who are probably better than you and I at writing efficient searches.
  • The gettext domain (your strings) are cached by the implementation so it really is quite fast.

Ok, so let me run through quickly how it’s meant to work, starting with some code

<?
setlocale(LC_ALL, 'af_ZA');
bindtextdomain('messages', '/var/www/myapp/locale');
textdomain('messages');
echo gettext("Hello World!");
?>

Line for line:

  • setlocale tells php which locale to use; in this example I’m using af_ZA (Afrikaans)
  • bindtextdomain tells php which domain to look for and where your gettext locale folders are. A “domain” is really just a collection. In this case we’re arbitrarily calling it “messages”.
  • textdomain is telling php which domain to use from now on. (seems redundant I know but I assume you might be able to bind multiple text domains)
  • gettext will look to see if it can find a translation for the locale you set earlier (af_ZA) for this index. gettext’s index is the original string in the original language. In this case we originally used the phrase “Hello World!”. If the locale can’t be found or there isn’t a translation for this index in the locale, gettext will return the original language — in this case “Hello World!”.
  • What is really important to note at this point is that there are a million or so variations of this code on the Internet. This is the stripped down version that works fine under PHP5 and Apache2.

Next we have to create our locale directory structure. This is what it looks like:

/locale
    /af_ZA
        /LC_MESSAGES
            messages.po (You'll create these later)
            messages.mo (You'll create these later)

Obviously you would create one per language you are wanting to support. I therefore have one for en_ZA and one for af_ZA.

Next we need to create our .po file. The .po file is the unindexed, uncompiled “language” file. Basically it has human readable plaintext in it. If you had a hoard of translators working for you you would send them your .po file/s, which they would add their translations to and then send back.

The important stuff in a .po file is:

msgid "Hello World!"
msgstr ""

Now, the cool thing about using gettext is that there are tools to generate a messages.po file from .php files automatically. The following command will scan all php files looking for references to gettext and will generate messages.po file for you.

xgettext -n *.php

The next step is to copy your messages.po file into your LC_MESSAGES folders. Once you’ve copied them you can make the change to the af_ZA one.

msgid "Hello World!"
msgstr "Hello Wêreld!"

Next you need to compile both your messages.po files by running the following command in the respective directories. This command will output a binary, indexed messages.mo file.

msgfmt messages.po

Once you’ve done that you should be able to rerun your code and it should give you the afrikaans version… although it won’t because here’s what you don’t get told. gettext will only work for locales it recognises, and even though you selected South Africa when you installed your ubuntu, it still doesn’t know what Afrikaans is. Enter the myriad of confusion solved, as usual, by one simple command.

locale-gen af_ZA

This will, if you’re on a newish debian-ish box, enable the af_ZA locale and then, after restarting Apache (remember it caches), your app should be speaking Afrikaans fluently.

cna.co.za fixes themselves…

A while ago I was moaning about how CNA’s website didn’t want to let me on with my never-before-heard-of-crazy-combo of Ubuntu and Firefox… It seems they’ve fixed that problem which probably also fixed the “telling Google to go away” problem.

http://www.cna.co.za and http://www.google.co.za/search?q=cna.co.za

I wonder if that had anything to do with me? They never said anything. Probably because I’m such a big bully.

ath.

I should blog more… GeekDinner 5 – Eccentric Eggplant

GeekDinner 5 - Eccentric EggplantNo really, I should. I have a really good blog post chomping at the proverbial bit… Even Adrian would approve. (probably not, but a man can have hope)

Anyway, it’s GeekDinner time again, and this one, “Eccentric Eggplant” promises to be a good’un for two reasons… Firstly, I might finally be able to get Derek the marketing guru to do his now – way – too – over – hyped – and – yet – not – delivered – on speil – about – the – old – world – vs – new – world – advertising, and secondly, but most certainly not leastly, my friend Jennie will be talking about her experiences in the world of game development. Yes, she’s a real girl, and yes, she’s a real game developer currently working on something to do with Maya and the Wii. (I like how that rhymes with Maya The Bee).

Sign up here http://wiki.geekdinner.org.za/wiki/Cape_Town_November_2007

Later, Aligator!

j.