コード例 #1
0
 function updateTranslations($source_dir, $dry_run = false)
 {
     $loader = new lmbFsDictionaryExtractor();
     $loader->registerFileParser('.html', new lmbWACTDictionaryExtractor());
     $loader->registerFileParser('.php', new lmbPHPDictionaryExtractor());
     $loader->registerFileParser('.phtml', new lmbPHPDictionaryExtractor());
     $dicts = array();
     $iterator = new lmbFsRecursiveIterator($source_dir);
     $this->response->write("======== Extracting translations from source ========\n");
     $loader->traverse($iterator, $dicts, $this->response);
     if (!($translations = $this->backend->loadAll())) {
         $this->response->write("======== No existing translations found!(create them first) ========\n");
         return;
     }
     $this->response->write("======== Updating translations ========\n");
     foreach ($translations as $locale => $domains) {
         foreach ($domains as $domain => $old_dict) {
             if (isset($dicts[$domain])) {
                 $this->response->write($this->backend->info($locale, $domain) . "...");
                 $new_dict = $dicts[$domain]->merge($old_dict);
                 if (!$dry_run) {
                     $this->backend->save($locale, $domain, $new_dict);
                     $this->response->write("updated\n");
                 } else {
                     $this->response->write("skipped(dry-run)\n");
                 }
             }
         }
     }
 }
コード例 #2
0
 function testLoad()
 {
     $it = new MockFsRecursiveIterator();
     $m1 = new MockBaseDictionaryParser();
     $m2 = new MockBaseDictionaryParser();
     $it->setReturnValueAt(0, 'valid', true);
     $it->setReturnValueAt(0, 'isFile', false);
     $it->setReturnValueAt(0, 'current', 'junky');
     $file_path1 = 'some.php';
     $file_path2 = 'some.html';
     $it->setReturnValueAt(1, 'valid', true);
     $it->setReturnValueAt(1, 'current', $file_path1);
     $it->setReturnValueAt(1, 'isFile', true);
     $it->setReturnValueAt(2, 'valid', true);
     $it->setReturnValueAt(2, 'current', $file_path2);
     $it->setReturnValueAt(2, 'isFile', true);
     $loader = new lmbFsDictionaryExtractor();
     $loader->registerFileParser('.php', $m1);
     $loader->registerFileParser('.html', $m2);
     $dictionaries = array();
     $response = new lmbCliOutput();
     $m1->expectOnce('extractFromFile', array($file_path1, $dictionaries, $response));
     $m2->expectOnce('extractFromFile', array($file_path2, $dictionaries, $response));
     $loader->traverse($it, $dictionaries, $response);
 }