function smarty_function_displayLanguageOption($params, &$smarty)
{
    // @codingStandardsIgnoreEnd
    static $translator = false;
    if (!$translator) {
        global $configArray;
        $translator = new I18N_Translator(array('lang', 'lang_local'), 'native', $configArray['System']['debug']);
    }
    return $translator->translate($params['text']);
}
Пример #2
0
 /**
  * Test the translator class.
  *
  * @return void
  * @access public
  */
 public function testTranslator()
 {
     // Save valid path to language files:
     $path = dirname(__FILE__) . '/../../../web/lang';
     // Test bad path:
     $translator = new I18N_Translator('/bad/garbage/illegal/path/', 'en');
     $error1 = $translator->error;
     // Test bad language code:
     $translator = new I18N_Translator($path, 'NOTAVALIDCODE');
     $error2 = $translator->error;
     // Make sure both error situations generated a warning and that the two
     // warnings are different!
     $this->assertTrue($error1 !== false);
     $this->assertTrue($error2 !== false);
     $this->assertTrue($error1 !== $error2);
     // Try to parse all available language files:
     $dir = opendir($path);
     if ($dir) {
         while ($file = readdir($dir)) {
             if (is_file($path . '/' . $file) && substr($file, -4) == '.ini') {
                 $lang = substr($file, 0, strlen($file) - 4);
                 $translator = new I18N_Translator($path, $lang);
                 // Make sure there were no errors loading the file and that
                 // the file contains at least ten words (an arbitrary number,
                 // but presumably a safe minimum for a legitimate language file).
                 $this->assertTrue($translator->error === false);
                 $this->assertTrue(count($translator->words) > 10);
             }
         }
     }
     // Test an actual translation:
     $translator = new I18N_Translator($path, 'es');
     $this->assertEquals($translator->translate('Author'), 'Autor');
     // Test missing translations, with and without debug mode on:
     $this->assertEquals($translator->translate('asdfasdfasdf'), 'asdfasdfasdf');
     $translator = new I18N_Translator($path, 'es', true);
     $this->assertEquals($translator->translate('asdfasdfasdf'), 'translate_index_not_found(asdfasdfasdf)');
 }
