function i18nprofile_translation_field in Internationalization 5.3
Same name and namespace in other branches
- 5 i18nprofile/i18nprofile.module \i18nprofile_translation_field()
- 5.2 i18nprofile/i18nprofile.module \i18nprofile_translation_field()
Form to translate profile field
1 string reference to 'i18nprofile_translation_field'
- i18nprofile_translation in i18nprofile/
i18nprofile.module - Menu callback: profile translations
File
- i18nprofile/
i18nprofile.module, line 306
Code
function i18nprofile_translation_field($field, $language) {
$translation = db_fetch_object(db_query("SELECT * FROM {i18n_profile_fields} WHERE fid=%d AND language='%s'", $field->fid, $language));
$languages = i18n_supported_languages();
if ($translation) {
drupal_set_title("Edit profile field translation");
$form['current'] = array(
'#type' => 'value',
'#value' => $translation,
);
}
else {
drupal_set_title("Create profile field translation");
$translation = $field;
}
$form['source'] = array(
'#type' => 'value',
'#value' => $field,
);
$form['fields'] = array(
'#type' => 'fieldset',
'#title' => t('Source field'),
);
$form['fields']['title'] = array(
'#type' => 'item',
'#title' => t('Title'),
'#value' => $field->title,
);
$form['fields']['name'] = array(
'#type' => 'item',
'#title' => t('Form name'),
'#value' => $field->name,
);
$form['fields']['category'] = array(
'#type' => 'item',
'#title' => t('Category'),
'#value' => $field->category,
);
$form['translation'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('%language_name translation', array(
'%language_name' => $languages[$language],
)),
);
$form['translation']['language'] = array(
'#type' => 'value',
'#value' => $language,
);
$form['translation']['fid'] = array(
'#type' => 'value',
'#value' => $translation->fid,
);
$form['translation']['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $translation->title,
'#description' => t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'),
'#required' => TRUE,
);
$form['translation']['explanation'] = array(
'#type' => 'textarea',
'#title' => t('Explanation'),
'#default_value' => $translation->explanation,
'#description' => t('An optional explanation to go with the new field. The explanation will be shown to the user.'),
);
if ($field->type == 'selection') {
$form['translation']['options'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Selection options'),
'#description' => t('A list of all options. You need to update this translation when you change the options in the original language.'),
);
$options = unserialize($translation->options);
$lines = split("[,\n\r]", $field->options);
foreach ($lines as $line) {
if ($line = trim($line)) {
$form['translation']['options'][$line] = array(
'#type' => 'textfield',
'#title' => $line,
'#default_value' => $options[$line],
);
}
}
}
if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
$form['translation']['page'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
'#default_value' => $translation->page,
'#description' => t('To enable browsing this field by value, enter a title for the resulting page. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". This is only applicable for a public field.'),
);
}
else {
if ($field->type == 'checkbox') {
$form['translation']['page'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
'#default_value' => $translation->page,
'#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed". This is only applicable for a public field.'),
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save field'),
);
return $form;
}