PHPDoc to GitHub wiki

About a month ago I came across an interesting question over at StackOverflow.  Emanuele Minotto was asking if anybody knows of any easy way to integrate PHPDocumentor with GitHub’s wiki.  It seemed like a really good idea, so I dug around, but didn’t find anything ready made.  PHPDoc’s manual however suggests that things are possible.  Unfortunately, I’m too busy currently to get involved in it myself, but I am really glad to see that Emanuele didn’t abandon the idea and started the project at GitHub.  If that’s something that you are interested in, I strongly suggest lending a helping hand.  I’m sure there are plenty of people who’d welcome this integration.

spoon.net – run any desktop application on deman

spoon.net – run any desktop application on deman

I haven’t tried it myself yet, but a few people mentioned to me that this is mighty useful for cross-browser testing during web development and design.

Programming fonts

Once a decade or so I get to review my Vim configuration, which also usually brings my attention to all the things surrounding – bash, terminal, etc.  This time around I wasn’t looking for anything in particular, but somehow I stumbled across the Top 10 Programming Fonts.  Of course, this one of those lists that will vary from person to person, but given that I am not particularly into fonts, I thought I’d just try the ones recommended and maybe switch my day-to-day font to something better.

Gladly, these days, trying TrueType Fonts on Linux is really easy.  Many are available directly through package management.  The ones that not, can be simply downloaded into the fonts folder (/usr/share/fonts or  ~/.fonts or whatever your distribution supports).  Trying out the fonts from that article, I arrived to these conclusions:

  • Inconsolata is going to be my font of choice for now.  It’s quite different from everything I’ve been using until now, in particular, it’s much thinner.  But I love how easy it makes distinguishing zeros from upper O’s and ones from lowercase L’s.  Bonus points for being available through yum install levien-inconsolata-fonts.noarch .
  • If Inconsolata weren’t easily available, I’d go with Droid Mono.  Which is available through yum install google-droid-* .  It’s very easy on the eyes, even if it doesn’t differentiate 0/O and 1/l so well.
  • I would have never chosen Monaco – even though it’s easy to try. I find this surprising, as I though Apple were very picking about their fonts.  Maybe they are.  But Monaco is hard on the eyes.  I’ve opened a couple of screen of ugly code and my eyes nearly bled from lack of space and the amount of curvy edges.  To each his own though.
  • Microsoft’s Consolas is a good font and I remember trying it out before.  But given that it’s not that easy to find around and install, I decided to completely ignore it this time.

What’s your favorite font for programming?

Happy Programmer’s Day

My brother reminded me that today is Programmer’s Day, an official holiday and appreciation day for those hundreds of thousands of people who spend their days teaching computers new tricks.  I know that not many people think about it, but I do and I find it totally fascinating, that everything, every tiny little thing that we see on a computer screen is thanks to someone who programmed it in.  Just think about it.

What are you staring at now?  Probably a web browser.  That’s a large and mighty complicated program that was written over a few years by hundreds, if not thousands of programmers.  Your browser runs on top of an operating system, which again was written by many programmers over lengthy periods of time.  The browser, through operating system, communicates with the server that runs my blog.  All those communications go through a number of networking devices (routers, switches, firewalls, load balancers, etc), which run software written by more people.  My server runs Apache web server software.  Which runs PHP software.  Which runs WordPress software.  Which connects to MySQL database.  These are just a few major pieces of software involved in the process.  There are probably thousands of smaller applications that nobody ever thinks of, that still do their job to deliver this content from me to you.  Like TinyMCE editor that I am using inside of WordPress to write this post.  Or like Google search engine that you probably misused to get to this post.

Do you like any video games?  Those are software applications.  How about YouTube videos?  For you to be able to waste time at work this inefficiently, a lot of software had to be written by a lot of people.  Oh, are you working then?  Doing some calculations in Excel or drafting up Word document?  Maybe you are working through some customer data in the CRM application.  All those are software applications too.  They didn’t just grow on trees.  Someone somewhere had to think them up, design them, implement them, and maintain them.

Oh, and do you know what’s even crazier?   Programmers are using software applications created by other programmers.  Operating systems, text editors, compilers, linkers, debuggers, and more!

Software industry is very young.  I’m not sure when was the first program ever written, but, according to Wikipedia, the first theory was proposed by Alan Turing in 1935.  That’s not even 80 years ago.  And if you look around you now, the amount and the complexity of software applications created to date is immense – from operating systems, through games and business applications, to all the things online and mobile.

