diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc index 4610d9d..e2257a9 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -22,15 +22,12 @@ function translation_entity_overview(EntityInterface $entity) { $translations = $entity->getTranslationLanguages(); $field_ui = module_exists('field_ui'); // Validate how many source languages are used. - $count_lauguage_as_source = array(); + $count_language_as_source = array(); $path = $controller->getViewPath($entity); $base_path = $controller->getBasePath($entity); $edit_path = $controller->getEditPath($entity); - $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations')); - $rows = array(); - if (language_multilingual()) { // If we have a view path defined for the current entity get the switch // links based on it. @@ -49,6 +46,40 @@ function translation_entity_overview(EntityInterface $entity) { } } + // Determine which languages have been used as a source for other + // translations. + foreach ($languages as $language) { + $langcode = $language->langcode; + + $is_original = $langcode == $original; + // Original has no source. + if (!$is_original && isset($translations[$langcode])) { + // Non-original existing translation in the translation set: keep track + // of the source language. + $source = isset($entity->source[$langcode]) ? $entity->source[$langcode] : ''; + + // Note the source language has been used as a source. + $language_as_source[$source] = TRUE; + } + } + + // Only show the translations column if there is more than one source value. + if (isset($language_as_source) && count($language_as_source) > 1) { + $show_source_column = TRUE; + } + else { + $show_source_column = FALSE; + } + + // Set up the translations table. + if ($show_source_column) { + $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations')); + } + else { + $header = array(t('Language'), t('Translation'), t('Status'), t('Operations')); + } + $rows = array(); + foreach ($languages as $language) { $language_name = $language->name; $langcode = $language->langcode; @@ -126,15 +157,12 @@ function translation_entity_overview(EntityInterface $entity) { $status = t('Not translated'); } - // Count how many translations use each source. - if (isset($count_lauguage_as_source[$source_name])) { - $count_lauguage_as_source[$source_name] ++; + if ($show_source_column) { + $rows[] = array($language_name, $row_title, $source_name, $status, $operations); } else { - $count_lauguage_as_source[$source_name] = 1; + $rows[] = array($language_name, $row_title, $status, $operations); } - - $rows[] = array($language_name, $row_title, $source_name, $status, $operations); } } @@ -144,20 +172,6 @@ function translation_entity_overview(EntityInterface $entity) { // which entity this is. $build['#entity'] = $entity; - // Remove Source Language column if there is only one unique source language. - // Check for two or fewer since that would correspond to 'n/a' and one unique - // source language, for example: English. - if (count($count_lauguage_as_source) <= 2) { - // The Source Language column is the 3rd, aka 2th column in the table. - $source_table_column=2; - // Remove source language header. - unset($header[$source_table_column]); - foreach ($rows as $index => $row) { - // Remove source language in each row. - unset($rows[$index][$source_table_column]); - } - } - $build['translation_entity_overview'] = array( '#theme' => 'table', '#header' => $header,