Hy,

public function getAlpha($name, $locale = false) {
   $characters = 'a-z';
   if ($locale ! = = false) {
       $characters = Zend_Locale_Data::getContent($locale, 'characters');
   }
   preg_match($characters, '/[' . $characters . ']/', $result);
   return $result;
}

I like your idea, especially leaving locale-dependent details to
Zend_Locale. I have a couple of questions related to this:

1. What are your thoughts about passing $locale to the constructor
instead of each individual method?

I preferr using both.
Example:
In Zend_Date you can use the optional $locale parameter by creation
$date = new Zend_Date($myDate, $myLocale);

But you can also use $date = new Zend_Date($myDate);
Then your individual locale will be used.

Having the locale in each calling function adds the functionality to have informations from an other locale. When you are using 'en' for creation you are able to get back the date for 'de' instead of your 'en'.
So instead of 11-30-2006 you will get 30.11.2006.

Using a locale for creation within Zend_Filter would mean that all functions within Zend_Filter are locale aware which is not done right now for the moment. Also is you have a locale by creation our alpha function will always ask the locale-chars. So even with 'en' the
chars will be asked which slowers our function.

Locale should only be used where its informations are usefull and a must for proper results.

2. Is there a clever solution that would let people allow multiple
locales? For example, even if I don't need to allow all possible
alphabetic characters, I might want to all possible English, French,
Spanish, and German alphabetic characters. I haven't looked at
Zend_Locale, so my apologies if this is a redundant question.

You will just have to ask each locale for the proper characters, and throw all of them into one regex. Zend_Locale itself is not able to do so... think of Date. It would be nonsense to have the Date for 'en' and 'ru' extracted the same time. So you will get characters like this 'a-z ß ä ö ü' and 'a-z é á ú' and you or our alpha function would have to create an complete request like 'a-z ä ö ü é á ú'. This way it will work.

Greetings
Thomas

Reply via email to