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!

Comments

Itangalo’s picture

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

michaelcrm’s picture

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

mooffie’s picture

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:

Male
Female

First you'd better chage it to:

male|Male
female|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')
);
Devr’s picture

Your solution helped a lot today!

Regards, Devr

smv’s picture

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.

smv’s picture

I have resolved the problem

weedoo’s picture

When you find answers to your questions, you should leave it in the forum to help others. Thanks

artycul’s picture

thank you from me too moofie.

asak’s picture

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? ;)

mooffie’s picture

It doesn't however work for text fields...

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.

What about decimal fields? I'd like to change the pre & post

CCK currently doesn't wrap it in t(). Consider filing a bug.

pictogram’s picture

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

mooffie’s picture

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:

  1. Do, e.g., setlocale('LC_COLLATE', 'de_DE.utf8') somewhere and add SORT_LOCALE_STRING as 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.)
  2. Put the country names in the database and do 'ORDER BY' when you fetch them. I already did this example. This is probably the preferable solution because, I guess, your lists are quite lenthy by now. I've lately seen a 'country_list' module --I think that was its name-- and you should propose to add to it multilingualism support.
GN’s picture

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')
);}
nikdip’s picture

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')
);
cpsaltis’s picture

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.

joebest’s picture

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')
);

mooffie’s picture

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.)

Allowed value list:
=============================
main event|Main Event
...

(You don't need this anymore once you're using the PHP block.)

Ace Cooper’s picture

Clear solution, mooffie, thank you!

For those, who can not find the created strings in the Translation menu: just load the page with the created field at least once under admin. Then you can go search for translatable strings and voilà!

What we know shapes who we are.

DarkteK’s picture

Man, thx so much, you just saved my life I was about to hardcore page.tpl with jQuery and man I didn't wantedto do that, thx so much !!! :D

andreiashu’s picture

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 :)

Letharion’s picture

I used

$language = i18n_get_lang();
if(language == "x")
  return y;
else
  return z;
intyms’s picture

the following code works for me:
(paste it inside "Allowed values fieldgroup - Php code")

global $language;
if ($language->language=="en") {
	return array(
		'active' => t('active status'),
		'finished' => t('closed')
		);
}
if ($language->language=="ro") {
	return array(
		'active' => t('activ'),
		'finished' => t('inchis')
		);
}
if ($language->language=="ru") {
	return array(
		'active' => t('активный'),
		'finished' => t('закрытый')
		);
}
Junro’s picture

This method translate only values in CCK fields on EDIT PAGE? Right?

Because it's working on edit page, but doesn't translate it on content nodes.

Right? or I miss something...

If that's right, how to have the translated values on content nodes?

colan’s picture

Why not simply use the taxonomy system? For example, create a vocabulary called "Gender" with the terms "Male" and "Female". If you make the vocabulary and terms translatable (through core/i18n/locale), you don't need to worry about PHP coding.

strellman’s picture

Here I am developing a site in English, waiting to make it multilingual after all the CCK fields are set up like we need, but I didn't even realize there was a translation issue on defaults or allowed values. You are right, taxonomy is the way to go. The only drawback I see is not being able to put the taxonomy fields where you want within other field groupings.

Itangalo’s picture

The Content Taxonomy module is swell -- it lets you manage taxonomy terms just like CCK fields.
It's the way taxonomy will be managed in Drupal 7 as well, so you're not wasting time on dead-end.

I'm not completely sure that it's a good idea to just replace CCK text fields with taxonomy terms, but if you're going to do it Content Taxonomy will be your friend.

Cheers!
//Johan Falk, http://nodeone.se

cannanso’s picture

The Internationalization module has a submodule specifically for CCK fields. Go to your modules list and under Multilanguage, enable CCK translation. Now your cck fields are translatable.

colan’s picture

Yes, but it doesn't help with translation if you're defining a set of allowed values.