Zend_Form, Russification error messages

not Publish your article. Here is a link to the original http://web-blog.org.ua/articles/uchim-zend-form-russkomu-yazuky But this link is not working.
Therefore, in order to avoid the loss of such a valuable, in my opinion, the information, I decided to census still here. I hope the author won't mind.

The full article decided not to write, and only post useful code. Those who will need to solve a problem — all will understand.

// Array of translated messages
$data = array(
Zend_Validate_Alnum::NOT_ALNUM => 'Entered value is "%value%" is wrong. Allowed only Latin symbols and figures',
Zend_Validate_Alnum::STRING_EMPTY = > 'the Field cannot be empty. Fill it up please',
Zend_Validate_Alpha::NOT_ALPHA => 'Enter only letters',
Zend_Validate_Alpha::STRING_EMPTY = > 'the Field cannot be empty. Fill it up please',
Zend_Validate_Barcode_UpcA::INVALID => '"%value% incorrect UPC-A bar code"',
Zend_Validate_Barcode_UpcA::INVALID_LENGTH => 'invalid value "%value%". Enter the 12 characters',
Zend_Validate_Barcode_Ean13::INVALID => '"%value% incorrect EAN-13 bar code',
Zend_Validate_Barcode_Ean13::INVALID_LENGTH => 'invalid value "%value%". Enter the 13 characters',
Zend_Validate_Between::NOT_BETWEEN = > '"%value%" is not between "%min%" and "%max%", inclusive,'
Zend_Validate_Between::NOT_BETWEEN_STRICT => '"%value%" is not between "%min%" and "%max%"'
Zend_Validate_Ccnum::LENGTH => '"%value%" must be a numerical value of 13 to 19 digits long',
Zend_Validate_Ccnum::CHECKSUM = > 'checksum failed. The value "%value%" is incorrect',
Zend_Validate_Date::NOT_YYYY_MM_DD = > '"%value%" does not fit the format year-month-day(eg. 2008-11-03)',
Zend_Validate_Date::INVALID => '"%value%" - wrong date',
Zend_Validate_Date::FALSEFORMAT = > '"%value%" is not the correct format,
Zend_Validate_Digits::NOT_DIGITS => 'Value "%value%" is wrong. Enter only digits',
Zend_Validate_Digits::STRING_EMPTY = > 'the Field cannot be empty. Fill it up please',
Zend_Validate_EmailAddress::INVALID => '"%value%" wrong e-mail address. Enter it in the format name@domain',
Zend_Validate_EmailAddress::INVALID_HOSTNAME => '"%hostname%" invalid domain address "%value%"'
Zend_Validate_EmailAddress::INVALID_MX_RECORD => 'Domain "%hostname%" has no MX record about the address "%value%"'
Zend_Validate_EmailAddress::DOT_ATOM => '"%localPart%" does not match format dot-atom',
Zend_Validate_EmailAddress::QUOTED_STRING => '"%localPart%" does not match the format specified for the string'
Zend_Validate_EmailAddress::INVALID_LOCAL_PART => '"%localPart%" is not the correct name for address "%value%", enter the address of the form name@domain',
Zend_Validate_Float::NOT_FLOAT => '"%value%" is not a decimal number,
Zend_Validate_GreaterThan::NOT_GREATER => '"%value%" does not exceed "%min%"'
Zend_Validate_Hex::NOT_HEX => '"%value%" contains not only hexadecimal characters',
Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED => '"%value%" is the IP address, but IP addresses are not allowed ',
Zend_Validate_Hostname::UNKNOWN_TLD => '"%value%" is the DNS host name, but it must be from TLD-list',
Zend_Validate_Hostname::INVALID_DASH => '"%value%" is the DNS host name, but the sign "-" is in the wrong place',
Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA => '"%value%" is the DNS host name, but it does not match the TLD for the TLD "%tld%"'
Zend_Validate_Hostname::UNDECIPHERABLE_TLD => '"%value%" is the DNS host name. Cannot extract TLD part',
Zend_Validate_Hostname::INVALID_HOSTNAME = > '"%value%" - does not match the expected structure for a DNS hostname',
Zend_Validate_Hostname::INVALID_LOCAL_NAME => '"%value%" - address is not a valid local network address',
Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED => '"%value%" - address is a network location, but the local network addresses are not allowed',
Zend_Validate_Identical::NOT_SAME = > 'the Values do not match',
Zend_Validate_Identical::MISSING_TOKEN => 'is Not entered the value for the identity'
Zend_Validate_InArray::NOT_IN_ARRAY => '"%value%" is not found in the listed allowable values',
Zend_Validate_Int::NOT_INT => '"%value%" is not an integer value',
Zend_Validate_Ip::NOT_IP_ADDRESS => '"%value%" is not a valid IP address',
Zend_Validate_LessThan::NOT_LESS = > '"%value%" not less than "%max%"'
Zend_Validate_NotEmpty::IS_EMPTY = > 'the value Entered is empty, fill in the field please',
Zend_Validate_Regex::NOT_MATCH = > 'the Value "%value%" does not fit the regular expression pattern "%pattern%"'
Zend_Validate_StringLength::TOO_SHORT = > 'Length of the entered value "%value%" is less than %min% characters.',
);
// create an instance of Zend_Translate adapter Array using
$translator = new Zend_Translate_Adapter_Array($data);
// create our form
$form = new Zend_Form();
// pass it our Zend_Translate
$form- > setTranslator($translator);
/**
* Execute other code, e.g., custom form
*/


Made a little differently — inherited class Zend_Form and has done all of this in its constructor, now use it.

class My_Form extends Zend_Form {
public function __construct() {
parent::__construct();
$data = array(
...
...
...
);
$translator = new Zend_Translate_Adapter_Array($data);
$this- > setTranslator($translator);
}
}


Question for experts ZF — maybe there's a more careful way to do this? For example, through static some methods to set the translations for validators forms for the whole application?
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Automatically create Liquibase migrations for PostgreSQL

Vkontakte sync with address book for iPhone. How it was done

What part of the archived web