function set($locale) { global $__locale, $__text, $service; if (strtolower($locale) == 'auto') { $locale = 'ko'; $supportedLanguages = Locale::getSupportedLocales(); if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $_accepted) { if (in_array($_accepted, $supportedLanguages)) { $locale = $_accepted; break; } } } } list($common) = explode('-', $locale, 2); Locale::refreshLocaleResource($locale); if (file_exists($__locale['directory'] . '/' . $locale . '.php')) { include($__locale['directory'] . '/' . $locale . '.php'); $__locale['locale'] = $locale; return true; } else if (($common != $locale) && file_exists($__locale['directory'] . '/' . $common . '.php')) { include($__locale['directory'] . '/' . $common . '.php'); $__locale['locale'] = $common; return true; } return false; }
/** * Return the key name of the user's currently selected locale (default * is "en_US" for U.S. English). * @return string */ function getLocale() { static $currentLocale; if (!isset($currentLocale)) { if (defined('SESSION_DISABLE_INIT') || !Config::getVar('general', 'installed')) { // If the locale is specified in the URL, allow // it to override. (Necessary when locale is // being set, as cookie will not yet be re-set) $locale = Request::getUserVar('setLocale'); if (empty($locale) || !in_array($locale, array_keys(Locale::getSupportedLocales()))) { $locale = Request::getCookieVar('currentLocale'); } } else { $sessionManager =& SessionManager::getManager(); $session =& $sessionManager->getUserSession(); $locale = $session->getSessionVar('currentLocale'); $journal =& Request::getJournal(); $site =& Request::getSite(); if (!isset($locale)) { $locale = Request::getCookieVar('currentLocale'); } if (isset($locale)) { // Check if user-specified locale is supported if ($journal != null) { $locales =& $journal->getSupportedLocaleNames(); } else { $locales =& $site->getSupportedLocaleNames(); } if (!in_array($locale, array_keys($locales))) { unset($locale); } } if (!isset($locale)) { // Use journal/site default if ($journal != null) { $locale = $journal->getPrimaryLocale(); } if (!isset($locale)) { $locale = $site->getPrimaryLocale(); } } } if (!Locale::isLocaleValid($locale)) { $locale = LOCALE_DEFAULT; } $currentLocale = $locale; } return $currentLocale; }
/** * Add hidden form parameters for the localized fields for this form * and display the language chooser field * @param $params array * @param $smarty object */ function smartyFormLanguageChooser($params, &$smarty) { // Echo back all non-current language field values so that they // are not lost. $formLocale = $smarty->get_template_vars('formLocale'); foreach ($this->getLocaleFieldNames() as $field) { $values = $this->getData($field); if (!is_array($values)) { continue; } foreach ($values as $locale => $value) { if ($locale != $formLocale) { $this->_decomposeArray($field, $value, array($locale)); } } } // Display the language selector widget. $formLocale = $smarty->get_template_vars('formLocale'); echo '<div id="languageSelector"><select size="1" name="formLocale" id="formLocale" onchange="changeFormAction(\'' . htmlentities($params['form'], ENT_COMPAT, LOCALE_ENCODING) . '\', \'' . htmlentities($params['url'], ENT_QUOTES, LOCALE_ENCODING) . '\')" class="selectMenu">'; foreach (Locale::getSupportedLocales() as $locale => $name) { echo '<option ' . ($locale == $formLocale ? 'selected="selected" ' : '') . 'value="' . htmlentities($locale, ENT_COMPAT, LOCALE_ENCODING) . '">' . htmlentities($name, ENT_COMPAT, LOCALE_ENCODING) . '</option>'; } echo '</select></div>'; }
/** * Delete a book for review by book ID. * @param $bookId int */ function deleteBookForReviewById($bookId) { $book =& $this->getBookForReview($bookId); if ($book) { // Delete authors $this->bookForReviewAuthorDao->deleteAuthorsByBookForReview($bookId); // Delete cover image files (for all locales) from the filesystem import('file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $locales = Locale::getSupportedLocales(); foreach ($locales as $locale) { $publicFileManager->removeJournalFile($book->getJournalId(), $book->getFileName($locale)); } // Delete settings $this->update('DELETE FROM books_for_review_settings WHERE book_id = ?', $bookId); // Delete book $this->update('DELETE FROM books_for_review WHERE book_id = ?', $bookId); } }
/** * Translate an ISO639-2b compatible 3-letter string * into the PKP locale identifier. * * This can be ambiguous if several locales are defined * for the same language. In this case we'll use the * primary locale to disambiguate. * * If that still doesn't determine a unique locale then * we'll choose the first locale found. * * @param $iso3letter string * @return string */ function getLocaleFrom3LetterIso($iso3Letter) { assert(strlen($iso3Letter) == 3); $primaryLocale = Locale::getPrimaryLocale(); $localeCandidates = array(); $locales =& Locale::_getAllLocalesCacheContent(); foreach ($locales as $locale => $localeData) { assert(isset($localeData['iso639-2b'])); if ($localeData['iso639-2b'] == $iso3Letter) { if ($locale == $primaryLocale) { // In case of ambiguity the primary locale // overrides all other options so we're done. return $primaryLocale; } $localeCandidates[] = $locale; } } // Return null if we found no candidate locale. if (empty($localeCandidates)) { return null; } if (count($localeCandidates) > 1) { // Check whether one of the candidate locales // is a supported locale. If so choose the first // supported locale. $supportedLocales = Locale::getSupportedLocales(); foreach ($supportedLocales as $supportedLocale => $localeName) { if (in_array($supportedLocale, $localeCandidates)) { return $supportedLocale; } } } // If there is only one candidate (or if we were // unable to disambiguate) then return the unique // (first) candidate found. return array_shift($localeCandidates); }
function smartyFBVElementMultilingual($params, &$smarty, $content = null) { if (!isset($params['value']) || !is_array($params['value'])) { $smarty->trigger_error('FBV: value parameter must be an array for multilingual elements'); } if (!isset($params['name'])) { $smarty->trigger_error('FBV: parameter must be set'); } $required = isset($params['required']) ? $params['required'] : false; $returner = ''; $values = $params['value']; $name = $params['name']; foreach (Locale::getSupportedLocales() as $locale => $localeName) { // if the field is required, only set the main locale as required and others optional if ($locale == Locale::getPrimaryLocale()) { $params['required'] = $required; } else { $params['required'] = false; } $params['name'] = $name . "[{$locale}]"; $params['value'] = $values[$locale]; $returner .= $localeName . ' ' . $this->smartyFBVElement($params, $smarty, $content) . '<br />'; } return $returner; }
/** * Delete a submissionChecklist * @param $args array * @param $request PKPRequest * @return string Serialized JSON object */ function deleteItem($args, &$request) { $rowId = $request->getUserVar('rowId'); $router =& $request->getRouter(); $press =& $router->getContext($request); // get all of the submissionChecklists $submissionChecklistAll = $press->getSetting('submissionChecklist'); foreach (Locale::getSupportedLocales() as $locale => $name) { if (isset($submissionChecklistAll[$locale][$rowId])) { unset($submissionChecklistAll[$locale][$rowId]); } else { // only fail if the currently displayed locale was not set // (this is the one that needs to be removed from the currently displayed grid) if ($locale == Locale::getLocale()) { $json = new JSON(false, Locale::translate('manager.setup.errorDeletingSubmissionChecklist')); return $json->getString(); exit; } } } $press->updateSetting('submissionChecklist', $submissionChecklistAll, 'object', true); $json = new JSON(true); return $json->getString(); }
/** * Save email template. */ function execute($args, &$request) { $router =& $request->getRouter(); $press =& $router->getContext($request); $submissionChecklistAll = $press->getSetting('submissionChecklist'); //FIXME: a bit of kludge to get unique submissionChecklist id's $this->submissionChecklistId = $this->submissionChecklistId ? $this->submissionChecklistId : max(array_keys($submissionChecklistAll[Locale::getPrimaryLocale()])) + 1; $checklistItem = $this->getData('checklistItem'); foreach (Locale::getSupportedLocales() as $locale => $name) { $submissionChecklistAll[$locale][$this->submissionChecklistId]['content'] = $checklistItem[$locale]; } $press->updateSetting('submissionChecklist', $submissionChecklistAll, 'object', true); return true; }