But that’s just the job, right? All those people were paid for it, right? Wrong! Very wrong!  While many did indeed get paid, there is plenty of contribution from amateurs and enthusiasts.  Those are the people who push the technology, ask hard questions, and try to make the world a better place not necessarily for their own greater income, but out of pure curiosity and for the love of science.

Anyways, I’m getting carried away.  All I wanted to say is that it’s important to pause once in a while, look around, and appreciate what we have and people who brought us all that.  Computer software is not the single most important thing around us, but it is one of those things that we rarely notice, until it breaks.  So, have a thought about what software you use, what role does it play in your life, and how did it get there.  And then, find a programmer and buy him a beer.  Because there is someone somewhere not just using his software, but enjoying and/or depending on it, and not thinking about it.

One last thing I wanted to mention.  Of course, I knew about Programmer’s Day for a while now.  And, of course, I knew that it is an officially recognized holiday in Russia.  But what I didn’t know is that I actually know one of those people who worked to make it an officially recognized holiday.

This particular day was proposed by Valentin Balt, an employee of Parallel Technologies web design company. As early as 2002, he tried to gather signatures for a petition to the government of Russia to recognize the day as the official programmers’ day.

Valentine Balt currently works in FxPro, here in Cyprus.  And we had a few drinks together.  Well done, Valentine!

To all you programmers out there – happy Programmer’s Day.  I wish you faster computers, shorter compile times, fewer bugs, better APIs, clearer specifications, more pull requests and patch submissions, and more appreciative users.  Enjoy!

Managing gettext translations on the command line

I am working on a rather multilingual project in the office currently.  And, as always, we tried a few alternatives before ending up with gettext again.  For those of you who don’t know, gettext is the de facto standard for managing language translations in software, especially when it comes to messages and user interface elements.  It’s a nice, powerful system but it’s a bit awkward when things come to web development.

Anyways, we started using it in a bit of a rush, without doing all the necessary planning, and quite soon ended up in a bit of a mess.  Different people used different editors to update translations.  And each person’s environment was setup in a different way.   All that made its way into the PO files that hold translations.  More so, we didn’t really define the procedure for the updates of translations.  That became a bigger problem when we realized that Arabic has only 50 translated strings, while English has 220, and Chinese 350.  All languages were supposed to have exactly the same amount of strings, even if the actual translations were missing.

So today I had to rethink and redefine how we do it.  First of all, I had to figure out and try the process outside of the project.  It took me a good couple of hours to brush up my gettext knowledge and find some useful documentation online.  Here is a very helpful article that got me started.

After reading the article, a few manuals and playing with the actual commands, I decided on the following:

  1. The source of all translations will be a single POT file.  This file will be completely dropped and regenerated every time any strings are updated in the source code.
  2. Each language will have a PO file of its own. However, the strings for the language won’t be extracted from the source code, but from the common POT file.
  3. All editors will use current project folder as the primary path.  In other words, “.” instead of full path to “/var/www/foobar”.  This will make all file references in PO/POT files point to a relative location to the project folder, ignoring the specifics of each contributor’s setup.
  4. Updating language template files (PO) and building of MO files will be a part of the project build/deploy script, to make sure everything stays as up to date as possible.

Now for the actual code.   Here is the shell script that does the job. (Here is a link to the Gist, just in case I’ll update it in the future.)

#!/bin/bash

DOMAIN="project_tag"
POT="$DOMAIN.pot"
LANGS="en_US ru_RU"
SOURCES="*.php"

# Create template
echo "Creating POT"
rm -f $POT
xgettext \
 --copyright-holder="2012 My Company Ltd" \
 --package-name="Project Name" \
 --package-version="1.0" \
 --msgid-bugs-address="[email protected]" \
 --language=PHP \
 --sort-output \
 --keyword=__ \
 --keyword=_e \
 --from-code=UTF-8 \
 --output=$POT \
 --default-domain=$DOMAIN \
 $SOURCES

# Create languages
for LANG in $LANGS
do
 if [ ! -e "$LANG.po" ]
 then
 echo "Creating language file for $LANG"
 msginit --no-translator --locale=$LANG.UTF-8 --output-file=$LANG.po --input=$POT
 fi

echo "Updating language file for $LANG from $POT"
 msgmerge --sort-output --update --backup=off $LANG.po $POT

echo "Converting $LANG.po to $LANG.mo"
 msgfmt --check --verbose --output-file=$LANG.mo $LANG.po
done

 

Now, all you need to do is run the script once to get the default POT file and a PO file for every language.  You can edit PO files with translations for as much as you want.  Then simply run the script again and it will update generated MO files.  No parameters, no manuals, no nothing.  If you need to add another language, just put the appropriate locale in the $LANGS variable and run the script again.  You are good to go.

Enjoy!