r80186 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80185‎ | r80186 | r80187 >
Date:19:47, 13 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Ignore insignificant translation units and batch insert opertaions
Modified paths:
  • /trunk/extensions/LiveTranslate/api/ApiImportTranslationMemories.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/LT_TMUnit.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/includes/LT_TMUnit.php
@@ -85,4 +85,48 @@
8686 return count( $this->variants ) > 0;
8787 }
8888
 89+ /**
 90+ * Returns if the translation unit has any significant value. This means it has at least 2
 91+ * variants with different values.
 92+ *
 93+ * @since 0.4
 94+ *
 95+ * @return boolean
 96+ */
 97+ public function isSignificant() {
 98+ return count( $this->variants ) > 1 && $this->hasVariantDifferences();
 99+ }
 100+
 101+ /**
 102+ * Returns if the translation unit has a certain minimal amount (default: 1) of
 103+ * differences in values in it's variants.
 104+ *
 105+ * @since 0.4
 106+ *
 107+ * @return boolean
 108+ */
 109+ public function hasVariantDifferences( $minAmount = 1 ) {
 110+ $amount = -1; // The first unknown value is not a difference.
 111+ $knownValues = array();
 112+
 113+ foreach ( $this->variants as $variant ) {
 114+ // If the value is not known yet, it's a difference.
 115+ if ( !in_array( $variant[0], $knownValues ) ) {
 116+ $knownValues[] = $variant[0];
 117+ $amount++;
 118+ }
 119+ // If there are synonyms, just assume it's different.
 120+ // This might not be the case, but no full accuracy is required.
 121+ else if ( count( $variant ) > 1 ) {
 122+ $amount++;
 123+ }
 124+
 125+ if ( $amount >= $minAmount ) {
 126+ return true;
 127+ }
 128+ }
 129+
 130+ return false;
 131+ }
 132+
89133 }
Index: trunk/extensions/LiveTranslate/api/ApiImportTranslationMemories.php
@@ -91,8 +91,14 @@
9292
9393 $wordId = ( $memoryId - 1 ) * 100000;
9494
 95+ $dbw->begin();
 96+
9597 // Insert the memory in the db.
9698 foreach ( $tm->getTranslationUnits() as $tu ) {
 99+ if ( !$tu->isSignificant() ) {
 100+ continue;
 101+ }
 102+
97103 foreach ( $tu->getVariants() as $language => $translations ) {
98104 $primary = 1;
99105
@@ -113,7 +119,14 @@
114120 }
115121
116122 $wordId++;
117 - }
 123+
 124+ if ( $wordId % 500 == 0 ) {
 125+ $dbw->commit();
 126+ $dbw->begin();
 127+ }
 128+ }
 129+
 130+ $dbw->commit();
118131 }
119132
120133 /**

Status & tagging log