Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CChoiceFormat
  • CDateFormatter
  • CDbMessageSource
  • CGettextMessageSource
  • CLocale
  • CMessageSource
  • CMissingTranslationEvent
  • CNumberFormatter
  • CPhpMessageSource
  • Overview
  • Package
  • Class
  • Tree

Class CChoiceFormat

CChoiceFormat is a helper that chooses an appropriate message based on the specified number value. The candidate messages are given as a string in the following format:

'expr1#message1|expr2#message2|expr3#message3'

where each expression should be a valid PHP expression with <span class="php-quote">'n'</span> as the only variable. For example, <span class="php-quote">'n==1'</span> and <span class="php-quote">'n%10==2 && n>10'</span> are both valid expressions. The variable <span class="php-quote">'n'</span> will take the given number value, and if an expression evaluates true, the corresponding message will be returned.

For example, given the candidate messages <span class="php-quote">'n==1#one|n==2#two|n>2#others'</span> and the number value 2, the resulting message will be <span class="php-quote">'two'</span>.

For expressions like <span class="php-quote">'n==1'</span>, we can also use a shortcut <span class="php-quote">'1'</span>. So the above example candidate messages can be simplified as <span class="php-quote">'1#one|2#two|n>2#others'</span>.

In case the given number doesn't select any message, the last candidate message will be returned.

The PHP expressions will be evaluated using CChoiceFormat::evaluate().

Package: system\i18n
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Located at x2engine/framework/i18n/CChoiceFormat.php
Methods summary
public static string
# format( string $messages, mixed $number )

Formats a message according to the specified number value.

Formats a message according to the specified number value.

Parameters

$messages
string
$messages the candidate messages in the format of 'expr1#message1|expr2#message2|expr3#message3'. See CChoiceFormat for more details.
$number
mixed
$number the number value

Returns

string
the selected message
protected static boolean
# evaluate( string $expression, mixed $n )

Evaluates a PHP expression with the given number value.

Evaluates a PHP expression with the given number value.

Parameters

$expression
string
$expression the PHP expression
$n
mixed
$n the number value

Returns

boolean
the expression result
API documentation generated by ApiGen 2.8.0