Пример #3
0
function translate($params)
{
    global $translator;
    // If no translator exists yet, create one -- this may be necessary if we
    // encounter a failure before we are able to load the global translator
    // object.
    if (!is_object($translator)) {
        global $configArray;
        $translator = new I18N_Translator('lang', $configArray['Site']['language'], $configArray['System']['missingTranslations']);
    }
    if (is_array($params)) {
        return $translator->translate($params['text']);
    } else {
        return $translator->translate($params);
    }
}
Пример #4
0
 /**
  * Process parameters and display the page.
  *
  * @return void
  * @access public
  */
 public function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     // Collect all messages so that nothing is overwritten
     $userMessages = array();
     $userErrors = array();
     // These require just a login
     if (UserAccount::isLoggedIn()) {
         // Update email address
         if (isset($_POST['email'])) {
             if ($user->changeEmailAddress($_POST['email'])) {
                 $userMessages[] = 'profile_update';
             }
         }
         $interface->assign('email', $user->email);
         // Update due date reminder
         if (isset($_POST['due_date_reminder'])) {
             $interval = $_POST['due_date_reminder'];
             if (is_numeric($interval) && $interval >= 0) {
                 if ($user->changeDueDateReminder($_POST['due_date_reminder'])) {
                     $userMessages[] = 'profile_update';
                 }
             }
         }
         $interface->assign('dueDateReminder', $user->due_date_reminder);
     }
     // Get My Profile
     if ($patron = UserAccount::catalogLogin()) {
         if (PEAR::isError($patron)) {
             $this->handleCatalogError($patron);
         } else {
             // Address change request form
             if (isset($_POST['changeAddressRequest'])) {
                 $profile = $this->catalog->getMyProfile($patron);
                 if (!PEAR::isError($profile)) {
                     $interface->assign('address1', isset($profile['address1']) ? $profile['address1'] : '');
                     $interface->assign('zip', isset($profile['zip']) ? $profile['zip'] : '');
                 }
                 $interface->display('/MyResearch/change-address.tpl');
                 return;
             }
             // Address change request
             if (isset($_POST['changeAddressLine1']) && isset($_POST['changeAddressZip'])) {
                 $profile = $this->catalog->getMyProfile($patron);
                 $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
                 $data['oldAddress1'] = isset($profile['address1']) ? $profile['address1'] : '';
                 $data['oldZip'] = isset($profile['zip']) ? $profile['zip'] : '';
                 $result = $this->sendEmail($patron, $data, 'Osoitteenmuutospyyntö', 'Emails/change-address.tpl');
                 if (!PEAR::isError($result)) {
                     $userMessages[] = 'request_change_email_sent';
                 } else {
                     error_log('Sending of address change request mail failed: ' . $result->getMessage());
                     $userErrors[] = 'request_change_email_failed';
                 }
             }
             // Messaging settings request form
             if (isset($_POST['changeMessagingSettingsRequest'])) {
                 $profile = $this->catalog->getMyProfile($patron);
                 if (isset($profile['messagingServices'])) {
                     $interface->assign('services', $profile['messagingServices']);
                     $emailDays = array();
                     foreach (array(1, 2, 3, 4, 5) as $day) {
                         if ($day == 1) {
                             $label = translate("messaging_settings_num_of_days");
                         } else {
                             $label = translate("messaging_settings_num_of_days_plural");
                             $label = str_replace('{1}', $day, $label);
                         }
                         $emailDays[] = $label;
                     }
                     $interface->assign('emailDays', $emailDays);
                     $interface->assign('days', array(1, 2, 3, 4, 5));
                     $interface->display('/MyResearch/change-messaging-settings.tpl');
                     return;
                 }
             }
             // Messaging settings request
             if (isset($_POST['changeMessagingSettings'])) {
                 // Translator for email message (always in Finnish)
                 $translator = new I18N_Translator(array('lang', 'lang_local'), 'fi', $configArray['System']['debug']);
                 $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
                 $data['pickUpNotice'] = $translator->translate('messaging_settings_method_' . $data['pickUpNotice']);
                 $data['overdueNotice'] = $translator->translate('messaging_settings_method_' . $data['overdueNotice']);
                 if ($data['dueDateAlert'] == 0) {
                     $data['dueDateAlert'] = $translator->translate('messaging_settings_method_none');
                 } else {
                     if ($data['dueDateAlert'] == 1) {
                         $data['dueDateAlert'] = $translator->translate('messaging_settings_num_of_days');
                     } else {
                         $txt = $translator->translate('messaging_settings_num_of_days_plural');
                         $txt = str_replace('{1}', $data['dueDateAlert'], $txt);
                         $data['dueDateAlert'] = $txt;
                     }
                 }
                 $result = $this->sendEmail($patron, $data, 'Viestiasetusten muutospyyntö', 'Emails/change-messaging-settings.tpl');
                 if (!PEAR::isError($result)) {
                     $userMessages[] = 'request_change_email_sent';
                 } else {
                     error_log('Sending of messaging settings change request mail failed: ' . $result->getMessage());
                     $userErrors[] = 'request_change_email_failed';
                 }
             }
             // Change home library
             if (isset($_POST['home_library']) && $_POST['home_library'] != "") {
                 $home_library = $_POST['home_library'];
                 if ($user->changeHomeLibrary($home_library)) {
                     $userMessages[] = 'profile_update';
                 } else {
                     $userErrors[] = 'profile_update_failed';
                 }
             }
             // Change Password
             if (isset($_POST['oldPassword']) && isset($_POST['newPassword']) && isset($_POST['newPassword2'])) {
                 if ($_POST['newPassword'] !== $_POST['newPassword2']) {
                     $userErrors[] = 'change_password_error_verification';
                 } else {
                     $result = $this->changePassword($_POST['oldPassword'], $_POST['newPassword']);
                     if (PEAR::isError($result)) {
                         $userErrors[] = $result->getMessage();
                     } else {
                         if ($result['success']) {
                             $userMessages[] = 'change_password_ok';
                             $user->changeCatalogPassword($_POST['newPassword']);
                             // Re-retrieve patron to make sure it's up to date
                             $patron = UserAccount::catalogLogin();
                         } else {
                             $userErrors[] = $result['status'];
                         }
                     }
                 }
             }
             // Change phone number
             if (isset($_POST['phone_number'])) {
                 $phoneNumber = trim($_POST['phone_number']);
                 if (preg_match('/^[\\+]?[ \\d\\-]+\\d+$/', $phoneNumber)) {
                     $result = $this->catalog->setPhoneNumber($patron, $phoneNumber);
                     if ($result['success']) {
                         $userMessages[] = 'phone_updated';
                         // Re-retrieve patron to make sure it's up to date
                         $patron = UserAccount::catalogLogin();
                     } else {
                         $userErrors[] = $result['sys_message'];
                     }
                 } else {
                     $userErrors[] = 'Phone Number is invalid';
                 }
             }
             // Change email address
             if (isset($_POST['email_address'])) {
                 $email = trim($_POST['email_address']);
                 if (Mail_RFC822::isValidInetAddress($email)) {
                     $result = $this->catalog->setEmailAddress($patron, $email);
                     if ($result['success']) {
                         $userMessages[] = 'email_updated';
                         // Re-retrieve patron to make sure it's up to date
                         $patron = UserAccount::catalogLogin();
                     } else {
                         $userErrors[] = $result['sys_message'];
                     }
                 } else {
                     $userErrors[] = 'Email address is invalid';
                 }
             }
             $result = $this->catalog->getMyProfile($patron);
             if (!PEAR::isError($result)) {
                 $result['home_library'] = $user->home_library;
                 $libs = $this->catalog->getPickUpLocations($patron);
                 $defaultPickUpLocation = $this->catalog->getDefaultPickUpLocation($patron);
                 $interface->assign('defaultPickUpLocation', $defaultPickUpLocation);
                 $interface->assign('pickup', $libs);
                 $interface->assign('profile', $result);
             } else {
                 $userErrors[] = $result->getMessage();
             }
             $result = $this->catalog->checkFunction('changePassword');
             if ($result !== false) {
                 $interface->assign('changePassword', $result);
             }
             $driver = isset($patron['driver']) ? $patron['driver'] : '';
             $interface->assign('driver', $driver);
         }
     }
     $interface->assign('userMsg', array_unique($userMessages));
     $interface->assign('userError', array_unique($userErrors));
     $interface->assign('hideDueDateReminder', isset($configArray['Site']['hideDueDateReminder']) && (bool) $configArray['Site']['hideDueDateReminder']);
     $interface->assign('hideProfileEmailAddress', isset($configArray['Site']['hideProfileEmailAddress']) && (bool) $configArray['Site']['hideProfileEmailAddress']);
     Login::setupLoginFormVars();
     $interface->setTemplate('profile.tpl');
     $interface->setPageTitle('My Profile');
     $interface->display('layout.tpl');
 }