Drupal: how to translate single CCK fields values

tags: Drupal  
drupal tags: translations   CCK   Locale  

Out of the box the localization and translation functionalities of Drupal can translate only the titles of each field created with the Content Construction Kit (CCK). Unfortunately at the moment no translation module (Locale, Localizer, i18n) offers direct support for the translation of cck fields, so we have to fix this ourselves.

In order for a string to get translated it must be enveloped by the t() function in the PHP code. We have to do this manually. Currently, your 'Allowed values' list probably looks like:

Apples
Oranges

First you'd better chage it to::

apples|Apples
oranges|Oranges

To the left of the pipe is what's stored in the DB. To the right is what's shown to the User. Without this distinction between the value stored in the DB and the string shown to the user there's no sense in translating.

The next step is to generate this 'Allowed value' list via PHP code instead. The box for PHP code is just beneath the normal box. Use code similar to:

return array(
  'apples' => t('Apples'),
  'oranges' => t('Oranges')
);

Now all we have to do is to look for our strings in Locale and proceed with their translation as usual.

Thanks mooffie for pointing this out.


Similar:

Thanks! Very helpful :-)

Thanks! Very helpful :-)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <img> <hr>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
Are you human (question to prevent spam)?
Twitter
Add to Technorati Favorites

Featured:

Archives

September 2010
SunMonTueWedThuFriSat
1234
567891011
12131415161718
19202122232425
2627282930
PureDivs Drupal Themes Conversions
PureDivs Conversione Temi Drupal