当前位置: 首页>>代码示例>>PHP>>正文


PHP i18n::set_locale方法代码示例

本文整理汇总了PHP中i18n::set_locale方法的典型用法代码示例。如果您正苦于以下问题:PHP i18n::set_locale方法的具体用法?PHP i18n::set_locale怎么用?PHP i18n::set_locale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在i18n的用法示例。


在下文中一共展示了i18n::set_locale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testFieldInDenmark

 function testFieldInDenmark()
 {
     $locale = i18n::get_locale();
     i18n::set_locale('da_DK');
     // Should start at 0
     $field = new PercentageField('Test', 'TestField');
     $this->assertEquals(0, $field->dataValue());
     $this->assertEquals('0%', $field->Value());
     // Entering 50 should yield 0.5
     $field->setValue('50');
     $this->assertEquals(0.5, $field->dataValue());
     $this->assertEquals('50%', $field->Value());
     // Entering 50% should yield 0.5
     $field->setValue('50%');
     $this->assertEquals(0.5, $field->dataValue());
     $this->assertEquals('50%', $field->Value());
     // Entering -50% should yield -0.5
     $field->setValue('-50%');
     $this->assertEquals(-0.5, $field->dataValue());
     $this->assertEquals('-50%', $field->Value());
     // Entering 0.5 should yield 0.5
     $field->setValue('0,5');
     $this->assertEquals(0.5, $field->dataValue());
     $this->assertEquals('50%', $field->Value());
     // Entering 0.5% should yield 0.005
     $field->setValue('0,5%');
     $this->assertEquals(0.005, $field->dataValue());
     $this->assertEquals('0,5%', $field->Value());
     i18n::set_locale($locale);
 }
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-shop-extendedpricing,代码行数:30,代码来源:PercentageFieldTest.php

示例2: testLinks

 public function testLinks()
 {
     // Run link checker
     $task = CheckExternalLinksTask::create();
     $task->setSilent(true);
     // Be quiet during the test!
     $task->runLinksCheck();
     // Get all links checked
     $status = BrokenExternalPageTrackStatus::get_latest();
     $this->assertEquals('Completed', $status->Status);
     $this->assertEquals(5, $status->TotalPages);
     $this->assertEquals(5, $status->CompletedPages);
     // Check all pages have had the correct HTML adjusted
     for ($i = 1; $i <= 5; $i++) {
         $page = $this->objFromFixture('ExternalLinksTest_Page', 'page' . $i);
         $this->assertNotEmpty($page->Content);
         $this->assertEquals($page->ExpectedContent, $page->Content, "Assert that the content of page{$i} has been updated");
     }
     // Check that the correct report of broken links is generated
     $links = $status->BrokenLinks()->sort('Link');
     $this->assertEquals(4, $links->count());
     $this->assertEquals(array('http://www.broken.com', 'http://www.broken.com/url/thing', 'http://www.broken.com/url/thing', 'http://www.nodomain.com'), array_values($links->map('ID', 'Link')->toArray()));
     // Check response codes are correct
     $expected = array('http://www.broken.com' => 403, 'http://www.broken.com/url/thing' => 404, 'http://www.nodomain.com' => 0);
     $actual = $links->map('Link', 'HTTPCode')->toArray();
     $this->assertEquals($expected, $actual);
     // Check response descriptions are correct
     i18n::set_locale('en_NZ');
     $expected = array('http://www.broken.com' => '403 (Forbidden)', 'http://www.broken.com/url/thing' => '404 (Not Found)', 'http://www.nodomain.com' => '0 (Server Not Available)');
     $actual = $links->map('Link', 'HTTPCodeDescription')->toArray();
     $this->assertEquals($expected, $actual);
 }
开发者ID:helpfulrobot,项目名称:govtnz-silverstripe-externallinks,代码行数:32,代码来源:ExternalLinksTest.php

