_locale_string_edit

Versions
4.6 – 5
_locale_string_edit($lid)

User interface for string editing.

Code

includes/locale.inc, line 354

<?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);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.