From 699e4eec681e7bf4b50f849895e148de66440c54 Mon Sep 17 00:00:00 2001 From: zilverdistel Date: Wed, 23 May 2012 15:28:05 +0200 Subject: [PATCH] Issue #1252144 by dimitriseng, nikosnikos, zilverdistel | skks: Added Support Wysiwyg editors for string translations (Wysiwyg Javascripts don't get loaded for block translations). --- i18n_string/i18n_string.module | 30 ++++++++++++++++++++++++++++++ i18n_string/i18n_string.pages.inc | 22 ++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/i18n_string/i18n_string.module b/i18n_string/i18n_string.module index 53ed032..6bef1de 100644 --- a/i18n_string/i18n_string.module +++ b/i18n_string/i18n_string.module @@ -483,6 +483,36 @@ function i18n_string_group_info($group = NULL, $property = NULL, $default = NULL } } +/** + * 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; +} /** * Translate / update multiple strings diff --git a/i18n_string/i18n_string.pages.inc b/i18n_string/i18n_string.pages.inc index 5557d4c..0083423 100644 --- a/i18n_string/i18n_string.pages.inc +++ b/i18n_string/i18n_string.pages.inc @@ -191,10 +191,10 @@ function i18n_string_translate_page_form_strings($strings, $langcode) { $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 . _i18n_string_translate_format_help($format_id), + '#description' => $item->format ? '' : $description . _i18n_string_translate_format_help($format_id), //'#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), @@ -206,6 +206,24 @@ function i18n_string_translate_page_form_strings($strings, $langcode) { } /** + * Form validation callback for in-place string translation. + */ +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); + } + } + } +} + +/** * Form submission callback for in-place string translation. */ function i18n_string_translate_page_form_submit($form, &$form_state) { -- 1.7.9.5