public function testToArray() { $tmxFile = new Application_Util_TmxFile(); $tmxFile->setVariantSegment('test_translation_unit', 'de', 'Testübersetzung'); $tmxFile->setVariantSegment('test_translation_unit', 'en', 'Test translation'); $tmxFile->save(APPLICATION_PATH . DIRECTORY_SEPARATOR . $this->tmxTarget); foreach ($this->contentFiles as $contentFile) { file_put_contents(APPLICATION_PATH . DIRECTORY_SEPARATOR . $this->contentBasepath . DIRECTORY_SEPARATOR . $contentFile, 'Test Data'); } $array = $this->object->toArray(); foreach ($this->contentFiles as $lang => $contentFile) { // $this->assertTrue $this->assertEquals($contentFile, $array[$lang]['file']['filename'], "Expected file '{$contentFile}' in array."); $this->assertEquals('Test Data', $array[$lang]['file']['contents']); } $this->assertTrue(isset($array['de']['key']['test_translation_unit']), "Expected translation unit 'test_translation_unit'"); $this->assertTrue(isset($array['en']['key']['test_translation_unit']), "Expected translation unit 'test_translation_unit'"); $this->assertEquals('Testübersetzung', $array['de']['key']['test_translation_unit']); $this->assertEquals('Test translation', $array['en']['key']['test_translation_unit']); }
/** * @see Description in abstract base class */ public function fromArray(array $data) { $resultData = array(); $resultTmx = new Application_Util_TmxFile(); foreach ($data as $language => $fields) { foreach ($fields as $key => $val) { switch ($key) { case 'file': if (!is_array($val) || !isset($val['filename']) || !isset($val['contents'])) { throw new Setup_Model_Exception('Invalid data structure'); } $filePath = $this->_contentBasepath . DIRECTORY_SEPARATOR . $val['filename']; $resultData[$filePath] = $val['contents']; break; case 'key': foreach ($val as $translationUnit => $variant) { $resultTmx->setVariantSegment($translationUnit, $language, $variant); } break; default: throw new Setup_Model_Exception('Failed loading array. Invalid data structure.'); } } } $this->setContent($resultData); $this->setTranslation($resultTmx->toArray()); }
/** * @see Description in abstract base class */ public function fromArray(array $data) { $resultData = array(); $resultTmx = new Application_Util_TmxFile(); foreach ($data as $translationUnit => $variants) { foreach ($variants as $language => $contents) { if (is_array($contents) && isset($contents['filename']) && isset($contents['contents'])) { $filePath = $this->_contentBasepath . DIRECTORY_SEPARATOR . $contents['filename']; $resultData[$filePath] = $contents['contents']; $contents = $contents['filename']; } $resultTmx->setVariantSegment($translationUnit, $language, $contents); } } $this->setContent($resultData); $this->setTranslation($resultTmx->toArray()); }