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.

The mark of a true DJ…

Kitty’s party was on Saturday night. It was inside the Simons Town Naval Base. Two things struck me here.

1. Why do we spend so much any money on naval vessels for South Africa and then let people like me say “I’m here for the party” and drive right in… and I mean *in*! On our way out we got lost and ended up staring at huge friggen submarines just sitting there while we drove past. These things are big. Not USA nuclear submarine big, but still big enough to put a little frog in your throat as you run through what you’re going to say when stopped by 10 men with semi automatic assault rifles asking why the hell you are driving around “secure” parts of the naval base in your unofficial looking Polo.

2. You get two types of DJs in the world. Those whose names you recognise and those that have custom wooden boxes to carry the 400 cd’s they take to every gig. As a tribute to these legends of the underworld I present my top 10 ways to spot an underworld DJ.

1. Has home-made wooden boxes to carry the 400 CDs he carefully selected for this gig.

breathless.jpg2. Not only does he have the Kenny G Breathless CD, but he chooses to display it proudly as if it was some limited edition Vinyl of the Beatles before they were cool.

3. He will arrange all his gear out on the biggest table he can find and will have brought all manner of unnecessary equipment (FM Tuner etc) to the party… Because everyone knows, second to having a shit-ton of CDs with you, the next most impressive thing a DJ can do is have lots and lots of gear.

4. The speakers will be home made. The amplifier might be too but I couldn’t bring myself to look. There might also be an impressive array of home made or cash converters purchased “lights”.

5. He also has the latest Timberland.

6. Instead of playing a well know Tina Turner track, he will chose to bust out the one obscure Tina track that you have never heard, despite that road trip to Durban when you were 7 when your mom went through that Tina Turner phase.

7. He will play rave music… Not stuff that old people label as “rave music”, but actual, real deal rave music that the ex-ravers in the room recognize and start breaking out in a cold sweat over.

8. He will play Mambo Number 5 and the old lady in the wheelchair will wave her hands in the air like she just doesn’t give a fuck any more care.

9. He will have a helper, usually a younger relative who looks like he gets beaten up at school. This kid will be wearing his sunday best with his shirt tucked in. He will usually be found frantically searching through the 400 CDs looking for the Coolio – Gangstas Paradise CD… Despite the fact that this CD predates his birth. This is also known as child abuse. There is a small part of this child’s mind that is being infected with the idea that this is cool… that this is how he could make his millions and get the chicks. Child A-B-U-S-E.

10. Despite the shockingly random choice of music the people will be too drunk to notice and be shaking their whatnots on the dance floor.

Kitty it was totally rad seeing you and I can’t wait to spend more time with you before you go home.

j.

Things that make me smile…

Ever have one of those weeks when you just can’t stop smiling because the world is just being so damn inspirational?

Ok, so here’s my list of things I am currently happy about:

minicards.jpg1. My Moo Cards arrived: You have no idea how friggen happy I am with them. Moo is an inspirational company and yes, I would even consider living in London to be able to work there and learn from the Moo’inistas. Since everyone wanted to know, they cost $19.99 (R145) for 100 cards. Next time you see me ask for a moo card. I’ve even made my first Moo friend.

2. Civil Twilight made my day: So a couple of days ago I got a message on facebook to say that there was a CD waiting for me in Hout Bay… Apparently I was on the “list” of complementary CDs… getting a free CD is much more of a big deal when there are probably only a few in the country at the moment. Thanks boys. Much Appreciated! The album is awesome, my only fear is that I might wear out the CD. Check out their other video.

Civil Twilight Press Pics3. Mix two of my favourite things…: If I was into American football I could have called this one “mix three of my favourite things” because one of Civil Twilight’s songs, ‘Human’ will be featured on this Sunday’s special Superbowl episode of ‘House’ guest starring Academy Award winning actress Mira Sorvino. House is one of my favourites… so is Civil Twilight. Mira is ok. 😉

4. An awesome GeekDinner: The 6th GeekDinner took place in the cosy Sloppy Sams. I was MC for the evening and really enjoyed it. About 70 of us crammed into the tiny little restaurant and had an absolute blast. Thanks to everyone who helped out.

5. Friends: I guess it goes without saying that friends are important, but recently I’ve been finding my friends to be more than just important, they’ve been critical. Sometimes your friends can give you the kick in the bum you need to get your ducks in a row… Other times they just need to be there to make you laugh. Some friends are their to guide you, others to chide you and still others just to make you feel good about yourself. Tonight I’m going to see kitty! My long lost kitty from London!… Super stoked.

