/**
  * @return void
  */
 public function testGetTranslations()
 {
     $res = $this->Transifex->getTranslations('cake', 'de');
     $this->assertEquals('text/x-po', $res['mimetype']);
     $this->assertTextContains('Plural-Forms: nplurals=2; plural=(n != 1);', $res['content']);
 }
 /**
  * TransifexShell::pull()
  *
  * @return void
  */
 public function pull()
 {
     $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('No such 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('No such resource');
     }
     if ($resource === '*') {
         $resources = $availableResources;
     } else {
         $resources = (array) $resource;
     }
     $approvedOnly = false;
     if ($questioning && !$this->params['reviewed-only']) {
         $approvedOnly = $this->in('Only reviewed translations', ['y', 'n'], 'n') === 'y';
     } else {
         $approvedOnly = $this->params['reviewed-only'];
     }
     $count = 0;
     foreach ($languages as $language) {
         foreach ($resources as $resource) {
             $this->out(sprintf('Generating PO file for %s and %s', $language, $resource), 1, Shell::VERBOSE);
             $translations = $this->Transifex->getTranslations($resource, $language, $approvedOnly);
             if (empty($translations['content'])) {
                 $this->err(' - ' . sprintf('No PO file for %s and %s', $language, $resource));
                 continue;
             }
             $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_dir($dir)) {
                 if (!mkdir($dir, 0770, true)) {
                     return $this->error(sprintf('Cannot create new Locale folder %s', str_replace(APP, DS, $dir)));
                 }
             }
             if (empty($this->params['dry-run']) && !file_put_contents($file, $translations['content'])) {
                 return $this->error(sprintf('Could not store translation content into PO file (%s).', str_replace(APP, DS, $file)));
             }
             $count++;
             $this->out(sprintf('PO file %s generated', str_replace(APP, DS, $file)), 1, Shell::VERBOSE);
         }
     }
     $this->out('... Done! ' . $count . ' PO file(s) generated.');
 }