Esempio n. 1
0
 public function testGetComponents()
 {
     $finder = new LU_Finder(array('TranslateSearch' => '/IP/extensions/Translate/TranslateSearch.i18n.php', 'Babel' => '/IP/extensions/Babel/Babel.i18n.php'), array('Babel' => '/IP/extensions/Babel/i18n', 'Door' => array('core' => '/IP/extensions/Door/i18n/core', 'extra' => '/IP/extensions/Door/i18n/extra')), '/IP');
     $observed = $finder->getComponents();
     $expected = array('repo' => 'mediawiki', 'orig' => "file:///IP/languages/messages/Messages*.php", 'path' => 'languages/messages/Messages*.php');
     $this->assertArrayHasKey('core', $observed);
     $this->assertSame($expected, $observed['core'], 'Core php file');
     $expected = array('repo' => 'extension', 'name' => 'Translate', 'orig' => 'file:///IP/extensions/Translate/TranslateSearch.i18n.php', 'path' => 'TranslateSearch.i18n.php');
     $this->assertArrayHasKey('TranslateSearch', $observed);
     $this->assertSame($expected, $observed['TranslateSearch'], 'PHP only extension');
     $expected = array('repo' => 'extension', 'name' => 'Babel', 'orig' => 'file:///IP/extensions/Babel/i18n/*.json', 'path' => 'i18n/*.json');
     $this->assertArrayHasKey('Babel-0', $observed);
     $this->assertSame($expected, $observed['Babel-0'], 'PHP&JSON extension');
     $expected = array('repo' => 'extension', 'name' => 'Door', 'orig' => 'file:///IP/extensions/Door/i18n/core/*.json', 'path' => 'i18n/core/*.json');
     $this->assertArrayHasKey('Door-core', $observed);
     $this->assertSame($expected, $observed['Door-core'], 'Multidir json extension');
     $expected = array('repo' => 'extension', 'name' => 'Door', 'orig' => 'file:///IP/extensions/Door/i18n/extra/*.json', 'path' => 'i18n/extra/*.json');
     $this->assertArrayHasKey('Door-extra', $observed);
     $this->assertSame($expected, $observed['Door-extra'], 'Multidir json extension');
 }
Esempio n. 2
0
 public function execute(LU_Finder $finder, LU_ReaderFactory $readerFactory, LU_FetcherFactory $fetcherFactory, array $repos)
 {
     $components = $finder->getComponents();
     $updatedMessages = array();
     foreach ($components as $key => $info) {
         $originFiles = $this->fetchFiles($fetcherFactory, $info['orig']);
         $remoteFiles = $this->fetchFiles($fetcherFactory, $this->expandRemotePath($info, $repos));
         if ($remoteFiles === array()) {
             // Small optimization: if nothing to compare with, skip
             continue;
         }
         $originMessages = $this->readMessages($readerFactory, $originFiles);
         $remoteMessages = $this->readMessages($readerFactory, $remoteFiles);
         if (!isset($remoteMessages['en'])) {
             // Could not find remote messages
             continue;
         }
         // If remote translation in English is not present or differs, we do not want
         // translations for other languages for those messages, as they are either not
         // used in this version of code or can be incompatible.
         $forbiddenKeys = $this->findChangedTranslations($originMessages['en'], $remoteMessages['en']);
         // We never accept updates for English strings
         unset($originMessages['en'], $remoteMessages['en']);
         // message: string in all languages; translation: string in one language.
         foreach ($remoteMessages as $language => $remoteTranslations) {
             // Check for completely new languages
             $originTranslations = array();
             if (isset($originMessages[$language])) {
                 $originTranslations = $originMessages[$language];
             }
             $updatedTranslations = $this->findChangedTranslations($originTranslations, $remoteTranslations, $forbiddenKeys);
             // Avoid empty arrays
             if ($updatedTranslations === array()) {
                 continue;
             }
             if (!isset($updatedMessages[$language])) {
                 $updatedMessages[$language] = array();
             }
             // In case of conflicts, which should not exist, this prefers the
             // first translation seen.
             $updatedMessages[$language] += $updatedTranslations;
         }
     }
     return $updatedMessages;
 }