CC-1960: Internationalize Airtime / Support translations
- overwrote default zend form error messages
This commit is contained in:
parent
37ce75f686
commit
9acfb6c181
10 changed files with 94 additions and 29 deletions
|
@ -10,6 +10,7 @@ require_once 'Preference.php';
|
|||
require_once "DateHelper.php";
|
||||
require_once "OsPath.php";
|
||||
require_once "Database.php";
|
||||
require_once __DIR__.'/forms/helpers/ValidationTypes.php';
|
||||
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm
|
|||
{
|
||||
public function init()
|
||||
{
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
// retrieves the length limit for each char field
|
||||
// and store to assoc array
|
||||
$maxLens = Application_Model_Show::getMaxLengths();
|
||||
|
@ -26,9 +27,8 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm
|
|||
'class' => 'input_text',
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array('NotEmpty'),
|
||||
'value' => _('Untitled Show'),
|
||||
'validators' => array(array('StringLength', false, array(0, $maxLens['name'])))
|
||||
'validators' => array($notEmptyValidator, array('StringLength', false, array(0, $maxLens['name'])))
|
||||
));
|
||||
|
||||
// Add URL element
|
||||
|
@ -37,7 +37,7 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm
|
|||
'class' => 'input_text',
|
||||
'required' => false,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array('NotEmpty', array('StringLength', false, array(0, $maxLens['url'])))
|
||||
'validators' => array($notEmptyValidator, array('StringLength', false, array(0, $maxLens['url'])))
|
||||
));
|
||||
|
||||
// Add genre element
|
||||
|
|
|
@ -9,6 +9,12 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
array('ViewScript', array('viewScript' => 'form/add-show-when.phtml'))
|
||||
));
|
||||
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
$dateValidator = Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY-MM-DD");
|
||||
$regexValidator = Application_Form_Helper_ValidationTypes::overrideRegexValidator(
|
||||
"/^[0-2]?[0-9]:[0-5][0-9]$/",
|
||||
_("'%value%' does not fit the time format 'HH:mm'"));
|
||||
|
||||
// Add start date element
|
||||
$startDate = new Zend_Form_Element_Text('add_show_start_date');
|
||||
$startDate->class = 'input_text';
|
||||
|
@ -17,8 +23,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))))
|
||||
$notEmptyValidator,
|
||||
$dateValidator))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$startDate->setAttrib('alt', 'date');
|
||||
$this->addElement($startDate);
|
||||
|
@ -30,9 +36,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
->setValue('00:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Time format should be HH:mm')))
|
||||
$notEmptyValidator,
|
||||
$regexValidator
|
||||
))->setDecorators(array('ViewHelper'));
|
||||
$startTime->setAttrib('alt', 'time');
|
||||
$this->addElement($startTime);
|
||||
|
@ -45,8 +50,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))))
|
||||
$notEmptyValidator,
|
||||
$dateValidator))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endDate->setAttrib('alt', 'date');
|
||||
$this->addElement($endDate);
|
||||
|
@ -58,9 +63,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
->setValue('01:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Time format should be HH:mm')))))
|
||||
$notEmptyValidator,
|
||||
$regexValidator))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endTime->setAttrib('alt', 'time');
|
||||
$this->addElement($endTime);
|
||||
|
|
|
@ -10,6 +10,8 @@ class Application_Form_AddUser extends Zend_Form
|
|||
'../application/validate',
|
||||
'validate');
|
||||
* */
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
$emailValidator = Application_Form_Helper_ValidationTypes::overrideEmailAddressValidator();
|
||||
|
||||
$this->setAttrib('id', 'user_form');
|
||||
|
||||
|
@ -21,6 +23,7 @@ class Application_Form_AddUser extends Zend_Form
|
|||
$login->setLabel(_('Username:'));
|
||||
$login->setAttrib('class', 'input_text');
|
||||
$login->setRequired(true);
|
||||
$login->addValidator($notEmptyValidator);
|
||||
$login->addFilter('StringTrim');
|
||||
//$login->addValidator('UserNameValidate');
|
||||
$this->addElement($login);
|
||||
|
@ -30,21 +33,21 @@ class Application_Form_AddUser extends Zend_Form
|
|||
$password->setAttrib('class', 'input_text');
|
||||
$password->setRequired(true);
|
||||
$password->addFilter('StringTrim');
|
||||
$password->addValidator('NotEmpty');
|
||||
$password->addValidator($notEmptyValidator);
|
||||
$this->addElement($password);
|
||||
|
||||
$firstName = new Zend_Form_Element_Text('first_name');
|
||||
$firstName->setLabel(_('Firstname:'));
|
||||
$firstName->setAttrib('class', 'input_text');
|
||||
$firstName->addFilter('StringTrim');
|
||||
$firstName->addValidator('NotEmpty');
|
||||
$firstName->addValidator($notEmptyValidator);
|
||||
$this->addElement($firstName);
|
||||
|
||||
$lastName = new Zend_Form_Element_Text('last_name');
|
||||
$lastName->setLabel(_('Lastname:'));
|
||||
$lastName->setAttrib('class', 'input_text');
|
||||
$lastName->addFilter('StringTrim');
|
||||
$lastName->addValidator('NotEmpty');
|
||||
$lastName->addValidator($notEmptyValidator);
|
||||
$this->addElement($lastName);
|
||||
|
||||
$email = new Zend_Form_Element_Text('email');
|
||||
|
@ -52,7 +55,8 @@ class Application_Form_AddUser extends Zend_Form
|
|||
$email->setAttrib('class', 'input_text');
|
||||
$email->addFilter('StringTrim');
|
||||
$email->setRequired(true);
|
||||
$email->addValidator('EmailAddress');
|
||||
$email->addValidator($notEmptyValidator);
|
||||
$email->addValidator($emailValidator);
|
||||
$this->addElement($email);
|
||||
|
||||
$cellPhone = new Zend_Form_Element_Text('cell_phone');
|
||||
|
@ -71,7 +75,7 @@ class Application_Form_AddUser extends Zend_Form
|
|||
$jabber->setLabel(_('Jabber:'));
|
||||
$jabber->setAttrib('class', 'input_text');
|
||||
$jabber->addFilter('StringTrim');
|
||||
$jabber->addValidator('EmailAddress');
|
||||
$jabber->addValidator($emailValidator);
|
||||
$this->addElement($jabber);
|
||||
|
||||
$select = new Zend_Form_Element_Select('type');
|
||||
|
|
|
@ -49,9 +49,9 @@ class Application_Form_EditAudioMD extends Zend_Form
|
|||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
array('date', false, array('YYYY-MM-DD')),
|
||||
array('date', false, array('YYYY-MM')),
|
||||
array('date', false, array('YYYY'))
|
||||
Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY-MM-DD"),
|
||||
Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY-MM"),
|
||||
Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY")
|
||||
)
|
||||
));
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
|
|||
public function init()
|
||||
{
|
||||
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/preferences_general.phtml'))
|
||||
));
|
||||
|
@ -31,9 +32,9 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
|
|||
$this->addElement('text', 'stationDefaultFade', array(
|
||||
'class' => 'input_text',
|
||||
'label' => _('Default Fade (s):'),
|
||||
'required' => false,
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(array('regex', false,
|
||||
'validators' => array(array($notEmptyValidator, 'regex', false,
|
||||
array('/^[0-9]{1,2}(\.\d{1})?$/',
|
||||
'messages' => _('enter a time in seconds 0{.0}')))),
|
||||
'value' => $defaultFade,
|
||||
|
|
|
@ -10,11 +10,13 @@ class Application_Form_PasswordChange extends Zend_Form
|
|||
array('ViewScript', array('viewScript' => 'form/password-change.phtml'))
|
||||
));
|
||||
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
|
||||
$this->addElement('password', 'password', array(
|
||||
'label' => _('Password'),
|
||||
'required' => true,
|
||||
'filters' => array('stringTrim'),
|
||||
'validators' => array(
|
||||
'validators' => array($notEmptyValidator,
|
||||
array('stringLength', false, array(6, 80)),
|
||||
),
|
||||
'decorators' => array(
|
||||
|
@ -31,7 +33,7 @@ class Application_Form_PasswordChange extends Zend_Form
|
|||
return $value == $context['password'];
|
||||
}),
|
||||
),
|
||||
'errorMessages' => array("Password confirmation does not match your password."),
|
||||
'errorMessages' => array(_("Password confirmation does not match your password.")),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
|
|
|
@ -7,9 +7,7 @@ class ConditionalNotEmpty extends Zend_Validate_Abstract
|
|||
{
|
||||
const KEY_IS_EMPTY = 'keyIsEmpty';
|
||||
|
||||
protected $_messageTemplates = array(
|
||||
self::KEY_IS_EMPTY => 'Value is required and can\'t be empty'
|
||||
);
|
||||
protected $_messageTemplates;
|
||||
|
||||
protected $_fieldValues;
|
||||
|
||||
|
@ -24,6 +22,9 @@ class ConditionalNotEmpty extends Zend_Validate_Abstract
|
|||
public function __construct($fieldValues)
|
||||
{
|
||||
$this->_fieldValues = $fieldValues;
|
||||
$this->_messageTemplates = array(
|
||||
self::KEY_IS_EMPTY => _("Value is required and can't be empty")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
52
airtime_mvc/application/forms/helpers/ValidationTypes.php
Normal file
52
airtime_mvc/application/forms/helpers/ValidationTypes.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
Class Application_Form_Helper_ValidationTypes {
|
||||
|
||||
public static function overrideNotEmptyValidator()
|
||||
{
|
||||
$validator = new Zend_Validate_NotEmpty();
|
||||
$validator->setMessage(
|
||||
_("Value is required and can't be empty"),
|
||||
Zend_Validate_NotEmpty::IS_EMPTY
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overrideEmailAddressValidator()
|
||||
{
|
||||
$validator = new Zend_Validate_EmailAddress();
|
||||
$validator->setMessage(
|
||||
_("'%value%' is no valid email address in the basic format local-part@hostname"),
|
||||
Zend_Validate_EmailAddress::INVALID_FORMAT
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overrrideDateValidator($p_format)
|
||||
{
|
||||
$validator = new Zend_Validate_Date();
|
||||
|
||||
$validator->setFormat($p_format);
|
||||
|
||||
$validator->setMessage(
|
||||
_("'%value%' does not fit the date format '%format%'"),
|
||||
Zend_Validate_Date::FALSEFORMAT
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overrideRegexValidator($p_pattern, $p_msg)
|
||||
{
|
||||
$validator = new Zend_Validate_Regex($p_pattern);
|
||||
|
||||
$validator->setMessage(
|
||||
$p_msg,
|
||||
Zend_Validate_Regex::NOT_MATCH
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
}
|
|
@ -33,7 +33,7 @@ class Application_Model_Auth
|
|||
$message = sprintf(_("Hi %s, \n\nClick this link to reset your password: "), $user->getDbLogin());
|
||||
$message .= "{$e_link_protocol}://{$e_link_base}:{$e_link_port}{$e_link_path}";
|
||||
|
||||
$success = Application_Model_Email::send('Airtime Password Reset', $message, $user->getDbEmail());
|
||||
$success = Application_Model_Email::send(_('Airtime Password Reset'), $message, $user->getDbEmail());
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue