diff --git a/i18n_string/i18n_string.module b/i18n_string/i18n_string.module index 5fe5158..5b313fa 100644 --- a/i18n_string/i18n_string.module +++ b/i18n_string/i18n_string.module @@ -485,6 +485,37 @@ } /** + * Implements hook_element_info_alter(). + */ +function i18n_string_element_info_alter(&$types) { + $types['text_format']['#pre_render'][] = 'i18n_string_pre_render_text_format'; +} + +/** + * The '#pre_render' function to alter text format in a translation. + * + * @param $element + * The text_format element which will be rendered. + * + * @return + * The altered text_format element with a disabled "Text format" select with only the source filter in it. + */ +function i18n_string_pre_render_text_format($element) { + if (isset($element['format']['format']) && isset($element['#i18n_string_format'])) { + if ($element['#i18n_string_format']) { + $filters = filter_formats(); + $element['format']['format']['#options'] = array($element['#i18n_string_format'] => $filters[$element['#i18n_string_format']]->name); + $element['format']['format']['#attributes']['disabled'] = TRUE; + } + else { + $element['format']['#access'] = FALSE; + } + } + + return $element; +} + +/** * Check user access to translate a specific string. * * If the string has a format the user is not allowed to edit, it will return FALSE diff --git a/i18n_string/i18n_string.pages.inc b/i18n_string/i18n_string.pages.inc index 7ca4289..72d26a1 100644 --- a/i18n_string/i18n_string.pages.inc +++ b/i18n_string/i18n_string.pages.inc @@ -185,10 +185,10 @@ $default_value = $item->format_translation($langcode, array('langcode' => $langcode, 'sanitize' => FALSE, 'debug' => FALSE)); $form[$item->get_name()] = array( '#title' => $item->get_title(), - '#type' => 'textarea', + '#type' => $item->format ? 'text_format' : 'textarea', '#default_value' => $default_value, '#disabled' => $disabled, - '#description' => $description, + '#description' => $item->format ? '' : $description, '#i18n_string_format' => $source ? $source->format : 0, // If disabled, provide smaller textarea (that can be expanded anyway). '#rows' => $disabled ? 1 : min(ceil(str_word_count($default_value) / 12), 10), @@ -203,6 +203,17 @@ */ function i18n_string_translate_page_form_validate($form, &$form_state) { foreach ($form_state['values']['strings'] as $key => $value) { + if (is_array($value)) { + if (isset($value['value'])) { + $value = $value['value']; + $form_state['values']['strings'][$key] = $value; + } + else { + form_set_error("strings][$key", t('Unable to get the translated string value.')); + watchdog('locale', 'Unable to get the translated string value, string array is: %string', array('%string' => var_dump($value)), WATCHDOG_WARNING); + } + } + // We don't need to validate disabled form fields because those are already // validated by the FormAPI. if (empty($form['strings'][$key]['#i18n_string_format'])) {