I18n::insertArgs PHP Method

insertArgs() public static method

Puts the parameters in raw translated strings
public static insertArgs ( string $translated, array $args ) : string
$translated string The raw translated string
$args array The arguments to put in the translation
return string Translated string with arguments
    public static function insertArgs($translated, array $args)
    {
        $len = count($args);
        if ($len === 0 || $len === 1 && $args[0] === null) {
            return $translated;
        }
        if (is_array($args[0])) {
            $args = $args[0];
        }
        $translated = preg_replace('/(?<!%)%(?![%\'\\-+bcdeEfFgGosuxX\\d\\.])/', '%%', $translated);
        return vsprintf($translated, $args);
    }

Usage Example

コード例 #1
0
ファイル: basics.php プロジェクト: mrbadao/api-official
 /**
  * The category argument allows a specific category of the locale settings to be used for fetching a message.
  * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
  *
  * Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
  *
  * - LC_ALL       I18n::LC_ALL
  * - LC_COLLATE   I18n::LC_COLLATE
  * - LC_CTYPE     I18n::LC_CTYPE
  * - LC_MONETARY  I18n::LC_MONETARY
  * - LC_NUMERIC   I18n::LC_NUMERIC
  * - LC_TIME      I18n::LC_TIME
  * - LC_MESSAGES  I18n::LC_MESSAGES
  *
  * @param string $context  Context of the text
  * @param string $msg      String to translate
  * @param int    $category Category
  * @param mixed  $args     Array with arguments or multiple arguments in function, otherwise null.
  *
  * @return string translated string
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
  */
 function __xc($context, $msg, $category, $args = NULL)
 {
     if (!$msg) {
         return NULL;
     }
     App::uses('I18n', 'I18n');
     $translated = I18n::translate($msg, NULL, NULL, $category, NULL, NULL, $context);
     $arguments = func_get_args();
     return I18n::insertArgs($translated, array_slice($arguments, 3));
 }