本文整理汇总了PHP中Cake\I18n\I18n::translate方法的典型用法代码示例。如果您正苦于以下问题:PHP I18n::translate方法的具体用法?PHP I18n::translate怎么用?PHP I18n::translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\I18n\I18n
的用法示例。
在下文中一共展示了I18n::translate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTranslateEmptyDomain
/**
* Test that the '' domain causes exceptions.
*
* @expectedException \Cake\Error\Exception
* @return void
*/
public function testTranslateEmptyDomain()
{
I18n::translate('Plural Rule 1', null, '');
}
示例2: putenv
//@codingStandardsIgnoreStart
@mkdir(LOGS);
@mkdir(SESSIONS);
@mkdir(CACHE);
@mkdir(CACHE . 'views');
@mkdir(CACHE . 'models');
//@codingStandardsIgnoreEnd
require CAKE . 'Core/ClassLoader.php';
$loader = new Cake\Core\ClassLoader();
$loader->register();
$loader->addNamespace('TestApp', APP);
$loader->addNamespace('TestPlugin', TEST_APP . 'Plugin/TestPlugin');
$loader->addNamespace('TestPluginTwo', TEST_APP . 'Plugin/TestPluginTwo');
$loader->addNamespace('PluginJs', TEST_APP . 'Plugin/PluginJs');
require CAKE . 'bootstrap.php';
date_default_timezone_set('UTC');
mb_internal_encoding('UTF-8');
Configure::write('debug', true);
Configure::write('App', ['namespace' => 'App', 'encoding' => 'UTF-8', 'base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT, 'fullBaseUrl' => 'http://localhost', 'imageBaseUrl' => 'img/', 'jsBaseUrl' => 'js/', 'cssBaseUrl' => 'css/', 'paths' => ['plugins' => [TEST_APP . 'Plugin' . DS], 'templates' => [APP . 'Template' . DS]]]);
Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cake_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cake_model_', 'serialize' => true]]);
// Ensure default test connection is defined
if (!getenv('db_class')) {
putenv('db_class=Cake\\Database\\Driver\\Sqlite');
putenv('db_dsn=sqlite::memory:');
}
ConnectionManager::config('test', ['className' => 'Cake\\Database\\Connection', 'driver' => getenv('db_class'), 'dsn' => getenv('db_dsn'), 'database' => getenv('db_database'), 'login' => getenv('db_login'), 'password' => getenv('db_password'), 'timezone' => 'UTC']);
Configure::write('Session', ['defaults' => 'php']);
Log::config(['debug' => ['engine' => 'Cake\\Log\\Engine\\FileLog', 'levels' => ['notice', 'info', 'debug'], 'file' => 'debug'], 'error' => ['engine' => 'Cake\\Log\\Engine\\FileLog', 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], 'file' => 'error']]);
// Initialize the empty language.
I18n::translate('empty');
Carbon\Carbon::setTestNow(Carbon\Carbon::now());
示例3: elseif
/**
* 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 $msg String to translate
* @param int $category Category
* @param mixed $args Array with arguments or multiple arguments in function
* @return string translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
*/
function __c($msg, $category, $args = null)
{
if (!$msg) {
return;
}
$translated = I18n::translate($msg, null, null, $category);
if ($args === null) {
return $translated;
} elseif (!is_array($args)) {
$args = array_slice(func_get_args(), 2);
}
$translated = preg_replace('/(?<!%)%(?![%\'\\-+bcdeEfFgGosuxX\\d\\.])/', '%%', $translated);
return vsprintf($translated, $args);
}