コード例 #1
0
 function isLocaleFile($locale, $filename)
 {
     if (in_array($filename, TranslatorAction::getLocaleFiles($locale))) {
         return true;
     }
     if (in_array($filename, TranslatorAction::getMiscLocaleFiles($locale))) {
         return true;
     }
     if ($filename == Locale::getEmailTemplateFilename($locale)) {
         return true;
     }
     return false;
 }
コード例 #2
0
 function saveEmail($args)
 {
     list($plugin) = TranslatorHandler::validate();
     TranslatorHandler::setupTemplate();
     $locale = array_shift($args);
     if (!Locale::isLocaleValid($locale)) {
         Request::redirect(null, null, 'index');
     }
     $emails = TranslatorAction::getEmailTemplates($locale);
     $referenceEmails = TranslatorAction::getEmailTemplates(MASTER_LOCALE);
     $emailKey = array_shift($args);
     if (!in_array($emailKey, array_keys($referenceEmails)) && !in_array($emailKey, array_keys($emails))) {
         Request::redirect(null, null, 'index');
     }
     import('i18n.EditableEmailFile');
     $file =& new EditableEmailFile($locale, Locale::getEmailTemplateFilename($locale));
     $subject = TranslatorHandler::correctCr(Request::getUserVar('subject'));
     $body = TranslatorHandler::correctCr(Request::getUserVar('body'));
     $description = TranslatorHandler::correctCr(Request::getUserVar('description'));
     if (!$file->update($emailKey, $subject, $body, $description)) {
         $file->insert($emailKey, $subject, $body, $description);
     }
     $file->write();
     if (Request::getUserVar('returnToCheck') == 1) {
         Request::redirect(null, null, 'check', $locale);
     } else {
         Request::redirect(null, null, 'edit', $locale);
     }
 }
コード例 #3
0
ファイル: Locale.inc.php プロジェクト: alenoosh/ojs
 /**
  * Test the emails in the supplied locale against those in the supplied
  * reference locale.
  * @param $locale string
  * @param $referenceLocale string
  * @return array List of errors
  */
 function testEmails($locale, $referenceLocale)
 {
     $errors = array();
     $xmlParser =& new XMLParser();
     $referenceEmails =& $xmlParser->parse(Locale::getEmailTemplateFilename($referenceLocale));
     $emails =& $xmlParser->parse(Locale::getEmailTemplateFilename($locale));
     $emailsTable =& $emails->getChildByName('table');
     $referenceEmailsTable =& $referenceEmails->getChildByName('table');
     $matchedReferenceEmails = array();
     // Pass 1: For all translated emails, check that they match
     // against reference translations.
     for ($emailIndex = 0; ($email =& $emailsTable->getChildByName('row', $emailIndex)) !== null; $emailIndex++) {
         // Extract the fields from the email to be tested.
         $fields = Locale::extractFields($email);
         // Locate the reference email and extract its fields.
         for ($referenceEmailIndex = 0; ($referenceEmail =& $referenceEmailsTable->getChildByName('row', $referenceEmailIndex)) !== null; $referenceEmailIndex++) {
             $referenceFields = Locale::extractFields($referenceEmail);
             if ($referenceFields['email_key'] == $fields['email_key']) {
                 break;
             }
         }
         // Check if a matching reference email was found.
         if (!isset($referenceEmail) || $referenceEmail === null) {
             $errors[EMAIL_ERROR_EXTRA_EMAIL][] = array('key' => $fields['email_key']);
             continue;
         }
         // We've successfully found a matching reference email.
         // Compare it against the translation.
         $bodyParams = Locale::getParameterNames($fields['body']);
         $referenceBodyParams = Locale::getParameterNames($referenceFields['body']);
         $diff = array_diff($bodyParams, $referenceBodyParams);
         if (!empty($diff)) {
             $errors[EMAIL_ERROR_DIFFERING_PARAMS][] = array('key' => $fields['email_key'], 'mismatch' => $diff);
         }
         $subjectParams = Locale::getParameterNames($fields['subject']);
         $referenceSubjectParams = Locale::getParameterNames($referenceFields['subject']);
         $diff = array_diff($subjectParams, $referenceSubjectParams);
         if (!empty($diff)) {
             $errors[EMAIL_ERROR_DIFFERING_PARAMS][] = array('key' => $fields['email_key'], 'mismatch' => $diff);
         }
         $matchedReferenceEmails[] = $fields['email_key'];
         unset($email);
         unset($referenceEmail);
     }
     // Pass 2: Make sure that there are no missing translations.
     for ($referenceEmailIndex = 0; ($referenceEmail =& $referenceEmailsTable->getChildByName('row', $referenceEmailIndex)) !== null; $referenceEmailIndex++) {
         // Extract the fields from the email to be tested.
         $referenceFields = Locale::extractFields($referenceEmail);
         if (!in_array($referenceFields['email_key'], $matchedReferenceEmails)) {
             $errors[EMAIL_ERROR_MISSING_EMAIL][] = array('key' => $referenceFields['email_key']);
         }
     }
     return $errors;
 }
コード例 #4
0
 function deleteEmail($args)
 {
     $this->validate();
     $plugin =& $this->plugin;
     $this->setupTemplate();
     $locale = array_shift($args);
     if (!Locale::isLocaleValid($locale)) {
         Request::redirect(null, null, null, 'index');
     }
     $emails = TranslatorAction::getEmailTemplates($locale);
     $referenceEmails = TranslatorAction::getEmailTemplates(MASTER_LOCALE);
     $emailKey = array_shift($args);
     if (!in_array($emailKey, array_keys($emails))) {
         Request::redirect(null, null, null, 'index');
     }
     import('file.EditableEmailFile');
     $file = new EditableEmailFile($locale, Locale::getEmailTemplateFilename($locale));
     $subject = Request::getUserVar('subject');
     $body = Request::getUserVar('body');
     $description = Request::getUserVar('description');
     if ($file->delete($emailKey)) {
         $file->write();
     }
     Request::redirect(null, null, null, 'edit', $locale, null, 'emails');
 }