6. Synchronicity: A while back I was looking for a maid/domestic worker/housekeeper whatever you want to call them. I asked around the apartment building I live in and someone suggested an awesome woman called Nokulunga who’s been my angel for the past few months. I can’t tell you what a pleasure it is to come home to a clean apartment every friday. Anyways, the reason I’m mentioning this is because she’s looking for somewhere to work on mondays. She comes highly recommended.

7. Last but not least: As some of you may know, I’ve been seeing someone recently. Anything I say here will be dripping with cheese and I’d rather not put you all through that. Maybe I’ll just say yay!

What did you learn in the last 10 years…

Watching a documentary on education this morning it struck me that I’ve been out of school for 10 years; I matriculated in ’98. Considering that I spent 10 years in “big school” I began to ask myself an interesting question.

Have I learnt more or less in the past 10 years since leaving school than in the 10 years I spent in school.

I guess the answer depends on what your definition of knowledge is. I’m trying to think of things I learnt in school. It’s a pathetic list. Jan Van Riebek in 1652, Dutch British Settlers 1820. Tightly packed molecules make a solid. Obviously there’s more, but it’s all anecdotal, incomplete or just plain incorrect.

I think the most important thing I’ve learnt since I left school is the joy of learning… That inate part of every human being’s soul that yearns for knowledge… that sponge that your school spent 10 years abusing with limited facts, half truths and parrot fashion learning.

I think I spent the better part of 3 years after I left school learning how awesome learning is again. Getting back that feeling of awesomeness that you had when you learnt a new word at 7 years old. The feeling of completeness that you got when you finished your first “big book”.

Perhaps I learnt everything I needed to know in those first 2 years… A to Z and how they make words. Everything else was so badly taught that I’ve spent the following ten years patching all the holes and erasing all the untruths.

I know one thing for sure: I’m going to teach my kids the stuff they’ll never learn in school, starting with the joy of learning. That, and they’ll have a huge map of the world stuck up on their bedroom wall from the day they are born until the day they leave my house. This planet is a incomprehensibly huge place and the biggest mistake you can make in life is to get too caught up in the insular little envelope that is your school and the 100 or so people who have an influence in your life.

j.

Douglas Adams talking about The Internet 9 years ago…

Reading this reminds me how flipping awesome Douglas Adams was and how incredibly tragic it is that he’s not here with us any more, guiding us like a storytelling shaman, through this crazy mixed up world we call home.

This piece first appeared in the News Review section of The Sunday Times on August 29th 1999.

A couple of years or so ago I was a guest on Start The Week, and I was authoritatively informed by a very distinguished journalist that the whole Internet thing was just a silly fad like ham radio in the fifties, and that if I thought any different I was really a bit naïve. It is a very British trait – natural, perhaps, for a country which has lost an empire and found Mr Blobby – to be so suspicious of change.

But the change is real. I don’t think anybody would argue now that the Internet isn’t becoming a major factor in our lives. However, it’s very new to us. Newsreaders still feel it is worth a special and rather worrying mention if, for instance, a crime was planned by people ‘over the Internet.’ They don’t bother to mention when criminals use the telephone or the M4, or discuss their dastardly plans ‘over a cup of tea,’ though each of these was new and controversial in their day.

Then there’s the peculiar way in which certain BBC presenters and journalists (yes, Humphrys Snr., I’m looking at you) pronounce internet addresses. It goes ‘www DOT … bbc DOT… co DOT… uk SLASH… today SLASH…’ etc., and carries the implication that they have no idea what any of this new-fangled stuff is about, but that you lot out there will probably know what it means.

I suppose earlier generations had to sit through all this huffing and puffing with the invention of television, the phone, cinema, radio, the car, the bicycle, printing, the wheel and so on, but you would think we would learn the way these things work, which is this:

Read the rest of this article here

2 weeks of search terms

I finally did something that I really should have done a long long time ago. I installed Google Analytics on my personal blog. This is just short of 2 weeks worth of data.

A few things that suprised me.

  1. I didn’t expect to be getting this much search engine traffic
  2. I am suprised how many people search for things Computer Mania, Computicket and Nonna Lina and end up reading my blog. If you take Computer Mania as an example, every day almost 2 people search for “Computer Mania”, no doubt looking for a phone number etc, and end up reading my rant about their crappy service.
  3. I come up for some pretty weird search terms like “what to do when your computer takes a crap“. My answer to that is simple. Install an operating system that doesn’t poo on itself. My suggestion is Linux.
  4. I get some “interesting” traffic ending up at my penis enlargement email spam collection. Most of it has to do with either fetishes or worried men looking for answers to the “does size matter” question. Perhaps I’ll update that page with the search terms… I’ll keep this post clean.
  5. Did Alan Levin break his ankle?

The Results:

