Exemplo n.º 1
0
 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');
 }
Exemplo n.º 2
0
 public function testPrefixTranslation()
 {
     $this->assertEqual(i18n::translate('app', null, null, 'url'), 'application');
     $this->assertEqual(i18n::translate('application', null, true, 'url'), 'app');
 }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
0
/**
 * 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);
}