function i18nstrings_form_alter in Internationalization 6
Implementation of hook_form_alter().
Add English language in some string forms when it is not the default.
File
- i18nstrings/
i18nstrings.module, line 139 - Internationalization (i18n) package - translatable strings.
Code
function i18nstrings_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'locale_translate_export_po_form':
case 'locale_translate_import_form':
$names = locale_language_list('name', TRUE);
if (language_default('language') != 'en' && array_key_exists('en', $names)) {
if (isset($form['export'])) {
$form['export']['langcode']['#options']['en'] = $names['en'];
}
else {
$form['import']['langcode']['#options'][t('Already added languages')]['en'] = $names['en'];
}
}
break;
case 'locale_translate_edit_form':
// Restrict filter permissions and handle validation and submission for i18n strings
$context = db_fetch_object(db_query("SELECT * FROM {i18n_strings} WHERE lid = %d", $form['lid']['#value']));
if ($context) {
$form['i18nstrings_context'] = array(
'#type' => 'value',
'#value' => $context,
);
// Replace validate callback
$form['#validate'] = array(
'i18nstrings_translate_edit_form_validate',
);
if ($context->format) {
$format = filter_formats($context->format);
$disabled = !filter_access($context->format);
if ($disabled) {
drupal_set_message(t('This string uses the %name input format. You are not allowed to translate or edit texts with this format.', array(
'%name' => $format->name,
)), 'warning');
}
foreach (element_children($form['translations']) as $langcode) {
$form['translations'][$langcode]['#disabled'] = $disabled;
}
$form['translations']['format_help'] = array(
'#type' => 'item',
'#title' => t('Input format: @name', array(
'@name' => $format->name,
)),
'#value' => theme('filter_tips', _filter_tips($context->format, FALSE)),
);
$form['submit']['#disabled'] = $disabled;
}
}
// Aditional submit callback
$form['#submit'][] = 'i18nstrings_translate_edit_form_submit';
break;
case 'l10n_client_form':
$form['#action'] = url('i18nstrings/save');
break;
}
}