WordPress – Translated frontend with backoffice in English

Last days, i had to mess around with the excelent blog and publishing software WordPress. I wanted the frontend localized in portuguese (yes… one or other of my projects are not globe wide), so i downloaded the portuguese version, but the administration backoffice also gets translated, and it looks pretty lame in portuguese.

The localization in WordPress is (more or less) pretty straightforward. It’s gettext based, so a translated version is just the same as the usual with a corresponding .mo and .po file in wp-includes/languages/ directory. Then you set the corresponding WPLANG constant in wp_config.php file. But it’s all or nothing, you get both the frontend and the backoffice translated….

But quickly i found myself a solution and i was happy again with an english backoffice. It just needs a tweak in the apache virtualhost configuration to set up an environment variable fot the backoffice that can be tested in wp-config.php file.

The apache config:

</Directory "/usr/home/wordpress/">
    AllowOverride None
    Order deny,allow
    Allow from all

    RewriteEngine On
    RewriteRule ^wp-login\.php - [E=BO:true]
    RewriteRule ^wp-admin/.* - [E=BO:true]
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . %{DOCUMENT_ROOT}index.php [L]
</Directory>

So, all the requests to wp-login and wp-admin (the backoffice administration interface) get the BO variable, now just need to test it and apply the WP_LANG only to all other requests in wp-config.php:

if (! (isset($_SERVER['BO']) && $_SERVER['BO']))
    define ('WPLANG', 'pt_PT');

There, frontend translated and backoffice in good old english tech words.

PS
I needed to adjust some translated strings, but found the .po file without translated strings (like a .pot file). But no problem you can generate a .po file from the .mo file, just run:

msgunfmt pt_PT.mo > pt_PT.po

What’s wrong with what we eat

I really enjoyed this TED talk, about western food habits, if you didn’t watched yet, please take 20 minutes and watch it now

I’m really not a tofu/seitan/vegetarian kind of guy, but this talk really had an effect on me and since i’m trying to eat less meat and more plants. Not only because of my own health but also for the healh of the entire planet.

FreeBSD Server – Ports tree maintenance

In the new FreeBSD server i am dumping the old CVSUp/Portupgrade and going for new and improved tools for ports management.

For maintaining the ports tree up to date i will use portsnap. Why? You can read about the advantages in the portsnap web page. It’s already in base system, so no need to install nothing. Try:

# portsnap

and should print the usual help options. So first thing is to fetch and apply the whole ports tree. It will overwrite every custom file that you have in ports tree /usr/ports/ like patches. Distfiles will survive and config options also (as they live in /var/db/ports/).

# portsnap fetch extract

Now we have a fully updated ports tree, and the portsnap own database in /var/db/portsnap/.

From now on simply update the ports tree with

# portsnap fetch update

Much simpler than the cvsup command and config file… all that is left is to put this in auto-pilot. You have the cron option, witch is nothing more than a sleep by a random time, so all the clients don’t slashdot the portsnap server. You can test it with:

# portsnap cron update

Both handbook and man pages explicitly warn about automatic ports tree updating, as one can be installing a port at the same time and “cause major problems” (meaning ending up with a corrupted or non-working software installed), so you should only update the index.

# portsnap -I cron update

Personally i will live on the edge and take the risk of actually updating the ports tree, not just the index, as the risk of forgetting to update the ports tree before installing packages and installing deprecated/legacy software is much higher than installing at the sime time the tree update is running.

The handbook goes for the cron to do this, but i use periodic and make this a part of the normal maintenance works (automatic email reports, logs, logs rotation all for free)

Create local daily dir if not exists

# mkdir -p /usr/local/etc/periodic/daily/

add really simple sh script with full paths, save and set execution perms

#!/bin/sh
#
# Updates the Ports tree
#
/usr/sbin/portsnap cron update
rc=0
exit $rc

