ENHANCEMENT: added translatable support to mathspamprotection. PATCH via noini (#4755) (from r95194)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@95657 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2009-12-16 06:07:48 +00:00
parent 05147ffd37
commit 8f270a7a7c

View File

@ -25,7 +25,12 @@ class MathSpamProtection {
$v1 = Session::get("mathQuestionV1"); $v1 = Session::get("mathQuestionV1");
$v2 = Session::get("mathQuestionV2"); $v2 = Session::get("mathQuestionV2");
} }
return "What is ".MathSpamProtection::digitToWord($v1)." plus ".MathSpamProtection::digitToWord($v2)."?";
return sprintf(
_t('MathSpamProtection.WHATIS',"What is %s plus %s?"),
MathSpamProtection::digitToWord($v1),
MathSpamProtection::digitToWord($v2)
);
} }
/** /**
@ -49,12 +54,28 @@ class MathSpamProtection {
* Helper method for converting digits to their equivelant english words * Helper method for converting digits to their equivelant english words
*/ */
static function digitToWord($num){ static function digitToWord($num){
$numbers = array("zero","one","two","three","four","five","six","seven","eight","nine", $numbers = array(_t('MathSpamProtection.ZERO', 'zero'),
"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen"); _t('MathSpamProtection.ONE', 'one'),
if($num < 0){ _t('MathSpamProtection.TWO', 'two'),
return "minus ".($numbers[-1*$num]); _t('MathSpamProtection.THREE', 'three'),
} _t('MathSpamProtection.FOUR', 'four'),
//TODO: add checking or return null for bad value?? _t('MathSpamProtection.FIVE', 'five'),
_t('MathSpamProtection.SIX', 'six'),
_t('MathSpamProtection.SEVEN', 'seven'),
_t('MathSpamProtection.EIGHT', 'eight'),
_t('MathSpamProtection.NINE', 'nine'),
_t('MathSpamProtection.TEN', 'ten'),
_t('MathSpamProtection.ELEVEN', 'eleven'),
_t('MathSpamProtection.TWELVE', 'twelve'),
_t('MathSpamProtection.THIRTEEN', 'thirteen'),
_t('MathSpamProtection.FOURTEEN', 'fourteen'),
_t('MathSpamProtection.FIFTEEN', 'fifteen'),
_t('MathSpamProtection.SIXTEEN', 'sixteen'),
_t('MathSpamProtection.SEVENTEEN', 'seventeen'),
_t('MathSpamProtection.EIGHTEEN', 'eighteen'));
if($num < 0) return "minus ".($numbers[-1*$num]);
return $numbers[$num]; return $numbers[$num];
} }
@ -68,4 +89,3 @@ class MathSpamProtection {
} }
} }
?>