本文整理汇总了PHP中i18n::translate方法的典型用法代码示例。如果您正苦于以下问题:PHP i18n::translate方法的具体用法?PHP i18n::translate怎么用?PHP i18n::translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类i18n
的用法示例。
在下文中一共展示了i18n::translate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTranslationCaching
function testTranslationCaching()
{
Configure::write('Config.language', 'cache_test_po');
$i18n =& i18n::getInstance();
// reset cache & i18n
$i18n->__destruct();
Cache::clear(false, '_cake_core_');
$lang = $i18n->l10n->locale;
Cache::config('_cake_core_', Cache::config('default'));
// make some calls to translate using different domains
$this->assertEqual(i18n::translate('dom1.foo', false, 'dom1'), 'Dom 1 Foo');
$this->assertEqual(i18n::translate('dom1.bar', false, 'dom1'), 'Dom 1 Bar');
$this->assertEqual($i18n->__cache[0]['key'], 'dom1_' . $lang);
$this->assertEqual($i18n->__cache[0]['domain'], 'dom1');
$this->assertEqual($i18n->__domains['LC_MESSAGES']['cache_test_po']['dom1']['dom1.foo'], 'Dom 1 Foo');
// destruct -> writes to cache
$i18n->__destruct();
// now only dom1 should be in cache
$cachedDom1 = Cache::read('dom1_' . $lang, '_cake_core_');
$this->assertEqual($cachedDom1['dom1.foo'], 'Dom 1 Foo');
$this->assertEqual($cachedDom1['dom1.bar'], 'Dom 1 Bar');
// dom2 not in cache
$this->assertFalse(Cache::read('dom2_' . $lang, '_cake_core_'));
// translate a item of dom2 (adds dom2 to cache)
$this->assertEqual(i18n::translate('dom2.foo', false, 'dom2'), 'Dom 2 Foo');
// modify cache entry to verify that dom1 entry is now read from cache
$cachedDom1['dom1.foo'] = 'FOO';
Cache::write('dom1_' . $lang, $cachedDom1, '_cake_core_');
$this->assertEqual(i18n::translate('dom1.foo', false, 'dom1'), 'FOO');
// verify that only dom2 will be cached now
$this->assertEqual($i18n->__cache[0]['key'], 'dom2_' . $lang);
$this->assertEqual(count($i18n->__cache), 1);
// write to cache
$i18n->__destruct();
// verify caching through manual read from cache
$cachedDom2 = Cache::read('dom2_' . $lang, '_cake_core_');
$this->assertEqual($cachedDom2['dom2.foo'], 'Dom 2 Foo');
$this->assertEqual($cachedDom2['dom2.bar'], 'Dom 2 Bar');
}
示例2: testPrefixTranslation
public function testPrefixTranslation()
{
$this->assertEqual(i18n::translate('app', null, null, 'url'), 'application');
$this->assertEqual(i18n::translate('application', null, true, 'url'), 'app');
}
示例3: _getDate
private function _getDate($format = "numeric")
{
if ($format == "numeric") {
$this->_date = str_replace("%/%", $this->_dateSeparator, $this->_date);
$this->_date = str_replace("dd", $this->_day, $this->_date);
$this->_date = str_replace("mm", $this->_month, $this->_date);
$this->_date = str_replace("yyyy", $this->_year, $this->_date);
return $this->_date;
}
if ($format == "text") {
$this->_dateFormat = $this->_config->getParam("namedDateFormat");
$dayName = i18n::translate(date("l"));
$monthName = i18n::translate(date("F"));
$this->_date = $this->_dateFormat;
$this->_date = str_replace("dd", date("d"), $this->_date);
$this->_date = str_replace("Dname", $dayName, $this->_date);
$this->_date = str_replace("Mname", $monthName, $this->_date);
$this->_date = str_replace("yyyy", date("Y"), $this->_date);
return $this->_date;
}
}
示例4: __
/**
* A wrapper for i18n::translate();
*
* You can use it as if it has 2 arguments and then pass the rest of the arguments as arguments to go to sprintf.
*/
function __($section, $key = null, $locale = 'DEFAULT')
{
if (func_num_args() > 3 || func_num_args() > 2 && $locale !== 'DEFAULT') {
$args = func_get_args();
return call_user_func_array('i18n::translate', $args);
}
return i18n::translate($section, $key, $locale);
}