本文整理汇总了PHP中Locale::setDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::setDefault方法的具体用法?PHP Locale::setDefault怎么用?PHP Locale::setDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::setDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testValidateUsingCountrySpecificLocale
public function testValidateUsingCountrySpecificLocale()
{
\Locale::setDefault('en_GB');
$existingCountry = 'GB';
$this->context->expects($this->never())->method('addViolation');
$this->validator->validate($existingCountry, new Country());
}
示例2: setLocale
public function setLocale($locale)
{
setlocale(LC_ALL, $locale);
setlocale(LC_TIME, $locale);
PhpLocale::setDefault($locale);
$this->lang->setLangId(explode('_', $locale)[0]);
}
示例3: testValidateUsingCountrySpecificLocale
public function testValidateUsingCountrySpecificLocale()
{
\Locale::setDefault('fr_FR');
$existingLanguage = 'en';
$this->context->expects($this->never())->method('addViolation');
$this->validator->validate($existingLanguage, new Language(array('message' => 'aMessage')));
}
示例4: requireIntl
/**
* Should be called before tests that work fine with the stub implementation.
*/
public static function requireIntl(\PHPUnit_Framework_TestCase $testCase, $minimumIcuVersion = null)
{
if (null === $minimumIcuVersion) {
$minimumIcuVersion = Intl::getIcuStubVersion();
}
// We only run tests if the version is *one specific version*.
// This condition is satisfied if
//
// * the intl extension is loaded with version Intl::getIcuStubVersion()
// * the intl extension is not loaded
if (($minimumIcuVersion || defined('HHVM_VERSION_ID')) && IcuVersion::compare(Intl::getIcuVersion(), $minimumIcuVersion, '!=', 1)) {
$testCase->markTestSkipped('ICU version ' . $minimumIcuVersion . ' is required.');
}
// Normalize the default locale in case this is not done explicitly
// in the test
\Locale::setDefault('en');
// Consequently, tests will
//
// * run only for one ICU version (see Intl::getIcuStubVersion())
// there is no need to add control structures to your tests that
// change the test depending on the ICU version.
//
// Tests should only rely on functionality that is implemented in the
// stub classes.
}
示例5: setupDependencyInjection
/**
* Append objects to the global dependency injection container.
*
* @param Pimple\Container $container
*/
public static function setupDependencyInjection(Container $container)
{
parent::setupDependencyInjection($container);
$locale = $container['session']->get('_locale', 'en');
$container['request']->setLocale($locale);
\Locale::setDefault($locale);
}
示例6: testConstructor
public function testConstructor()
{
// Testing defaults
$validator = new CurrencyValidator();
$this->assertEquals('en_US', $validator->getLocale());
$this->assertEquals(Uncurrency::DEFAULT_SCALE_CORRECTNESS, $validator->getScaleCorrectness());
$this->assertEquals(Uncurrency::DEFAULT_CURRENCY_CORRECTNESS, $validator->getCurrencyCorrectness());
$this->assertEquals(CurrencyValidator::DEFAULT_NEGATIVE_ALLOWED, $validator->isNegativeAllowed());
// Testing application locale
\Locale::setDefault('de_DE');
$validator = new CurrencyValidator();
$this->assertEquals('de_DE', $validator->getLocale());
// Testing locale
$validator = new CurrencyValidator(['locale' => 'it_IT']);
$this->assertEquals('it_IT', $validator->getLocale());
// Testing options
$validator = new CurrencyValidator(['locale' => 'it_IT', 'currency_code' => 'EUR', 'scale_correctness' => false, 'currency_correctness' => false, 'negative_allowed' => false]);
$this->assertFalse($validator->getScaleCorrectness());
$this->assertFalse($validator->getCurrencyCorrectness());
$this->assertFalse($validator->isNegativeAllowed());
// Testing traversable
$traversableOpts = new ArrayObject(['locale' => 'it_IT', 'currency_code' => 'EUR', 'scale_correctness' => true, 'currency_correctness' => false, 'negative_allowed' => true]);
$validator = new CurrencyValidator();
$validator->setOptions($traversableOpts);
$this->assertEquals('it_IT', $validator->getLocale());
$this->assertTrue($validator->getScaleCorrectness());
$this->assertFalse($validator->getCurrencyCorrectness());
$this->assertTrue($validator->isNegativeAllowed());
}
示例7: onBootstrap
/**
* @param MvcEvent $event
*/
public function onBootstrap(MvcEvent $event)
{
$eventManager = $event->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$application = $event->getApplication();
$eventManager = $application->getEventManager();
/* @var $serviceManager ServiceManager */
$serviceManager = $application->getServiceManager();
$config = $serviceManager->get('config');
if (array_key_exists('locale', $config)) {
$config = $config['locale'];
} else {
$config = null;
}
if (!$config) {
Locale::setDefault('en');
// hardcoded here
$translator = $serviceManager->get('translator');
AbstractValidator::setDefaultTranslator($translator);
return;
}
$settings = new Settings($config);
// set the locale based on URL from route or cookie & set the default translator to all the app
$eventManager->attach(MvcEvent::EVENT_ROUTE, function (MvcEvent $e) use($config, $settings, $serviceManager) {
$settings->setRouteMatch($e->getRouteMatch());
if (!$e->getRequest() instanceof Request) {
$settings->setRequest($e->getRequest());
}
\Locale::setDefault($settings->getLocale());
$translator = $serviceManager->get('translator');
AbstractValidator::setDefaultTranslator($translator);
}, -9);
}
示例8: testOverrideCurrency
public function testOverrideCurrency()
{
\Locale::setDefault("fr_FR");
$form = $this->factory->create($this->simpleMoneyTypeClass, null, ["currency" => "USD"]);
$form->submit(array("tbbc_amount" => '1 252,5'));
$this->assertEquals(Money::USD(125250), $form->getData());
}
示例9: testDefaultLocaleFromHttpHeader
public function testDefaultLocaleFromHttpHeader()
{
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'sv-se,sv;q=0.8,en-us;q=0.6,en;q=0.4';
\Locale::setDefault('fi');
\Library\Application::init('Console', true);
$this->assertEquals('sv_SE', \Locale::getDefault());
}
示例10: tearDown
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->locale);
unset($this->locale);
unset($this->formType);
}
示例11: requireFullIntl
/**
* Should be called before tests that require a feature-complete intl
* implementation.
*
* @param \PhpUnit_Framework_TestCase $testCase
*/
public static function requireFullIntl(\PhpUnit_Framework_TestCase $testCase)
{
// We only run tests if the intl extension is loaded...
if (!Intl::isExtensionLoaded()) {
$testCase->markTestSkipped('The intl extension is not available.');
}
// ... and only if the version is *one specific version* ...
if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', $precision = 1)) {
$testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion());
}
// ... and only if the data in the Icu component matches that version.
if (IcuVersion::compare(Intl::getIcuDataVersion(), Intl::getIcuStubVersion(), '!=', $precision = 1)) {
$testCase->markTestSkipped('Please change the Icu component to version 1.0.x or 1.' . IcuVersion::normalize(Intl::getIcuStubVersion(), 1) . '.x');
}
// Normalize the default locale in case this is not done explicitly
// in the test
\Locale::setDefault('en');
// Consequently, tests will
//
// * run only for one ICU version (see Intl::getIcuStubVersion())
// there is no need to add control structures to your tests that
// change the test depending on the ICU version.
// * always use the C intl classes
// * always use the binary resource bundles (any locale is allowed)
}
示例12: setUp
protected function setUp()
{
\Locale::setDefault('en');
$dispatcher = new EventDispatcher();
$this->csrfProvider = $this->getMock('Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface');
$this->factory = new FormFactory(array(new CoreExtension(), new CsrfExtension($this->csrfProvider)));
}
示例13: testValidCurrenciesWithCountrySpecificLocale
/**
* @dataProvider getValidCurrencies
**/
public function testValidCurrenciesWithCountrySpecificLocale($currency)
{
IntlTestHelper::requireFullIntl($this);
\Locale::setDefault('en_GB');
$this->validator->validate($currency, new Currency());
$this->assertNoViolation();
}
示例14: testToString
public function testToString($value, $currencyCode, $expectedOutput)
{
if (Intl::isExtensionLoaded()) {
\Locale::setDefault('en');
}
$this->if($price = new TestedPrice($value, $currencyCode))->phpString((string) $price)->isIdenticalTo($expectedOutput);
}
示例15: testMoneyPatternWorksForYen
public function testMoneyPatternWorksForYen()
{
\Locale::setDefault('en_US');
$form = $this->factory->create('money', null, array('currency' => 'JPY'));
$view = $form->createView();
$this->assertTrue((bool) strstr($view->get('money_pattern'), '¥'));
}