For the report about old/obsolete packages i go again for periodic… but this time is already there all done for us (the FreeBSD users), just add in /etc/periodic.conf

weekly_status_pkg_enable="YES"

The ports tree is now managed, next post about the packages themselves.

Sources:
http://www.freebsd.org/cgi/man.cgi?query=periodic
http://www.freebsd.org/cgi/man.cgi?query=portsnap
http://www.freebsd.org/doc/handbook/portsnap.html

Making a donation

This is a post that i am cooking in my head for quite some time, and is a deviation of my own (roman catholic/Mediterranean/whatever) education pattern…

Long story short, since last year i made a personal commitment (several reasons in the decision making process) of donating a portion of my own income to some institution devoted to some noble cause each year. So, last year i selected an known institution as the recipient of the donation, so i contacted them and wired 1000 euro. A couple of weeks later i received back in snail mail a receipt, and that was it, no nothing. That left a bittersweet taste…

One may ask, what do you wanted? A full gospel band chanting “Thank you” and cheering you? Well, no. But a template thank you letter would be nice, and even nicer would be some kind of invitation to visit their work, not as an inspector (i believe that 99% of them have bigger bang for the buck than the public institutions) but to increase the involvement with them and encourage further donations.

Other very relevant point that i want to focus in this post, is the hypocrite view about the disclosure (or indeed the non-disclosure) of donors in our own culture. When you give you shouldn’t say, when you receive you also shouldn’t say. “Be kind and generous and don’t expect nothing in return” – i heard in church. For starters, turning this “rule” even more hypocrite, it only applies to small donations, if you give big enough it’s okay to put your name and bust in some building, even if proportionally, the donor of the smallest sum made a bigger effort. Also, this stupid secrecy has another effect, the lack of peer pressure and accountability, because no one has nothing to do with each others actions, the individuals that don’t give have a shield and the ones that do give are not accountable for their actions… ultimately no one is (both the doers and the non-doers).

As i couldn’t care less about these social conventions (or else i wouldn’t publish this post). This year i am selecting other institution and when it’s selected and the donation made, i will inform the world in the follow-up of this post, hoping that there will be followers.

Linux – upgrade to Kubuntu 11.04 “Natty Narwhal”

Just finished a laptop upgrade of Kubuntu (the Canonical Linux flavor) from distribution 10.10 to the latest 11.04″Natty Narwhal”. As usually my system was pretty messed up, and it take a couple of hours to put everything in working status. Anyway, the pain pays off and i really enjoy more and more to work with it, some of the key benefits are just awesome:

  • It’s free
  • It’s fast
  • The install/uninstall/upgrade software system is perfect, with thousands of free apps just a click away
  • The really beautiful KDE user interface

    It’s funny and kind of sad to walk into a room with 20 people, 15 of which running the “Think Different” computers, then boot up your laptop with Kubuntu…

  • The full freedom to customize and configure your OWN machine
  • The excellent fuse “mount everything” that you think of sub-system

There are still some problems that make it hard for non-geek users to embrace Linux on their desktops and laptops, even on the user friendly distributions (like Kubuntu). At least for me the major upgrades are nothing short of chaotic, some drivers support is still flaky and buggy (3d on ATI for me the worst by far), here and then there are some regressions with stuff unexpectedly stopping working good.

But the Linux community should be very proud, because the system has done such a long way. I still remember when just installing was some kind sorcery, not to speak in starting a graphical windows system (xorg.conf test #383). Or more recently support and configuration of wifi cards/networks/authentication nightmare. All of this is now gone, for instance last week i was able to configure VPN access and get 3G Internet via USB dongle just using the network manager GUI, no black screens, no bash, no googling…. simply amazing… – take that Windows – and then mounting remote filesystems with only one command – take that Apple.

So, is Linux perfect? Of course not.
Would i install it my friends computer? Maybe.
Am i willing to pay for Windows or OSX with Linux as a free alternative? Of course not.