| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
class patForms_AttributeFilter_Gettext extends patForms_AttributeFilter |
|---|
| 23 |
{ |
|---|
| 24 |
|
|---|
| 25 |
* use gettext marker |
|---|
| 26 |
* |
|---|
| 27 |
* defines whether to use a check for a "gettext:" token |
|---|
| 28 |
* @access private |
|---|
| 29 |
*/ |
|---|
| 30 |
var $_useMarker = true; |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
* attribute list |
|---|
| 34 |
* |
|---|
| 35 |
* list of attributes to handle |
|---|
| 36 |
* @access private |
|---|
| 37 |
*/ |
|---|
| 38 |
var $_attributes = array( 'label', 'title', 'description' ); |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
* define the attibute names to be translated with gettext |
|---|
| 42 |
* |
|---|
| 43 |
* By default the attributes 'label', 'title' and 'description' |
|---|
| 44 |
* will be translated. As those are the only attributes that contain |
|---|
| 45 |
* messages visible by human readers, this should be suffices. |
|---|
| 46 |
* Still, this list by be altered. |
|---|
| 47 |
* |
|---|
| 48 |
* @access public |
|---|
| 49 |
* @param array list of attributes to handle |
|---|
| 50 |
* @return boolean true on success |
|---|
| 51 |
*/ |
|---|
| 52 |
function setAttributes($attributes) |
|---|
| 53 |
{ |
|---|
| 54 |
$this->_attributes = $attributes; |
|---|
| 55 |
return true; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
* Filter attribute value on "set"-event |
|---|
| 60 |
* |
|---|
| 61 |
* @access public |
|---|
| 62 |
* @param string element's type |
|---|
| 63 |
* @param string attribute's names |
|---|
| 64 |
* @param mixed attribute's value |
|---|
| 65 |
* @return mixed true on success, patError-object on error |
|---|
| 66 |
*/ |
|---|
| 67 |
function onSet($type, $attribute, &$value) |
|---|
| 68 |
{ |
|---|
| 69 |
return $this->_translate($type, $attribute, $value); |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
* Filter attribute value on "apply"-event |
|---|
| 74 |
* |
|---|
| 75 |
* @access public |
|---|
| 76 |
* @param string element's type |
|---|
| 77 |
* @param string attribute's names |
|---|
| 78 |
* @param mixed attribute's value |
|---|
| 79 |
* @return mixed true on success, patError-object on error |
|---|
| 80 |
*/ |
|---|
| 81 |
function onApply($type, $attribute, &$value) |
|---|
| 82 |
{ |
|---|
| 83 |
return $this->_translate($type, $attribute, $value); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
* Translate string |
|---|
| 88 |
* |
|---|
| 89 |
* @access private |
|---|
| 90 |
* @param string element's type |
|---|
| 91 |
* @param string attribute's names |
|---|
| 92 |
* @param mixed attribute's value |
|---|
| 93 |
* @return mixed true on success, patError-object on error |
|---|
| 94 |
*/ |
|---|
| 95 |
function _translate($type, $attribute, &$value) |
|---|
| 96 |
{ |
|---|
| 97 |
|
|---|
| 98 |
if (!in_array( $attribute, $this->_attributes)) { |
|---|
| 99 |
return true; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
if (!is_string($value)) { |
|---|
| 104 |
return true; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
if (!$this->_useMarker) { |
|---|
| 109 |
$value = gettext($value); |
|---|
| 110 |
return true; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
if (preg_match('/^gettext:\'(.*)\'/', $value, $match)) { |
|---|
| 115 |
$value = gettext($match[1]); |
|---|
| 116 |
return true; |
|---|
| 117 |
} |
|---|
| 118 |
} |
|---|
| 119 |
} |
|---|
| 120 |
?> |
|---|