summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwei <>2008-02-15 01:09:36 +0000
committerwei <>2008-02-15 01:09:36 +0000
commitd88930d23f712f9b9da279f32ee689e6d719f13b (patch)
tree49c7c162740a166aada7ea2ea76c78cef96b4d49
parent5e8932fb41534dc0d06e76dae7b74cf47071f6e0 (diff)
update docs on TChoiceFormat
-rw-r--r--demos/quickstart/protected/pages/Advanced/I18N.page40
-rw-r--r--framework/I18N/TChoiceFormat.php24
-rw-r--r--framework/I18N/core/ChoiceFormat.php33
3 files changed, 90 insertions, 7 deletions
diff --git a/demos/quickstart/protected/pages/Advanced/I18N.page b/demos/quickstart/protected/pages/Advanced/I18N.page
index 32dd8ac6..73ff1d04 100644
--- a/demos/quickstart/protected/pages/Advanced/I18N.page
+++ b/demos/quickstart/protected/pages/Advanced/I18N.page
@@ -356,5 +356,43 @@ is "One Apple". If the <tt>Value</tt> was "2", then it will show "Two Apples".</
<p id="790665" class="block-content">Any non-empty combinations of the delimiters of square and round brackets are acceptable.
The string chosen for display depends on the <tt>Value</tt> property. The <tt>Value</tt> is evaluated for each set until the <tt>Value</tt> is found to belong to a particular set.</p>
+<com:SinceVersion Version="3.1.1" />
+<pi class="block-content"> Since version 3.1.1 the following set notation is also possible.</p>
+<ul class="block-content">
+ <li> <tt>{n: n % 10 > 1 && n % 10 < 5}</tt> -- matches numbers like 2, 3, 4, 22, 23, 24</li>
+</ul>
+
+<p class="block-content">Where set is defined by the expression after <tt>n:</tt>. In particular, the expression
+accepts the following mathematical/logical operators to form a set of logical conditions
+on the value given by <tt>n</tt>:</p>
+<ul class="block-content">
+ <li><tt>&lt;</tt> -- less than.</li>
+ <li><tt>&lt;=</tt> -- less than equals.</li>
+ <li><tt>&gt;</tt> -- greater than.</li>
+ <li><tt>&gt=</tt> -- greater than equals.</li>
+ <li><tt>==</tt> -- of equal value.</li>
+ <li><tt>%</tt> -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1.</li>
+ <li><tt>-</tt> -- minus, negative.</li>
+ <li><tt>+</tt> -- addition.</li>
+ <li><tt>&amp;</tt> -- conditional AND.</li>
+ <li><tt>&amp;&amp;</tt> -- condition AND with short circuit.</li>
+ <li><tt>|</tt> -- conditional OR.</li>
+ <li><tt>||</tt> -- conditional OR with short circuit. </li>
+ <li><tt>!</tt> -- negation.</li>
+</ul>
+<p class="block-content">Additional round brackets can also be used to perform grouping. The following example
+represents ordinal values in English such as: "0th", "1st", "2nd", "3rd", "4th", "11th", "21st", "22nd", etc.</p>
+
+<com:TTextHighlighter Language="prado" CssClass="source block-content" >
+&lt;com:TChoiceFormat Value="21"&gt;
+ {n: (n > 0) && (n < 10 || n > 20) && n % 10 == 1} {Value}st
+|{n: (n > 0) && (n < 10 || n > 20) && n % 10 == 2} {Value}nd
+|{n: (n > 0) && (n < 10 || n > 20) && n % 10 == 3} {Value}rd
+|{n: n > -1 } {Value}th
+|(-Inf, 0) {Value}
+&lt;/com:TChoiceFormat&gt;
+</com:TTextHighlighter>
+
+
-<div class="last-modified">$Id$</div></com:TContent> \ No newline at end of file
+<div class="last-modified">$Id$</div></com:TContent>
diff --git a/framework/I18N/TChoiceFormat.php b/framework/I18N/TChoiceFormat.php
index bf646c31..eeca3541 100644
--- a/framework/I18N/TChoiceFormat.php
+++ b/framework/I18N/TChoiceFormat.php
@@ -47,6 +47,28 @@ Prado::using('System.I18N.TTranslate');
* Properties
* - <b>Value</b>, float,
* <br>Gets or sets the Value that determines which string choice to display.
+ * Since version 3.1.2 the following set notation is also possible.
+ *
+ * # <tt>{n: n % 10 > 1 && n % 10 < 5}</tt> -- matches numbers like 2, 3, 4, 22, 23, 24
+ *
+ * Where set is defined by the expression after <tt>n:</tt>. In particular, the expression
+ * accepts the following mathematical/logical operators to form a set of logical conditions
+ * on the value given by <tt>n</tt>:
+ * # <tt>&lt;</tt> -- less than.
+ * # <tt>&lt;=</tt> -- less than equals.
+ * # <tt>&gt;</tt> -- greater than.
+ * # <tt>&gt=</tt> -- greater than equals.
+ * # <tt>==</tt> -- of equal value.
+ * # <tt>%</tt> -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1.
+ * # <tt>-</tt> -- minus, negative.
+ * # <tt>+</tt> -- addition.
+ * # <tt>&amp;</tt> -- conditional AND.
+ * # <tt>&amp;&amp;</tt> -- condition AND with short circuit.
+ * # <tt>|</tt> -- conditional OR.
+ * # <tt>||</tt> -- conditional OR with short circuit.
+ * # <tt>!</tt> -- negation.
+ *
+ * Additional round brackets can also be used to perform grouping.
*
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version v1.0, last update on Fri Dec 24 21:38:49 EST 2004
@@ -86,4 +108,4 @@ class TChoiceFormat extends TTranslate
return strtr($string, array('{Value}'=> $value));
}
}
-?> \ No newline at end of file
+?>
diff --git a/framework/I18N/core/ChoiceFormat.php b/framework/I18N/core/ChoiceFormat.php
index d36ab57b..b8eb69f0 100644
--- a/framework/I18N/core/ChoiceFormat.php
+++ b/framework/I18N/core/ChoiceFormat.php
@@ -41,14 +41,37 @@
*
* The message/string choices are separated by the pipe "|" followed
* by a set notation of the form
- * # <t>[1,2]</t> -- accepts values between 1 and 2, inclusive.
- * # <t>(1,2)</t> -- accepts values between 1 and 2, excluding 1 and 2.
- * # <t>{1,2,3,4}</t> -- only values defined in the set are accepted.
- * # <t>[-Inf,0)</t> -- accepts value greater or equal to negative infinity
+ * # <tt>[1,2]</tt> -- accepts values between 1 and 2, inclusive.
+ * # <tt>(1,2)</tt> -- accepts values between 1 and 2, excluding 1 and 2.
+ * # <tt>{1,2,3,4}</tt> -- only values defined in the set are accepted.
+ * # <tt>[-Inf,0)</tt> -- 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.
*
+ * Since version 3.1.2 the following set notation is also possible.
+ *
+ * # <tt>{n: n % 10 > 1 && n % 10 < 5}</tt> -- matches numbers like 2, 3, 4, 22, 23, 24
+ *
+ * Where set is defined by the expression after <tt>n:</tt>. In particular, the expression
+ * accepts the following mathematical/logical operators to form a set of logical conditions
+ * on the value given by <tt>n</tt>:
+ * # <tt>&lt;</tt> -- less than.
+ * # <tt>&lt;=</tt> -- less than equals.
+ * # <tt>&gt;</tt> -- greater than.
+ * # <tt>&gt=</tt> -- greater than equals.
+ * # <tt>==</tt> -- of equal value.
+ * # <tt>%</tt> -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1.
+ * # <tt>-</tt> -- minus, negative.
+ * # <tt>+</tt> -- addition.
+ * # <tt>&amp;</tt> -- conditional AND.
+ * # <tt>&amp;&amp;</tt> -- condition AND with short circuit.
+ * # <tt>|</tt> -- conditional OR.
+ * # <tt>||</tt> -- conditional OR with short circuit.
+ * # <tt>!</tt> -- negation.
+ *
+ * Additional round brackets can also be used to perform grouping.
+ *
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version v1.0, last update on Fri Dec 24 20:46:16 EST 2004
* @package System.I18N.core
@@ -200,4 +223,4 @@ class ChoiceFormat
}
}
-?> \ No newline at end of file
+?>