/** * @param I18NContext $context * @param I18NFileHelper $fileHelper */ function init(I18NContext $context, I18NFileHelper $fileHelper) { $this->context = $context; $adminFactory = new Translation2AdminFactory(); $adminFactory->setContext($context); $repo = new I18NAdminRepository(); $repo->setFileHelper($fileHelper); $repo->setAdminFactory($adminFactory); $repo->load(); $tr_admin = new Translation2AdminWrapper(); $tr_admin->setContext($context); $tr_admin->setRepository($repo); $phraseDataFactory = new PhraseDataFactory(); $phraseDataFactory->setLanguageDataSource($this->languageDataSource); $phraseDataFactory->setTranslationDataSource($this->translationDataSource); $this->languageDataSource->setContext($context); $this->languageDataSource->setTranslator($tr_admin); $this->languageDataSource->setTrAdmin($tr_admin); $this->domainDataSource->setContext($context); $this->domainDataSource->setTranslator($tr_admin); $this->domainDataSource->setTrAdmin($tr_admin); $this->translationDataSource->setContext($context); $this->translationDataSource->setTranslator($tr_admin); $this->translationDataSource->setTrAdmin($tr_admin); $this->phraseDataSource->setContext($context); $this->phraseDataSource->setTranslator($tr_admin); $this->phraseDataSource->setTrAdmin($tr_admin); $this->phraseDataSource->setPhraseDataFactory($phraseDataFactory); }
function isValid($value) { $trAdminFactory = new Translation2AdminFactory(); $trAdmin = $trAdminFactory->createTrAdmin($value); if (strpos(strtolower(get_class($trAdmin)), 'translation2_admin') === false) { $errors[] = 'UPLOADED_LANG_FILE_STRUCTURE_IS_INVALID'; SJB_Logger::error('UPLOADED_LANG_FILE_STRUCTURE_IS_INVALID'); return false; } $file_langs_list = $trAdmin->getLangs(); $import_lang_id = (string) $this->dataReflector->get('languageId'); if (!array_key_exists($import_lang_id, $file_langs_list)) { $errors[] = 'UPLOADED_LANG_FILE_DOESNOT_HAVE_NECESSARY_LANGUAGE'; SJB_Logger::error('UPLOADED_LANG_FILE_DOESNOT_HAVE_NECESSARY_LANGUAGE'); return false; } return true; }
function importLangFile($file_name, $file_path) { $languageID = $this->fileHelper->getLanguageIDForImportFile($file_name); $file_paths = $this->fileHelper->getFilePathToLangFiles($languageID); $trAdminFactory = new Translation2AdminFactory(); $trAdmin = $trAdminFactory->createTrAdmin($file_path, true, true, $file_path); $trAdmin->getLanguagePages(); // set new lang paths $trAdmin->storage->setFileName($file_paths['languages']); $trAdmin->storage->setPagesFileNameOption($file_paths['pages']); //check meta separators if (isset($trAdmin->storage->_data['languages'][$languageID]['meta'])) { $meta = unserialize($trAdmin->storage->_data['languages'][$languageID]['meta']); if (isset($meta['decimal_separator']) && isset($meta['thousands_separator'])) { if (!$meta['decimal_separator']) { $meta['decimal_separator'] = !$meta['thousands_separator'] || $meta['thousands_separator'] == ',' ? '.' : ','; } if (!$meta['thousands_separator']) { $meta['thousands_separator'] = !$meta['decimal_separator'] || $meta['decimal_separator'] == ',' ? '.' : ','; } } else { $meta['decimal_separator'] = '.'; $meta['thousands_separator'] = ','; } $trAdmin->storage->_data['languages'][$languageID]['meta'] = serialize($meta); } $trAdmin->storage->_saveData(); $fileSystem = SJB_ObjectMother::createFileSystem(); $fileSystem->deleteFile($file_path); return true; }
/** * @param array $file_paths * @return mixed|object|Translation2_Admin */ private function getLanguagesTrAdmin($file_paths) { return $this->adminFactory->createTrAdmin($file_paths['languages'], false, true, $file_paths['pages']); }