示例3: tearDown

 public function tearDown()
 {
     parent::tearDown();
     i18n::set_locale($this->originalLocale);
     Config::inst()->remove('TimeField', 'default_config');
     Config::inst()->update('TimeField', 'default_config', $this->origTimeConfig);
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:7,代码来源:TimeFieldTest.php

示例4: tearDown

 public function tearDown()
 {
     parent::tearDown();
     i18n::set_locale($this->originalLocale);
     DateField::$default_config['dateformat'] = $this->origDateFormat;
     TimeField::$default_config['timeformat'] = $this->origTimeFormat;
 }
开发者ID:normann,项目名称:sapphire,代码行数:7,代码来源:DatetimeFieldTest.php

示例5: tearDown

 function tearDown()
 {
     parent::tearDown();
     // Static publishing will just confuse things
     StaticPublisher::$disable_realtime = false;
     i18n::set_locale($this->origLocale);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-cmsworkflow,代码行数:7,代码来源:WorkflowReportsTest.php

示例6: Languages

 /**
  * Get a set of content languages (for quick language navigation)
  * @example
  * <code>
  * <!-- in your template -->
  * <ul class="langNav">
  * 		<% loop Languages %>
  * 		<li><a href="$Link" class="$LinkingMode" title="$Title.ATT">$Language</a></li>
  * 		<% end_loop %>
  * </ul>
  * </code>
  *
  * @return ArrayList|null
  */
 public function Languages()
 {
     $locales = TranslatableUtility::get_content_languages();
     // there's no need to show a navigation when there's less than 2 languages. So return null
     if (count($locales) < 2) {
         return null;
     }
     $currentLocale = Translatable::get_current_locale();
     $homeTranslated = null;
     if ($home = SiteTree::get_by_link('home')) {
         /** @var SiteTree $homeTranslated */
         $homeTranslated = $home->getTranslation($currentLocale);
     }
     /** @var ArrayList $langSet */
     $langSet = ArrayList::create();
     foreach ($locales as $locale => $name) {
         Translatable::set_current_locale($locale);
         /** @var SiteTree $translation */
         $translation = $this->owner->hasTranslation($locale) ? $this->owner->getTranslation($locale) : null;
         $langSet->push(new ArrayData(array('Locale' => $locale, 'RFC1766' => i18n::convert_rfc1766($locale), 'Language' => DBField::create_field('Varchar', strtoupper(i18n::get_lang_from_locale($locale))), 'Title' => DBField::create_field('Varchar', html_entity_decode(i18n::get_language_name(i18n::get_lang_from_locale($locale), true), ENT_NOQUOTES, 'UTF-8')), 'LinkingMode' => $currentLocale == $locale ? 'current' : 'link', 'Link' => $translation ? $translation->AbsoluteLink() : ($homeTranslated ? $homeTranslated->Link() : ''))));
     }
     Translatable::set_current_locale($currentLocale);
     i18n::set_locale($currentLocale);
     return $langSet;
 }
开发者ID:bummzack,项目名称:translatable-dataobject,代码行数:39,代码来源:TranslatableUtility.php

示例7: onBeforeInit

 /**
  * @return void
  */
 public function onBeforeInit()
 {
     // Check if we are runing a dev build, if so check if DB needs
     // upgrading
     $controller = $this->owner->request->param("Controller");
     $action = $this->owner->request->param("Action");
     global $project;
     // Only check if the DB needs upgrading on a dev build
     if ($controller == "DevelopmentAdmin" && $action == "build") {
         // Now check if the files we need are installed
         // Check if we have the files we need, if not, create them
         if (!class_exists("Category")) {
             copy(BASE_PATH . "/catalogue/scaffold/Category", BASE_PATH . "/{$project}/code/model/Category.php");
         }
         if (!class_exists("Category_Controller")) {
             copy(BASE_PATH . "/catalogue/scaffold/Category_Controller", BASE_PATH . "/{$project}/code/control/Category_Controller.php");
         }
         if (!class_exists("Product")) {
             copy(BASE_PATH . "/catalogue/scaffold/Product", BASE_PATH . "/{$project}/code/model/Product.php");
         }
         if (!class_exists("Product_Controller")) {
             copy(BASE_PATH . "/catalogue/scaffold/Product_Controller", BASE_PATH . "/{$project}/code/control/Product_Controller.php");
         }
     }
     if ($controller != "DevelopmentAdmin") {
         if (class_exists('Subsite') && Subsite::currentSubsite()) {
             // Set the location
             i18n::set_locale(Subsite::currentSubsite()->Language);
         }
     }
 }
开发者ID:alialamshahi,项目名称:silverstripe-catalogue-prowall,代码行数:34,代码来源:CatalogueControllerExtension.php

示例8: onBeforeInit

 /**
  * Handles enabling translations for controllers that are not pages
  */
 public function onBeforeInit()
 {
     //Bail for the root url controller and model as controller classes as they handle this internally, also disable for development admin and cms
     if ($this->owner instanceof MultilingualRootURLController || $this->owner instanceof MultilingualModelAsController || $this->owner instanceof LeftAndMain || $this->owner instanceof DevelopmentAdmin || $this->owner instanceof TestRunner) {
         return;
     }
     //Bail for pages since this would have been handled by MultilingualModelAsController, we're assuming that data has not been set to a page by other code
     if (method_exists($this->owner, 'data') && $this->owner->data() instanceof SiteTree) {
         return;
     }
     //Check if the locale is in the url
     $request = $this->owner->getRequest();
     if ($request && $request->param('Language')) {
         $language = $request->param('Language');
         if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
             $locale = $language;
         } else {
             if (strpos($request->param('Language'), '_') !== false) {
                 //Invalid format so redirect to the default
                 $url = $request->getURL(true);
                 $default = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL') ? Translatable::default_locale() : Translatable::default_lang();
                 $this->owner->redirect(preg_replace('/^' . preg_quote($language, '/') . '\\//', $default . '/', $url), 301);
                 return;
             } else {
                 $locale = i18n::get_locale_from_lang($language);
             }
         }
         if (in_array($locale, Translatable::get_allowed_locales())) {
             //Set the language cookie
             Cookie::set('language', $language);
             //Set the various locales
             Translatable::set_current_locale($locale);
             i18n::set_locale($locale);
         } else {
             //Unknown language so redirect to the default
             $url = $request->getURL(true);
             $default = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL') ? Translatable::default_locale() : Translatable::default_lang();
             $this->owner->redirect(preg_replace('/^' . preg_quote($language, '/') . '\\//', $default . '/', $url), 301);
         }
         return;
     }
     //Detect the locale
     if ($locale = MultilingualRootURLController::detect_browser_locale()) {
         if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
             $language = $locale;
         } else {
             $language = i18n::get_lang_from_locale($locale);
         }
         //Set the language cookie
         Cookie::set('language', $language);
         //Set the various locales
         Translatable::set_current_locale($locale);
         i18n::set_locale($locale);
     }
 }
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:58,代码来源:MultilingualControllerExtension.php

