Exemplo n.º 1
0
 /**
  * Test method.
  *
  * @covers ElKuKu\Crowdin\Package\File::update
  * @covers ElKuKu\Crowdin\Package\File::processLanguageFile
  *
  * @return void
  */
 public function testUpdate()
 {
     $languageFile = new Languagefile(__DIR__ . '/Data/test.txt', 'crowdinpath');
     $languageFile->setTitle('title');
     $languageFile->setExportPattern('pattern');
     $expected = 'project/{projectID}/update-file?key={APIKey}&multipart%5B0%5D%5Bname%5D=branch' . '&multipart%5B0%5D%5Bcontents%5D=branch&multipart%5B1%5D%5Bname%5D=files%5Bcrowdinpath%5D' . '&multipart%5B2%5D%5Bname%5D=titles%5Bcrowdinpath%5D&multipart%5B2%5D%5Bcontents%5D=title' . '&multipart%5B3%5D%5Bname%5D=export_patterns%5Bcrowdinpath%5D&multipart%5B3%5D%5Bcontents%5D=pattern';
     $this->assertThat($this->object->update($languageFile, 'branch'), $this->equalTo($this->testResponse->setBody($expected)));
 }
Exemplo n.º 2
0
 /**
  * Upload existing translations to your Crowdin project.
  *
  * @param   Languagefile  $languagefile            The translation object.
  * @param   string        $language                The language tag.
  * @param   boolean       $importDuplicates        Defines whether to add translation if there is
  *                                                 the same translation previously added.
  *                                                 Acceptable values are: 0 or 1. Default is 0.
  * @param   boolean       $importEqualSuggestions  Defines whether to add translation if it is equal to
  *                                                 source string at Crowdin.
  *                                                 Acceptable values are: 0 or 1. Default is 0.
  * @param   boolean       $autoImproveImports      Mark uploaded translations as approved.
  *                                                 Acceptable values are: 0 or 1. Default is 0.
  *
  * @see     https://crowdin.com/page/api/upload-translation
  * @since   1.0.1
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function upload(Languagefile $languagefile, $language, $importDuplicates = false, $importEqualSuggestions = false, $autoImproveImports = false)
 {
     $data = [];
     $data[] = ['name' => 'import_duplicates', 'contents' => (int) $importDuplicates];
     $data[] = ['name' => 'import_eq_suggestions', 'contents' => (int) $importEqualSuggestions];
     $data[] = ['name' => 'auto_approve_imported', 'contents' => (int) $autoImproveImports];
     $data[] = ['name' => 'language', 'contents' => $language];
     $data[] = ['name' => 'files[' . $languagefile->getCrowdinPath() . ']', 'contents' => fopen($languagefile->getLocalPath(), 'r')];
     return $this->getHttpClient()->post($this->getBasePath('upload-translation'), ['multipart' => $data]);
 }
Exemplo n.º 3
0
 /**
  * Process a language file.
  * 
  * @param   array         $data          Data array.
  * @param   Languagefile  $languagefile  The language file object.
  *
  * @return array
  */
 private function processLanguageFile(array $data, Languagefile $languagefile)
 {
     $data[] = ['name' => 'files[' . $languagefile->getCrowdinPath() . ']', 'contents' => fopen($languagefile->getLocalPath(), 'r')];
     if ($languagefile->getTitle()) {
         $data[] = ['name' => 'titles[' . $languagefile->getCrowdinPath() . ']', 'contents' => $languagefile->getTitle()];
     }
     if ($languagefile->getExportPattern()) {
         $data[] = ['name' => 'export_patterns[' . $languagefile->getCrowdinPath() . ']', 'contents' => $languagefile->getExportPattern()];
     }
     return $data;
 }
Exemplo n.º 4
0
 /**
  * Test method.
  *
  * @covers ElKuKu\Crowdin\Languagefile::getTitle
  *
  * @return void
  */
 public function testGetTitle()
 {
     $this->object->setTitle('fooBar');
     $this->assertThat($this->object->getTitle(), $this->equalTo('fooBar'));
 }