/** * 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]); }
/** * 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; }
/** * Test method. * * @covers ElKuKu\Crowdin\Languagefile::getLocalPath * * @return void */ public function testGetLocalPath() { $this->assertThat($this->object->getLocalPath(), $this->equalTo($this->dataDir . '/test.txt')); }