get_strings(array('empty' => TRUE)); if (empty($langcode)) { drupal_set_title(t('Translate @name', array('@name' => i18n_object_info($object_type, 'title')))); return i18n_string_translate_page_overview($object, $strings); } else { drupal_set_title(t('Translate to @language', array('@language' => i18n_language_name($langcode)))); return drupal_get_form('i18n_string_translate_page_form', $strings, $langcode); } } /** * Provide a core translation module like overview page for this object. */ function i18n_string_translate_page_overview($object, $strings) { include_once DRUPAL_ROOT . '/includes/language.inc'; // Set the default item key, assume it's the first. $item_title = reset($strings); $header = array(t('Language'), t('Title'), t('Status'), t('Operations')); $source_language = variable_get_value('i18n_string_source_language'); $rows = array(); foreach (language_list() as $langcode => $language) { if ($langcode == $source_language) { $rows[] = array( $language->name . ' ' . t('(source)'), check_plain($item_title->get_string()), t('original'), l(t('edit'), $object->get_edit_path()), ); } else { // Try to figure out if this item has any of its properties translated. $translated = FALSE; foreach ($strings as $i18nstring) { if ($i18nstring->get_translation($langcode)) { $translated = TRUE; break; } } // Translate the item that was requested to be displayed as title. $rows[] = array( $language->name, $item_title->format_translation($langcode, array('sanitize default' => TRUE)), $translated ? t('translated') : t('not translated'), l(t('translate'), $object->get_translate_path($langcode), array('query' => drupal_get_destination())), ); } } $build['i18n_string_translation_overview'] = array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, ); return $build; } /** * Form builder callback for in-place string translation. */ function i18n_string_translate_page_form($form, &$form_state, $strings, $langcode) { $form = i18n_string_translate_page_form_base($form, $langcode); $form['strings'] += i18n_string_translate_page_form_strings($strings, $langcode); return $form; } /** * Create base form for string translation */ function i18n_string_translate_page_form_base($form, $langcode, $redirect = NULL) { $form['langcode'] = array( '#type' => 'value', '#value' => $langcode, ); $form['strings'] = array( // Use a tree, so we can access the values easily. '#tree' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save translation'), ); if ($redirect) { $form['#redirect'] = array( $redirect, ); } // Add explicit validate and submit hooks so this can be used from inside any form. $form['#validate'] = array('i18n_string_translate_page_form_validate'); $form['#submit'] = array('i18n_string_translate_page_form_submit'); return $form; } /** * Create field elements for strings */ function i18n_string_translate_page_form_strings($strings, $langcode) { $formats = filter_formats(); foreach ($strings as $item) { $disabled = FALSE; $description = ''; // We may have a source or not. Maybe the format is disallowed for all. $source = $item->get_source(); $format_id = $source ? $source->format : $item->format; if ($format_id) { $format = filter_format_load($format_id); $disabled = !i18n_string_translate_access($item); if ($disabled) { $description = t('This string uses the %name text format. You are not allowed to translate or edit texts with this format.', array('%name' => $format->name)); } else { $description = '