/** * TransifexShell::push() * * @return void * @author Gustav Wellner Bou <*****@*****.**> */ public function push() { $options = $availableLanguages = $this->_languages(); $options[] = '*'; $questioning = false; if (!empty($this->params['language'])) { $language = $this->params['language']; } else { $language = $this->in('Language', $options, '*'); $questioning = true; } if (!in_array($language, $options, true)) { return $this->error(sprintf('No such language \'%s\'.', $language)); } if ($language === '*') { $languages = $availableLanguages; } else { $languages = (array) $language; } $options = $availableResources = $this->_resources(); $options[] = '*'; if (!empty($this->params['resource'])) { $resource = $this->params['resource']; } else { $resource = $this->in('Resource', $options, '*'); $questioning = true; } if (!in_array($resource, $options, true)) { return $this->error(sprintf('No such resource \'%s\'.', $language)); } if ($resource === '*') { $resources = $availableResources; } else { $resources = (array) $resource; } $count = 0; foreach ($languages as $language) { foreach ($resources as $resource) { $this->out('Submitting PO file for ' . $language . ' and ' . $resource, 1, Shell::NORMAL); $locale = $this->_getLocale($language); $path = !empty($this->params['plugin']) ? Plugin::path($this->params['plugin']) : APP; $file = $path . 'Locale' . DS . $locale . DS . 'LC_MESSAGES' . DS . $resource . '.po'; $dir = dirname($file); if (!is_file($file)) { $this->error(sprintf('PO file not found: %s', str_replace(APP, DS, $file))); } if (empty($this->params['dry-run']) && !$this->Transifex->putTranslations($resource, $language, $file)) { return $this->error('Could not submit translation.'); } $count++; $this->out(sprintf('PO file %s submitted', str_replace(APP, DS, $file)), 1, Shell::NORMAL); } } $this->out('... Done! ' . $count . ' PO file(s) pushed.'); }
/** * @return void */ public function testPutTranslations() { $file = Plugin::path('Transifex') . 'tests/test_files/test.pot'; $this->assertTrue(is_file($file)); $resource = 'foo'; $this->Transifex = $this->getMock('Transifex\\Lib\\TransifexLib', ['_post'], [$this->Transifex->settings]); $mockedResponse = ['strings_added' => 0, 'strings_updated' => 0, 'strings_delete' => 0]; $this->Transifex->expects($this->any())->method('_post')->will($this->returnValue($mockedResponse)); $result = $this->Transifex->putTranslations($resource, 'de', $file); $this->assertSame($mockedResponse, $result); }