示例9: 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

示例10: init

 public function init()
 {
     parent::init();
     i18n::set_locale(Session::get('language'));
     // You can include any CSS or JS required by your project here.
     // See: http://doc.silverstripe.org/framework/en/reference/requirements
     Requirements::css(BOWER_PATH . '/bootstrap/dist/css/bootstrap.min.css');
     Requirements::css('http://fonts.googleapis.com/css?family=Raleway');
     Requirements::css(BOWER_PATH . '/fancybox/source/jquery.fancybox.css');
     Requirements::css(BOWER_PATH . '/font-awesome/css/font-awesome.min.css');
     Requirements::css(CSS_DIR . '/customise.css');
     Requirements::javascript(BOWER_PATH . '/jquery/dist/jquery.min.js');
     Requirements::javascript(BOWER_PATH . '/bootstrap/dist/js/bootstrap.min.js');
     Requirements::javascript(BOWER_PATH . '/fancybox/source/jquery.fancybox.pack.js');
     Requirements::javascript("https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places");
 }
开发者ID:shawn3a,项目名称:ss_powermoney,代码行数:16,代码来源:Page.php

示例11: onBeforeInit

 /**
  * @return void
  */
 public function onBeforeInit()
 {
     if (class_exists('Subsite') && Subsite::currentSubsite()) {
         // Set the location
         i18n::set_locale(Subsite::currentSubsite()->Language);
         // Check if url is primary domain, if not, re-direct
         if ($_SERVER['HTTP_HOST'] != Subsite::currentSubsite()->getPrimaryDomain()) {
             $this->owner->redirect(Subsite::currentSubsite()->absoluteBaseURL());
         }
     }
     // Setup currency globally based on what is set in admin
     $config = SiteConfig::current_site_config();
     if ($config->Currency()) {
         Currency::setCurrencySymbol($config->Currency()->HTMLNotation);
     }
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:19,代码来源:Ext_Commerce_Controller.php

示例12: init_kern_environment

 protected static function init_kern_environment()
 {
     clock::stop();
     config::load();
     self::$log_execute_time = config::get_kern('log_execute_time', true);
     if (self::$log_execute_time) {
         self::$begin_microtime = clock::get_micro_stamp();
     }
     clock::set_timezone(config::get_kern('time_zone', 'Asia/Shanghai'));
     i18n::set_locale(config::get_kern('locale', 'en_us'));
     self::$is_debug = config::get_kern('is_debug', false);
     ini_set('display_errors', config::get_kern('display_errors', self::$is_debug));
     set_exception_handler([__CLASS__, 'exception_handler']);
     $error_reporting = config::get_kern('error_reporting', self::$is_debug ? E_ALL | E_STRICT : E_ALL & ~E_NOTICE);
     set_error_handler([__CLASS__, 'error_handler'], $error_reporting);
     loader::init();
 }
开发者ID:xpd1437,项目名称:swap,代码行数:17,代码来源:kern.php

示例13: testTranslate

 public function testTranslate()
 {
     i18n::set_locale('en_US');
     $this->assertEquals('Legacy translation', i18n::_t('i18nOtherModule.LEGACY'), 'Finds original strings in PHP module files');
     $this->assertEquals('Legacy translation', i18n::_t('i18nOtherModule.LEGACYTHEME'), 'Finds original strings in theme files');
     i18n::set_locale('de_DE');
     $this->assertEquals('Legacy translation (de_DE)', i18n::_t('i18nOtherModule.LEGACY'), 'Finds translations in PHP module files');
     $this->assertEquals('Legacy translation (de_DE)', i18n::_t('i18nOtherModule.LEGACYTHEME'), 'Finds original strings in theme files');
     // TODO Implement likely subtags solution
     // i18n::set_locale('de');
     // $this->assertEquals(
     // 	'Legacy translation (de_DE)',
     // 	// defined in i18nothermodule/lang/de_DE.php
     // 	i18n::_t('i18nOtherModule.LEGACY'),
     // 	'Finds translations in PHP module files if only language locale is set'
     // );
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:17,代码来源:i18nSSLegacyAdapterTest.php

示例14: init

 public function init()
 {
     parent::init();
     i18n::set_locale('de_DE');
     setlocale(LC_ALL, 'de_DE@euro', 'de_DE.UTF-8', 'de_DE', 'de', 'ge');
     i18n::set_date_format('dd.MM.YYYY');
     i18n::set_time_format('HH:mm');
     Requirements::set_write_js_to_body(false);
     Requirements::javascript("framework/thirdparty/jquery/jquery.js");
     Requirements::javascript("calendar/3rdparty/jquery-ui-1.9.2.custom.js");
     Requirements::javascript("calendar/3rdparty/fullcalendar/fullcalendar.js");
     Requirements::javascript("calendar/3rdparty/jQuery-Loading/toggleLoading.jquery.js");
     Requirements::javascript("calendar/javascript/widget.js");
     Requirements::css("framework/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css");
     Requirements::css("calendar/3rdparty/fullcalendar/fullcalendar.css");
     Requirements::css("calendar/css/calendar.css");
 }
开发者ID:robomod,项目名称:silverstripe-calendar,代码行数:17,代码来源:CalendarPage.php

示例15: testGettingWrittenDataObject

 /**
  * Write a Money object to the database, then re-read it to ensure it
  * is re-read properly.
  */
 function testGettingWrittenDataObject()
 {
     $local = i18n::get_locale();
     i18n::set_locale('en_US');
     //make sure that the $ amount is not prefixed by US$, as it would be in non-US locale
     $obj = new MoneyTest_DataObject();
     $m = new Money();
     $m->setAmount(987.65);
     $m->setCurrency('USD');
     $obj->MyMoney = $m;
     $this->assertEquals("\$987.65", $obj->MyMoney->Nice(), "Money field not added to data object properly when read prior to first writing the record.");
     $objID = $obj->write();
     $moneyTest = DataObject::get_by_id('MoneyTest_DataObject', $objID);
     $this->assertTrue($moneyTest instanceof MoneyTest_DataObject);
     $this->assertEquals('USD', $moneyTest->MyMoneyCurrency);
     $this->assertEquals(987.65, $moneyTest->MyMoneyAmount);
     $this->assertEquals("\$987.65", $moneyTest->MyMoney->Nice(), "Money field not added to data object properly when read.");
     i18n::set_locale($local);
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:23,代码来源:MoneyTest.php


注:本文中的i18n::set_locale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。