From ce11ffa3ca75bc1558abfed0acc911bec72f2e0c Mon Sep 17 00:00:00 2001 From: Tristan Olive Date: Fri, 22 May 2015 20:29:48 -0400 Subject: [PATCH] Remove duplicates from merged textgroup PO file when updating strings at Transifex (DBOINCP-141) --- .../boinctranslate/boinctranslate.module | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drupal/sites/default/boinc/modules/boinctranslate/boinctranslate.module b/drupal/sites/default/boinc/modules/boinctranslate/boinctranslate.module index b91fe7c1a9..302eabb719 100644 --- a/drupal/sites/default/boinc/modules/boinctranslate/boinctranslate.module +++ b/drupal/sites/default/boinc/modules/boinctranslate/boinctranslate.module @@ -658,9 +658,26 @@ function boinctranslate_get_po($langcode, $type = 'standard') { default: } + // Merge textgroup strings together for export as one file foreach ($textgroups as $textgroup) { $strings += _locale_export_get_strings($language, $textgroup); } + ksort($strings); + $unique_strings = array(); + $duplicate_strings = array(); + foreach ($strings as $id => $string) { + // Build a set of duplicate strings + if (!isset($unique_strings[$string['source']])) { + $unique_strings[$string['source']] = $id; + } + else { + $duplicate_strings[] = $id; + } + } + foreach ($duplicate_strings as $id) { + // Remove any duplicate source strings from the original array + unset($strings[$id]); + } if ($langcode != 'en') { // If not the source language, remove untranslated strings from the ouput foreach ($strings as $i => $string) {