Example #1
0
/**
 * Translate a message alias (plural).
 *
 * @param   integer $count      number for detecting format
 * @param   string  $single     message alias (single)
 * @param   string  $plural     message alias (plural)
 * @param   array   $tokens     parameters for translation
 * @param   array   $options    options
 * @return  string  message to display
 */
function t_plural($count, $single, $plural, $tokens = array(), $options = array())
{
    if (method_exists('SC_Helper_Locale_Ex', 'get_locale_plural')) {
        list($translated_single, $translated_plural) = SC_Helper_Locale_Ex::get_locale_plural($single, $plural, $options);
    } else {
        $translated_single = $single;
        $translated_plural = $plural;
        $options['lang_code'] = 'en-US';
    }
    if ($count == 1) {
        $return = $translated_single;
    } else {
        // Determine appropriate plural form.
        $index = get_plural_index($count, $options['lang_code']);
        if ($index < 0) {
            $return = $translated_plural;
        } else {
            switch ($index) {
                case "0":
                    $return = $translated_single;
                case "1":
                default:
                    $return = $translated_plural;
            }
        }
    }
    // Add a counter to translation parameters.
    $tokens['T_COUNT'] = number_format($count);
    return strtr($return, $tokens);
}
 /**
  * Return a string which corresponding with message alias.
  *
  * @param   string  $single     message alias (single)
  * @param   string  $plural     message alias (plural)
  * @param   array   $options    options
  * @return  array
  */
 public static function get_locale_plural($single, $plural, &$options)
 {
     // Plural strings are coupled with a null character.
     $key = $single . chr(0) . $plural;
     // Get a string of specified language which corresponds to the message alias.
     $translated = SC_Helper_Locale_Ex::get_locale($key, $options);
     // Divide with a null character.
     return explode(chr(0), $translated);
 }