Hi,
Making 126 subclasses, one for every language, is a very bad design idea.
From the first look, yes, but from the second view maybe not. These
classes would be very, very small. Making Zend_Filter locale aware is
pretty hard to reach. You will have a big switch ... case-statement in
every filter function which is not the best I guess. Having classes with
a small footprint is maybe the better solution as in normal use-cases
just one class must be loaded.
Why would you use a switch statement...
You should first look at the normal uswage for locale aware classes.
// example code
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;
}
Where should a switch statement be used here ???
The code is pretty small and pretty fast.
No use for 126 subclasses... only 3 codelines for alpha characters.
Why not making the filter locale aware ?
A locale-aware Zend_Filter-class seems to be pretty fat-weighted.
Remember the switch ... case.
I dont think that 3 codelines are "pretty fat-weighted"
Exactly therefor we created the complete Zend_Locale classes bunch.
Filter without locale only recognising a-z
getAlpha($content);
Filtering with locale recognising locale letters for example german
including ä, ö, ü, ß
getAlpha($content, $locale);
This would be possible.
We have Zend_Locale_Filter (or another name).
Zend_Filter::getAlpha($string, "de") now calls internally
Zend_Locale_Filter::singleton("de")->getAlpha($string) and returns the
value (we would need some hybrid of singleton and factory there, as
Zend_Locale_Filter would create, store and deliver the
Zend_Locale_Filter_<locale>-object). And no, I did not thought further
on saying "let's call it Zend_Locale_Filter" and I'm completely
unideological how to name it.
Sorry to say that, but this is in my eyes not a useable or functional class
design.
WHEN you know you would have 126 classes which all use the same code you
MUST
look how to compress them... having 126 times the same code only with 1
different line or so
is nonsense...
I would say first to look info the already avaiable locale aware classes to
know HOW to integrate
locale awareness. Take a look at Zend_Date's or Zend_Measure's function.
There is NO
switch necesary and no singleton or factory is used. Also no 126 subclasses
are needed but each
function asks for other values from Zend_Locale... but the implementation is
small and fast.
Greetings
Thomas
(I18N Head and Author)