getEnabled()) { // Add custom locale data for already registered locale files. $locale = AppLocale::getLocale(); $localeFiles = AppLocale::getLocaleFiles($locale); $journal = Request::getJournal(); $journalId = $journal->getId(); $publicFilesDir = Config::getVar('files', 'public_files_dir'); $customLocalePathBase = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR; import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); foreach ($localeFiles as $localeFile) { $customLocalePath = $customLocalePathBase . $localeFile->getFilename(); if ($fileManager->fileExists($customLocalePath)) { AppLocale::registerLocaleFile($locale, $customLocalePath, true); } } // Add custom locale data for all locale files registered after this plugin HookRegistry::register('PKPLocale::registerLocaleFile', array(&$this, 'addCustomLocale')); } return true; } return false; } function addCustomLocale($hookName, $args) { $locale =& $args[0]; $localeFilename =& $args[1]; $journal = Request::getJournal(); $journalId = $journal->getId(); $publicFilesDir = Config::getVar('files', 'public_files_dir'); $customLocalePath = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFilename; import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); if ($fileManager->fileExists($customLocalePath)) { AppLocale::registerLocaleFile($locale, $customLocalePath, false); } return true; } function getDisplayName() { return __('plugins.generic.customLocale.name'); } function getDescription() { return __('plugins.generic.customLocale.description'); } function smartyPluginUrl($params, &$smarty) { $path = array($this->getCategory(), $this->getName()); if (is_array($params['path'])) { $params['path'] = array_merge($path, $params['path']); } elseif (!empty($params['path'])) { $params['path'] = array_merge($path, array($params['path'])); } else { $params['path'] = $path; } if (!empty($params['key'])) { $params['path'] = array_merge($params['path'], array($params['key'])); unset($params['key']); } if (!empty($params['file'])) { $params['path'] = array_merge($params['path'], array($params['file'])); unset($params['file']); } return $smarty->smartyUrl($params, $smarty); } function getManagementVerbs() { $verbs = array(); if ($this->getEnabled()) { $verbs[] = array('index', __('plugins.generic.customLocale.customize')); } return parent::getManagementVerbs($verbs); } /** * Execute a management verb on this plugin * @param $verb string * @param $args array * @param $message string Result status message * @param $messageParams array Parameters for the message key * @return boolean */ function manage($verb, $args, &$message, &$messageParams) { if (!parent::manage($verb, $args, $message, $messageParams)) return false; $this->import('CustomLocaleHandler'); $customLocaleHandler = new CustomLocaleHandler($this->getName()); switch ($verb) { case 'edit': $customLocaleHandler->edit($args); return true; case 'saveLocaleChanges': $customLocaleHandler->saveLocaleChanges($args); return true; case 'editLocaleFile': $customLocaleHandler->editLocaleFile($args); return true; case 'saveLocaleFile': $customLocaleHandler->saveLocaleFile($args); return true; default: $customLocaleHandler->index(); return true; } } } ?>