You are here

function language_hierarchy_form_alter in Language Hierarchy 7

Implements hook_form_alter().

File

./language_hierarchy.module, line 192

Code

function language_hierarchy_form_alter(&$form, &$form_state, $form_id) {
  if (in_array($form_id, array(
    'locale_translate_edit_form',
    'i18n_string_locale_translate_edit_form',
  ))) {
    $lid = $form['lid']['#value'];
    $source = db_query('SELECT source, context, textgroup, location FROM {locales_source} WHERE lid = :lid', array(
      ':lid' => $lid,
    ))
      ->fetchObject();
    $languages = language_hierarchy_language_list();
    if (!$source || count($languages) == 1) {
      return;
    }

    // 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) {
      if (isset($form['translations'][$langcode])) {
        $form['translations'][$langcode]['#prefix'] = '<div style="margin-left: ' . $language->depth * 2 . 'em">';
        $form['translations'][$langcode]['#suffix'] = '</div>';
      }
      else {
        $form['translations'][$langcode] = array(
          '#type' => 'textarea',
          '#rows' => $rows,
          '#title' => $language->name . ' (' . $form['original']['#title'] . ')',
          '#disabled' => TRUE,
          // Reverse wordwrap().
          '#default_value' => $source->source,
        );
      }
      $form['translations'][$langcode]['#weight'] = $language->weight;
    }
  }
}