How to translate the values in CCK custom (select/checkbox) fields
michaelcrm - October 12, 2007 - 06:24
For example, when we add to a content type a custom select-list-field "Gender" which consists of two values to choose from: "Male" and "Female". How can we make these two values translatable when entering the translation page of any node created based on that content type?
Same question to check-box-field.
Thanks in advance!

Internationalization module
I haven't tried it myself, but I think the i18n module will get you where you want. With i18n, you can provide content (and even taxonomy) in different languages.
They say some/a lot of these features will be part of core in Drupal 6 (which is already available for beta testing).
Good luck!
//Johan Falk, Sweden
Hello Johan, Thank you for
Hello Johan,
Thank you for your post. I am still struggling to find out the differences among "i18n", "internationalization" and "localization", but I knew the way to translate the vocabularies, I even found out how to translate the field name, the "Gender" in my case, through individual strings translation, but I just couldn't find the VALUES.
If I can't translate the values in an user-friendly way, it also will help if anyone can tell me where the system store those values.
Thanks again.
Michael
...
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 ourselves.
Currently, your 'Allowed values' list probably looks like:
MaleFemale
First you'd better chage it to:
male|Malefemale|Female
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('male' => t('Male'),
'female' => t('Female')
);
Thanks, mooffie!
Your solution helped a lot today!
Regards, Devr
How to translate the values in CCK custom (select/checkbox) fiel
I need to place the custom checkbox. The default value is 1 and 0 but, need to make it as yes and no. Can anyone help me in changing the return value to 'yes' and 'no'. I need to know where to change i.e which file to open.
this is what it is showing up
needed the format
can anyone help with this please.
resolved
I have resolved the problem
Leave solution !
When you find answers to your questions, you should leave it in the forum to help others. Thanks
thank you from me too
thank you from me too moofie.
Works!
Thank you so very much!
--Update:
To change the TITLES of the fields just search for them as strings and change them there... notice that when using English and another language it only worked (for me) setting all titles in english and having them translated - not the other way around...
--Update:
This works perfect with select list.
It doesn't however work for text fields... even after adding the field to the variables to settings.php... body & title work but other cck text fields don't...
What about decimal fields? I'd like to change the pre & post added text to be language dependent as well but can't find them as strings to translate.
Any ideas? ;)
...
I suggest you upgrade your CCK. I had a quick look and the Text module does wrap the title in t(), so apparently you shouldn't have a problem here.
CCK currently doesn't wrap it in t(). Consider filing a bug.
ordering alphabetically
Thanks moofie for you code
it just works fine for me. I'm using it for many different select lists and one of them is a country list. I'm wondering how I could I have this country listed alphabetically according to the language selected ?? Is it possible to have the label sorted ??
pictogram
...
Yes, it's possible. My code currently looks like:
return array(...);change it to:
$a = array(...);asort($a);
return $a;
HOWEVER, asort() sorts the strings byte by byte. This may not be suitable for the language(s) you use. Two ways to solve this:
setlocale('LC_COLLATE', 'de_DE.utf8')somewhere and addSORT_LOCALE_STRINGas a second paramter to asort(). (Note that I used LC_COLLATE, not LC_ALL, because we don't want to affect the way numbers are printed --or else the search module will fail because it uses floating point numbers.)Translation of strings seems
Translation of strings seems to be a buggy thing for me - sometimes it works, sometimes not...
If it does not, there is a quick-n-dirty solution
global $locale;if($locale=="en")
{return array(
'big' => t('Big'),
'small' => t('Small')
);}
else
{return array(
'big' => t('Grand'),
'small' => t('Petit')
);}
Translation of TextArea type string
This solution helped me to translate all my fileds with Select lists. What about fields with Textarea. I'm using one Textarea type field with Number of values = 2. The first one is in english version and second in russian. What code should be used instead of:
return array('big' => t('Big'),
'small' => t('Small')
);
http://www.dip.ee/en
Strings not appearing
Hello,
I'm using Drupal 5.7 with CCK 1.9 and i18n 2.4 and I tried your solution, but there is a slight problem. The new strings I defined in the return array of my select list do not appear when I search through the localization-string search interface. I thought it could be an indexing problem so I croned the site, but nothing happened. Is there something else I should do before translating these terms?
Thank you.
Does not work
I'm using Drupal 6.10. Strings not found in Translate Interface
=============================
Allowed value list:
=============================
main event|Main Event
shofar|Shofar
radical youth|Radical Youth
single youth adults|Single Youth Adults
=============================
PHP code:
=============================
return array(
'main event' => t('Main Event'),
'shofar' => t('Shofar')
'radical youth' => t('Radical Youth')
'single youth adults' => t('Single Youth Adults')
);
...
You have a syntax error here. You forgot the commas. It should be:
return array('main event' => t('Main Event'),
'shofar' => t('Shofar'),
'radical youth' => t('Radical Youth'),
'single youth adults' => t('Single Youth Adults'),
);
(The last comma seems unneeded. Indeed, but it isn't a sytax error.)
(You don't need this anymore once you're using the PHP block.)
Checked checkbox
How can i make a checkbox "checked" by default ? I tried adding default value to 1 and other this like that but it doesn't seem to work.
I must be doing something wrong...
Thanks in advance.
EDIT: Sorry for the dumb question, i didn't see this: "For a 'Single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the Allowed values section. Note that the checkbox will be labeled with the label of the 'on' value."
Solved it now :)