Fix bug CKEditor when translate block

Public

Support Wysiwyg editors for string translations (Wysiwyg Javascripts don't get loaded for block translations)
http://drupal.org/node/1252144

</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_form_alter().
  3.  */
  4. function taxonomy_export_form_alter(&$form, &$form_state, $form_id) {
  5. if ($form_id == 'i18n_string_translate_page_form') {
  6. // Loop all strings.
  7. foreach ($form['strings']['all'] as $name => $field) {
  8. // The field for [ block title / vocabulary name / vocabulary description / term name ] are textfields in ori language,
  9. // but textareas when translating: change these to textfields.
  10. if (
  11. preg_match('/blocks:block:[0-9]+:title/i' , $name) ||
  12. preg_match('/taxonomy:(vocabulary|term):[0-9]+:name/i' , $name) ||
  13. preg_match('/taxonomy:vocabulary:[0-9]+:description/i' , $name)
  14. ) {
  15. $form['strings']['all'][$name]['#type'] = 'textfield';
  16. }
  17. // Change textarea to text_format and overwrite description which is already auto included in text_format fields.
  18. elseif (
  19. preg_match('/blocks:block:[0-9]+:body/i' , $name) ||
  20. preg_match('/taxonomy:term:[0-9]+:description/i' , $name)
  21. ) {
  22. $form['strings']['all'][$name]['#type'] = 'text_format';
  23. $form['strings']['all'][$name]['#description'] = '<br />';
  24. }
  25. }
  26.  
  27. // Add submit function.
  28. $form['#submit'] = array_merge(array('_taxonomy_export_form_submit') , $form['#submit']);
  29. }
  30. }
  31.  
  32. function _taxonomy_export_form_submit($form, &$form_state) {
  33. // Remove wysiwyg format because i18n cant handle it.
  34. foreach ($form_state['values']['strings'] as $name => $field) {
  35. if (
  36. preg_match('/blocks:block:[0-9]+:body/i' , $name) ||
  37. preg_match('/taxonomy:term:[0-9]+:description/i' , $name)
  38. ){
  39. unset($form_state['values']['strings'][$name]['format']);
  40. }
  41. }
  42. }

Comments

Augusto Busso's picture

Thanks, it works perfectly

bbob's picture

Where i need to insert this code?

langelhc's picture

Thnks, works fine!,
@bbob, put this in your own custom module, of course you have to replace YOURMODULE_form_alter().