當前位置: 首頁>>代碼示例>>PHP>>正文


PHP i18n::get_translator方法代碼示例

本文整理匯總了PHP中i18n::get_translator方法的典型用法代碼示例。如果您正苦於以下問題:PHP i18n::get_translator方法的具體用法?PHP i18n::get_translator怎麽用?PHP i18n::get_translator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在i18n的用法示例。


在下文中一共展示了i18n::get_translator方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

	function setUp() {
		parent::setUp();
		
		$this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
		$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
		FileSystem::makeFolder($this->alternateBaseSavePath);
		Director::setBaseFolder($this->alternateBasePath);

		// Push a template loader running from the fake webroot onto the stack.
		$templateManifest = new SS_TemplateManifest($this->alternateBasePath, false, true);
		$templateManifest->regenerate(false);
		SS_TemplateLoader::instance()->pushManifest($templateManifest);
		$this->_oldTheme = SSViewer::current_theme();
		SSViewer::set_theme('testtheme1');
		
		$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
		SS_ClassLoader::instance()->pushManifest($classManifest);

		$this->originalLocale = i18n::get_locale();
		
		// Override default adapter to avoid cached translations between tests.
		// Emulates behaviour in i18n::get_translators()
		$this->origAdapter = i18n::get_translator('core');
		$adapter = new Zend_Translate(array(
			'adapter' => 'i18nSSLegacyAdapter',
			'locale' => i18n::default_locale(),
			'disableNotices' => true,
		));
		i18n::register_translator($adapter, 'core');
		$adapter->removeCache();
		i18n::include_by_locale('en');
	}
開發者ID:redema,項目名稱:sapphire,代碼行數:32,代碼來源:i18nSSLegacyAdapterTest.php

示例2: testUpdateFieldLabels

 public function testUpdateFieldLabels()
 {
     // Add custom translation for testing
     i18n::get_translator('core')->getAdapter()->addTranslation(array('SiteTree.METATITLE' => 'TRANS-EN Meta Title'), 'en');
     $siteTree = new SiteTree();
     $labels = $siteTree->fieldLabels();
     $this->assertArrayHasKey('MetaTitle', $labels);
     $this->assertEquals('TRANS-EN Meta Title', $labels['MetaTitle']);
     // Set different locale, clear field label cache
     i18n::set_locale('de_DE');
     DataObject::reset();
     // Add custom translation for testing
     i18n::get_translator('core')->getAdapter()->addTranslation(array('SiteTree.METATITLE' => 'TRANS-DE Meta Title'), 'de_DE');
     $labels = $siteTree->fieldLabels();
     $this->assertEquals('TRANS-DE Meta Title', $labels['MetaTitle']);
 }
開發者ID:helpfulrobot,項目名稱:kinglozzer-metatitle,代碼行數:16,代碼來源:MetaTitleExtensionTest.php

示例3: setUp

 public function setUp()
 {
     parent::setUp();
     $this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
     $this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
     Filesystem::makeFolder($this->alternateBaseSavePath);
     Config::inst()->update('Director', 'alternate_base_folder', $this->alternateBasePath);
     // Replace old template loader with new one with alternate base path
     $this->_oldLoader = ThemeResourceLoader::instance();
     ThemeResourceLoader::set_instance(new ThemeResourceLoader($this->alternateBasePath));
     $this->_oldTheme = Config::inst()->get('SSViewer', 'theme');
     Config::inst()->update('SSViewer', 'theme', 'testtheme1');
     $classManifest = new SS_ClassManifest($this->alternateBasePath, false, true, false);
     SS_ClassLoader::instance()->pushManifest($classManifest);
     $this->originalLocale = i18n::get_locale();
     // Override default adapter to avoid cached translations between tests.
     // Emulates behaviour in i18n::get_translators()
     $this->origAdapter = i18n::get_translator('core');
     $adapter = new Zend_Translate(array('adapter' => 'i18nSSLegacyAdapter', 'locale' => i18n::default_locale(), 'disableNotices' => true));
     i18n::register_translator($adapter, 'core');
     $adapter->removeCache();
     i18n::include_by_locale('en');
 }
開發者ID:jacobbuck,項目名稱:silverstripe-framework,代碼行數:23,代碼來源:i18nSSLegacyAdapterTest.php

示例4: testIncludeByLocaleWithoutFallbackLanguage

 public function testIncludeByLocaleWithoutFallbackLanguage()
 {
     $classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
     SS_ClassLoader::instance()->pushManifest($classManifest);
     $adapter = i18n::get_translator('core')->getAdapter();
     $this->assertTrue($adapter->isAvailable('en'));
     $this->assertFalse($adapter->isAvailable('mi'));
     // not defined at all
     $this->assertFalse($adapter->isAvailable('mi_NZ'));
     // defined, but not loaded yet
     $this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'mi'), 'Existing unloaded entity not available before call');
     $this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'mi_NZ'), 'Non-existing unloaded entity not available before call');
     i18n::include_by_locale('mi_NZ');
     $this->assertFalse($adapter->isAvailable('mi'));
     $this->assertTrue($adapter->isAvailable('mi_NZ'));
     $this->assertTrue($adapter->isTranslated('i18nTestModule.ENTITY', null, 'mi_NZ'), 'Includes module files');
     SS_ClassLoader::instance()->popManifest();
 }
開發者ID:jakedaleweb,項目名稱:AtomCodeChallenge,代碼行數:18,代碼來源:i18nTest.php

示例5: testIncludeByLocale

	function testIncludeByLocale() {
		// Looping through modules, so we can test the translation autoloading
		// Load non-exclusive to retain core class autoloading
		$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
		SS_ClassLoader::instance()->pushManifest($classManifest);
		
		$adapter = i18n::get_translator('core')->getAdapter();
		$this->assertTrue($adapter->isAvailable('en'));
		$this->assertFalse($adapter->isAvailable('de'));
		$this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'de'), 
			'Existing unloaded entity not available before call'
		);
		$this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'af'), 
			'Non-existing unloaded entity not available before call'
		);

		i18n::include_by_locale('de');
		
		$this->assertTrue($adapter->isAvailable('en'));
		$this->assertTrue($adapter->isAvailable('de'));
		$this->assertTrue($adapter->isTranslated('i18nTestModule.ENTITY', null, 'de'), 'Includes module files');
		$this->assertTrue($adapter->isTranslated('i18nTestTheme1.LAYOUTTEMPLATE', null, 'de'), 'Includes theme files');
		$this->assertTrue($adapter->isTranslated('i18nTestModule.OTHERENTITY', null, 'de'), 'Includes submodule files');
		
		SS_ClassLoader::instance()->popManifest();
	}
開發者ID:redema,項目名稱:sapphire,代碼行數:26,代碼來源:i18nTest.php


注:本文中的i18n::get_translator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。