Class \Prado\I18N\TChoiceFormat
This component performs message/string choice translation. The translation source is set in the TGlobalization module. The following example demonstrates a simple 2 choice message translation.
<com:TChoiceFormat Value="1">[1] One Apple. |[2] Two Apples</com:TChoiceFormat>
The Choice has Value "1" (one), thus the translated string is "One Apple". If the Value is "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. Since version 3.1.2 the following set notation is also possible.
{n: n % 10 > 1 && n % 10 < 5} -- matches numbers like 2, 3, 4, 22, 23, 24
Where set is defined by the expression after n:. In particular, the expression accepts the following mathematical/logical operators to form a set of logical conditions on the value given by n:
< -- less than.
<= -- less than equals.
> -- greater than.
>= -- greater than equals.
== -- of equal value.
% -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1.
- -- minus, negative.
+ -- addition.
& -- conditional AND.
&& -- condition AND with short circuit.
| -- conditional OR.
|| -- conditional OR with short circuit.
! -- negation.
Additional round brackets can also be used to perform grouping.
Class hierarchy
- \Prado\I18N\TChoiceFormat
- \Prado\I18N\TTranslate
- \Prado\I18N\TI18NControl
- \Prado\Web\UI\TControl implements IRenderable, IBindable
- \Prado\TApplicationComponent
- \Prado\TComponent
public
|
|
public
|
|
protected
|
translateText(mixed $text, mixed $subs) : string
Display the choosen translated string.
Overrides the parent method, also calls parent's renderBody to translate. |