Computer Mania Related 26
Computicket Related 18
Alix Linux Related 10
Penis Size Related: 8
Ubuntu Gutsy Related 7
nonna lina 6
arbitrary user 5
cna.co.za related: 4
civil twilight human 2
krugmans grill 2
two faced bitch 2
aslam khan 1
neil garb 1
never had a bad day 1
pascal dornier 1
skye aspden 1
adsl provider for george frogfoot 1
alan levin breaks ankle 1
alcohol promotion girls 1
amphibian 1
animated picture of a boerewors roll 1
arbitrary 1
arbitrary meaning 1
average restaurant mark up 1
bad come in threes 1
bad luck 1
buy computer 1
buying a laptop computer 1
chilli chocolate steak 1
codecaine.co.za 1
cold calling free wine give me home address 1
computer resell 1
disturbing the peace 1
first aid mr muscle 1
food guru 1
funny picture of bush running in special olympics 1
futureshop reginal manager + complaints 1
ideas of setting up a new restaurant 1
mame arcade cabinet +south africa 1
mattress for exercise condense density 1
new ideas to do a restaurant 1
ok,please give me ideas to make money 1
pascal dornier 1
pictures inside the womb 1
pictures of physically retarded children 1
redhill simonstown 1
restaurant it system domain class ideas 1
restaurant review 1
restaurant review jobs 1
restaurant reviews 1
sharpeville massacre 1
shit 1
shit can this computer 1
shit to do on computer 1
user reviews 1
vodashop hout bay close times 1
vpxl 1
what is computing so shit 1
what to do when your computer takes a crap 1
where does luck come from 1
restaurant review costs 0

Civil Twilight releases Human as a free download (or you can pay)

human.jpgMany many years ago I used to organise gigs for a few kids from Hout Bay… (Ok, I was a kid at the time too, but it makes this story sound more awesome)

Anyway, a few years ago they went to Los Angeles and recorded an album. The album (which is awesome) has been out for a while now but they’ve finally decided to do the right thing and release it as a free download or a $5 download or a $10 CD. You can download it for free or buy it here.

This shouldn’t surprise you unless you’ve been living under a rock for the last few months. Radiohead launched their new album as a potentially free download a few months ago (Well, you could pay whatever you felt was fair)… critics said nobody would buy something they could get for free and the eventual sales numbers would reflect it. Well, the sales numbers reflected it… just not the way the critics had expected. Number 1 in the US and the UK.

Tom Yorke even said they’d made more money from the digital (paid for) downloads of In Rainbows than all their other digital downloads to date. To understand what that means you need to know how many albums Radiohead has and how many million songs they’ve probably sold on places like iTunes… The difference is that unlike previous albums where the proceeds were divided up between Apple (iTunes), various record labels, publishers and distributors, oh, and that band called Radiohead — this time it was all theirs.

The bottom line here is really the question:

What’s worth more: Having a million people listening to your music or money in the bank?

Luckily if you’re Radiohead you already have both… Let’s see if Civil Twilight can do a bit of both.

Oh, they have an awesome video here

The positive power of a brand and a strong community

About 5 days ago we officially announced the upcoming GeekDinner… We’d left things a bit last minute because of everyone getting back to work late in Jan etc.

Anyways, cut to the chase, its been 5 days and we already have our quota of 70+ people on the wiki. As usual we had our original stalwarts; the addicts who added themselves 2 months ago when the new dinner’s page was created (before we had a date or venue), but we’ve picked up about 40 people in 4 days. (Not counting the maybes)

Capetonians are crap at arriving at things they say they’ll go to so we have quite a high last minute drop out rate; sometimes as high as 20% against the number on the wiki. It’s fine because that allows us to go over the venues allotted 70 seats. We’re currently on 72 “confirmed” with 13 “maybes”. I think we can safely let the “confirmed” number get to about 90 before we create a “waiting list”. ie. If you haven’t already done so, go sign up now.

Anyway, the point I’m trying to make is that we have a brand and a community that’s growing and making it easier and easier for us to put these things together. We’re always looking for people to lurk/participate on the planning mailing list, so if you feel like lurking, and perhaps maybe helping with some stuff, join the list.

Long weekend

Mo FireEggs Haust Ed… Long weekend. Totally Awesome though.

  • Drinks with Tania and Co
  • Sushi (and Beer) with Jonathan H. and Graham.
  • Drinks with Kira, TRACY PAYNE, Helene and Ex G2Aers.
  • Free beer, food and fire dancing at a winefarm in Franshoek.
  • Breakfast at Arnolds.
  • Canal Walk for too many hours.
  • Braai at Lourens’.
  • Interspersed with lots of Flight Of the Concorde “Rhymenocerous”

Totally Ossum.

Check out the pics.Â