r80045 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80044‎ | r80045 | r80046 >
Date:22:27, 11 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added mapping for some language codes
Modified paths:
  • /trunk/extensions/LiveTranslate/api/ApiImportTranslationMemories.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/LT_TMXParser.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js
@@ -187,7 +187,7 @@
188188 * @param {string} targetLang
189189 */
190190 function requestGoogleTranslate( sourceLang, targetLang ) {
191 - translateElement( $( '#bodyContent' ), sourceLang, targetLang );
 191+ //translateElement( $( '#bodyContent' ), sourceLang, targetLang );
192192 }
193193
194194 /**
Index: trunk/extensions/LiveTranslate/includes/LT_TMXParser.php
@@ -125,7 +125,7 @@
126126 break;
127127 case 'tuv':
128128 if ( array_key_exists( 'xml:lang', $attribs ) ) {
129 - $this->currentLanguage = strtolower( $attribs['xml:lang'] );
 129+ $this->currentLanguage = $attribs['xml:lang'];
130130 }
131131 else {
132132 // TODO: ignore node or give warning
Index: trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php
@@ -291,6 +291,34 @@
292292 }
293293
294294 /**
 295+ * Returns an array with mapping from input language codes to MediaWiki language codes.
 296+ *
 297+ * @since 0.4
 298+ *
 299+ * @return array
 300+ */
 301+ public static function getInputLangMapping() {
 302+ return array(
 303+ 'en-us' => 'en',
 304+ 'en' => 'en-gb',
 305+ );
 306+ }
 307+
 308+ /**
 309+ * Returns an array with mapping from MediaWiki language codes to Google Translate language codes.
 310+ *
 311+ * @since 0.4
 312+ *
 313+ * @return array
 314+ */
 315+ public static function getOuputLangMapping() {
 316+ return array(
 317+ 'en-us' => 'en',
 318+ 'en-gb' => 'en',
 319+ );
 320+ }
 321+
 322+ /**
295323 * Returns the provided text starting with a letter in toggeled case.
296324 * If there is no difference between lowercase and upercase for the first
297325 * character, false is returned.
Index: trunk/extensions/LiveTranslate/api/ApiImportTranslationMemories.php
@@ -79,13 +79,14 @@
8080 */
8181 protected function doTMImport( LTTranslationMemory $tm, $memoryId ) {
8282 $dbw = wfGetDB( DB_MASTER );
83 -
 83+
8484 // Delete the memory from the db if already there.
8585 $dbw->delete(
8686 'live_translate',
8787 array( 'memory_id' => $memoryId )
8888 );
8989
 90+ // FIXME: this obviously goes wrong with multiple tms!
9091 $wordId = 0;
9192
9293 // Insert the memory in the db.
@@ -98,7 +99,7 @@
99100 'live_translate',
100101 array(
101102 'word_id' => $wordId,
102 - 'word_language' => $language,
 103+ 'word_language' => $this->cleanLanguage( $language ),
103104 'word_translation' => $translation,
104105 'word_primary' => $primary,
105106 'memory_id' => $memoryId
@@ -112,6 +113,26 @@
113114 }
114115 }
115116 }
 117+
 118+ /**
 119+ * Cleans the language code.
 120+ *
 121+ * @since 0.4
 122+ *
 123+ * @param string language
 124+ *
 125+ * @return string
 126+ */
 127+ protected function cleanLanguage( $language ) {
 128+ $language = strtolower( $language );
 129+ $mappings = LiveTranslateFunctions::getInputLangMapping();
 130+
 131+ if ( array_key_exists( $language, $mappings ) ) {
 132+ $language = $mappings[$language];
 133+ }
 134+
 135+ return $language;
 136+ }
116137
117138 public function getAllowedParams() {
118139 return array(

Status & tagging log