I'm implementing a gender field in a custom registration form.
The gender field also exists as a user field, so I'd like to call the label and allowed values from the existing instance. I've written it as a conditional override just in case...:
$form['gender'] = array(
'#title' => t('Gender'),
'#type' => 'radios',
'#options' => array('female' => t('Female'), 'male' => t('Male')),
'#required' => TRUE,
);
if($field = field_info_field('field_gender')) {
$form['gender']['#options'] = $field['settings']['allowed_values'];
$info = field_info_instance('user', 'field_gender', 'user');
$form['gender']['#title'] = t($info['label']);
}
Everything's working great, except for the multilingual part: despite having translated the field instance at the admin account settings using i18n, the extracted options and title of the existing field are not being translated upon changing the front-end language. They DO get translated however when visiting the user account page in a different language.
It seems my custom form doesn't send its strings through i18n...?
Can anyone point me out the pitfall please?
Thanks
UPDATE
I used
$func = function($val) { return t($val); };
$form['gender']['#options'] = array_map($func, $field['settings']['allowed_values']);
as suggested by Shameem to translate the options. But now it seems t() is fetching translations from the Locale module repository. How to direct t() to fetch it from i18n?