_locale_string_edit

  1. drupal
    1. 4.7
    2. 5
Versions
4.7 – 5 _locale_string_edit($lid)

User interface for string editing.

Code

includes/locale.inc, line 355

<?php
function _locale_string_edit($lid) {
  $languages = locale_supported_languages(FALSE, TRUE);
  unset($languages['name']['en']);

  $result = db_query('SELECT DISTINCT s.source, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid);
  $form = array();
  $form['translations'] = array('#tree' => TRUE);
  while ($translation = db_fetch_object($result)) {
    $orig = $translation->source;

    // Approximate the number of rows in a textfield with a maximum of 10.
    $rows = min(ceil(str_word_count($orig) / 12), 10);

    $form['translations'][$translation->locale] = array(
      '#type' => 'textarea', 
      '#title' => $languages['name'][$translation->locale], 
      '#default_value' => $translation->translation, 
      '#rows' => $rows,
    );
    unset($languages['name'][$translation->locale]);
  }

  // Handle erroneous lid.
  if (!isset($orig)) {
    drupal_set_message(t('String not found.'));
    drupal_goto('admin/locale/string/search');
  }

  // Add original text. Assign negative weight so that it floats to the top.
  $form['item'] = array(
    '#type' => 'item', 
    '#title' => t('Original text'), 
    '#value' => check_plain(wordwrap($orig, 0)), 
    '#weight' => -1,
  );

  foreach ($languages['name'] as $key => $lang) {
    $form['translations'][$key] = array(
      '#type' => 'textarea', 
      '#title' => $lang, 
      '#rows' => $rows,
    );
  }

  $form['lid'] = array(
    '#type' => 'value',
    '#value' => $lid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save translations'),
  );

  return drupal_get_form('_locale_string_edit', $form);
}
?>