Index: trunk/extensions/LiveTranslate/includes/LT_TMUnit.php |
— | — | @@ -85,4 +85,48 @@ |
86 | 86 | return count( $this->variants ) > 0; |
87 | 87 | } |
88 | 88 | |
| 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 | + |
89 | 133 | } |
Index: trunk/extensions/LiveTranslate/api/ApiImportTranslationMemories.php |
— | — | @@ -91,8 +91,14 @@ |
92 | 92 | |
93 | 93 | $wordId = ( $memoryId - 1 ) * 100000; |
94 | 94 | |
| 95 | + $dbw->begin(); |
| 96 | + |
95 | 97 | // Insert the memory in the db. |
96 | 98 | foreach ( $tm->getTranslationUnits() as $tu ) { |
| 99 | + if ( !$tu->isSignificant() ) { |
| 100 | + continue; |
| 101 | + } |
| 102 | + |
97 | 103 | foreach ( $tu->getVariants() as $language => $translations ) { |
98 | 104 | $primary = 1; |
99 | 105 | |
— | — | @@ -113,7 +119,14 @@ |
114 | 120 | } |
115 | 121 | |
116 | 122 | $wordId++; |
117 | | - } |
| 123 | + |
| 124 | + if ( $wordId % 500 == 0 ) { |
| 125 | + $dbw->commit(); |
| 126 | + $dbw->begin(); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + $dbw->commit(); |
118 | 131 | } |
119 | 132 | |
120 | 133 | /** |