function i18n_string_locale_translate_edit_form in Internationalization 7
User interface for string editing.
1 string reference to 'i18n_string_locale_translate_edit_form'
- i18n_string_menu_alter in i18n_string/
i18n_string.module - Implements hook_menu_alter().
File
- i18n_string/
i18n_string.pages.inc, line 307 - Internationalization (i18n) package - translatable strings reusable admin UI.
Code
function i18n_string_locale_translate_edit_form($form, &$form_state, $lid) {
// Fetch source string, if possible.
$source = db_query('SELECT source, context, textgroup, location FROM {locales_source} WHERE lid = :lid', array(
':lid' => $lid,
))
->fetchObject();
if (!$source) {
drupal_set_message(t('String not found.'), 'error');
drupal_goto('admin/config/regional/translate/translate');
}
// Add original text to the top and some values for form altering.
$form['original'] = array(
'#type' => 'item',
'#title' => t('Original text'),
'#markup' => check_plain(wordwrap($source->source, 0)),
);
if (!empty($source->context)) {
$form['context'] = array(
'#type' => 'item',
'#title' => t('Context'),
'#markup' => check_plain($source->context),
);
}
$form['lid'] = array(
'#type' => 'value',
'#value' => $lid,
);
$form['textgroup'] = array(
'#type' => 'value',
'#value' => $source->textgroup,
);
$form['location'] = array(
'#type' => 'value',
'#value' => $source->location,
);
// Include default form controls with empty values for all languages.
// This ensures that the languages are always in the same order in forms.
$languages = language_list();
// We don't need the default language value, that value is in $source.
$omit = $source->textgroup == 'default' ? 'en' : i18n_string_source_language();
unset($languages[$omit]);
$form['translations'] = array(
'#tree' => TRUE,
);
// Approximate the number of rows to use in the default textarea.
$rows = min(ceil(str_word_count($source->source) / 12), 10);
foreach ($languages as $langcode => $language) {
$form['translations'][$langcode] = array(
'#type' => 'textarea',
'#title' => t($language->name),
'#rows' => $rows,
'#default_value' => '',
);
}
// Fetch translations and fill in default values in the form.
$result = db_query("SELECT DISTINCT translation, language FROM {locales_target} WHERE lid = :lid AND language <> :omit", array(
':lid' => $lid,
':omit' => $omit,
));
foreach ($result as $translation) {
$form['translations'][$translation->language]['#default_value'] = $translation->translation;
}
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save translations'),
);
// Restrict filter permissions and handle validation and submission for i18n strings.
if (i18n_string_group_info($source->textgroup)) {
if ($i18nstring = i18n_string_get_by_lid($form['lid']['#value'])) {
$form['i18n_string'] = array(
'#type' => 'value',
'#value' => $i18nstring,
);
if ($message = $i18nstring
->check_translate_access()) {
drupal_set_message($message);
$disabled = TRUE;
}
// Add format help anyway, though the form may be disabled.
$form['translations']['format_help']['#markup'] = _i18n_string_translate_format_help($i18nstring->format);
}
else {
drupal_set_message(t('Source string not found.'), 'warning');
$disabled = TRUE;
}
if (!empty($disabled)) {
// Disable all form elements
$form['submit']['#disabled'] = TRUE;
foreach (element_children($form['translations']) as $langcode) {
$form['translations'][$langcode]['#disabled'] = TRUE;
}
}
}
return $form;
}