Translating CCK Checkboxes and Radiobuttons

By Bill Seremetis, 7 July, 2011

Translating Drupal is easier nowdays than it was two years ago. Gábor Hojtsy has helped a lot and LDO is a really cool platform for translating Drupal.

But what happens when you need to translate things on your site? Things not available through the "Translate Interface" of i8n?
One such thing is the Allowed values list in CCK Fields. The solution is really easy and is done by using a few easy lines of PHP code.

When I was building TicketWest.gr I wanted to have an option about parking in several venues of my town. I made a CCK field with options, Yes and No and decided to display them as radiobuttons.
Yes and No weren't translatable as I found out later.

After some googling I found the answer. I populated the Allowed Values List with PHP instead of the default text. The code I used was:

return array(
'no' => t('No'),
'yes' => t('Yes')
);

The left side is the key, the value that will be stored in the database. The right side is the label displayed in the user interface. As you can see the label is inside the t() function which makes it translatable.
Now by using "translate interface" you could easily change Yes and No to your language, in my case it was Ναι for Yes and Όχι for No!