From 4835704a04cf5aa5ec71a8aef902d54b9c6cae82 Mon Sep 17 00:00:00 2001
From: wei <>
Date: Fri, 6 Jan 2006 04:42:44 +0000
Subject: Adding I18N support.
---
framework/I18N/TChoiceFormat.php | 94 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
create mode 100644 framework/I18N/TChoiceFormat.php
(limited to 'framework/I18N/TChoiceFormat.php')
diff --git a/framework/I18N/TChoiceFormat.php b/framework/I18N/TChoiceFormat.php
new file mode 100644
index 00000000..24080700
--- /dev/null
+++ b/framework/I18N/TChoiceFormat.php
@@ -0,0 +1,94 @@
+
+ * @version $Revision: 1.2 $ $Date: 2005/04/24 00:21:13 $
+ * @package System.I18N
+ */
+
+ /**
+ * Get the ChoiceFormat class.
+ */
+Prado::using('System.I18N.core.ChoiceFormat');
+
+/**
+ * TChoiceFormat class.
+ *
+ * This component performs message/string choice translation. The translation
+ * source is set in the TGlobalization handler. The following example
+ * demonstrated a simple 2 choice message translation.
+ *
+ * [1] One Apple. |[2] Two Apples
+ *
+ *
+ * The Choice has Value "1" (one), thus the translated string
+ * is "One Apple". If the Value was "2", then it will show
+ * "Two Apples".
+ *
+ * The message/string choices are separated by the pipe "|" followed
+ * by a set notation of the form
+ * # [1,2] -- accepts values between 1 and 2, inclusive.
+ * # (1,2) -- accepts values between 1 and 2, excluding 1 and 2.
+ * # {1,2,3,4} -- only values defined in the set are accepted.
+ * # [-Inf,0) -- accepts value greater or equal to negative infinity
+ * and strictly less than 0
+ * Any non-empty combinations of the delimiters of square and round brackets
+ * are acceptable.
+ *
+ * The string choosen for display depends on the Value property.
+ * The Value is evaluated for each set until the Value is found
+ * to belong to a particular set.
+ *
+ * Properties
+ * - Value, float,
+ *
Gets or sets the Value that determines which string choice to display.
+ *
+ * @author Xiang Wei Zhuo
+ * @version v1.0, last update on Fri Dec 24 21:38:49 EST 2004
+ * @package System.I18N
+ */
+class TChoiceFormat extends TTranslate
+{
+ /**
+ * @return float the numerical value.
+ */
+ function getValue()
+ {
+ return $this->getViewState('Value','');
+ }
+
+ /**
+ * Sets the numerical choice value
+ * @param float the choice value
+ */
+ function setValue($value)
+ {
+ $this->setViewState('Value',$value,'');
+ }
+
+ /**
+ * Display the choosen translated string.
+ * Overrides the parent method, also calls parent's renderBody to
+ * translate.
+ */
+ protected function translateText($text, $subs)
+ {
+ $text = parent::translateText($text, $subs);
+ $choice = new ChoiceFormat();
+ $value = $this->getValue();
+ $string = $choice->format($text, $value);
+ if($string)
+ return strtr($string, array('{Value}'=> $value));
+ }
+}
+?>
\ No newline at end of file
--
cgit v1.2.3