Best Atoum code snippet using locale.set
AddCommand.php
Source:AddCommand.php
...59 protected $availableLocales = [];60 61 protected function configure()62 {63 $this->setDescription('Adds a new locale and copies translatable entities');64 $this->setName('locale:add');65 }66 67 protected function initialize(InputInterface $input, OutputInterface $output)68 {69 $this->localeManager = $this->getLocaleManager();70 $this->localeDataSet = $this->getLocaleDataSet();71 $this->currencyDataSet = $this->getCurrencyDataSet();72 $this->installedLocales = $this->getInstalledLocales();73 $this->installedCurrencies = $this->getInstalledCurrencies();74 $this->availableLocales = $this->getAvailableLocales();75 }76 77 protected function execute(InputInterface $input, OutputInterface $output)78 {79 $sourceLocale = $this->chooseSourceLocale($input, $output);80 $targetLocale = $this->chooseTargetLocale($input, $output);81 $targetCurrency = $this->chooseTargetCurrency($input, $output);82 83 $locale = $this->createLocale($targetLocale, $targetCurrency);84 $output->writeln(sprintf('<info>Created a new locale "%s"</info>', $locale->getCode()));85 86 $this->copyLocaleData($sourceLocale, $targetLocale);87 88 $output->writeln(sprintf('<info>Finished copying "%s" data</info>', $locale->getCode()));89 }90 91 private function createLocale(string $localeCode, string $targetLocaleCurrency): Locale92 {93 $currency = $this->getTargetCurrency($targetLocaleCurrency);94 /** @var Locale $locale */95 $locale = $this->localeManager->initResource();96 $locale->setCode($localeCode);97 $locale->setEnabled(true);98 $locale->setCurrency($currency);99 $this->localeManager->createResource($locale);100 101 return $locale;102 }103 104 private function findLocale(string $code): Locale105 {106 return $this->localeManager->getRepository()->findOneBy(['code' => $code]);107 }108 109 private function copyLocaleData(string $sourceLocaleCode, string $targetLocaleCode)110 {111 $sourceLocale = $this->findLocale($sourceLocaleCode);112 $targetLocale = $this->findLocale($targetLocaleCode);113 114 $this->getLocaleCopier()->copyLocaleData($sourceLocale, $targetLocale);115 }116 117 private function getTargetCurrency($targetCurrency): Currency118 {119 return $this->getContainer()->get('currency.repository')->findOneBy(['code' => $targetCurrency]);120 }121 122 private function chooseSourceLocale(InputInterface $input, OutputInterface $output): string123 {124 $defaultLocale = current($this->installedLocales);125 $question = new ChoiceQuestion(126 sprintf(127 'Please select source locale from which new entities will be copied (defaults to "%s"):',128 $defaultLocale129 ),130 $this->installedLocales,131 $defaultLocale132 );133 134 $sourceLocale = $this->getHelper('question')->ask($input, $output, $question);135 136 return $sourceLocale;137 }138 139 private function chooseTargetLocale(InputInterface $input, OutputInterface $output): string140 {141 $question = new ChoiceQuestion('Please select target locale to which new entities will be copied:', $this->availableLocales);142 $targetLocale = $this->getHelper('question')->ask($input, $output, $question);143 144 return $targetLocale;145 }146 147 private function chooseTargetCurrency(InputInterface $input, OutputInterface $output): string148 {149 $question = new ChoiceQuestion('Please select a default currency for new locale:', $this->installedCurrencies);150 $targetLocaleCurrency = $this->getHelper('question')->ask($input, $output, $question);151 152 return $targetLocaleCurrency;153 }154 155 private function getInstalledCurrencies(): array156 {157 return $this->currencyDataSet->getResult('select', ['order_by' => 'code'], [158 'label_column' => 'code',159 'value_column' => 'code',160 ]);161 }162 163 private function getInstalledLocales(): array164 {165 return $this->localeDataSet->getResult('select', ['order_by' => 'code'], [166 'label_column' => 'code',167 'value_column' => 'code',168 ]);169 }170 171 private function getAvailableLocales(): array172 {173 $locales = [];174 $collection = Intl::getLocaleBundle()->getLocaleNames();175 176 foreach ($collection as $locale => $name) {177 if (!in_array($locale, $this->installedLocales)) {178 $locales[$locale] = $name;179 }180 }181 182 return $locales;183 }184 185 private function getLocaleDataSet(): LocaleDataSet186 {187 return $this->getContainer()->get('locale.dataset.admin');188 }189 190 private function getCurrencyDataSet(): CurrencyDataSet191 {192 return $this->getContainer()->get('currency.dataset.admin');193 }194 195 private function getLocaleManager(): ManagerInterface196 {197 return $this->getContainer()->get('locale.manager');198 }199 200 private function getLocaleCopier(): LocaleCopierInterface201 {202 return $this->getContainer()->get('locale.copier');203 }204}...
locale_set_default.phpt
Source:locale_set_default.phpt
1--TEST--2locale_set_default($locale)3--SKIPIF--4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>5--FILE--6<?php7/*8 * Try setting the default Locale with different locales9 * with Procedural and Object methods.10 */11function ut_main()12{13 $res_str = '';14 $locales = array(15 'uk-ua_CALIFORNIA@currency=;currency=GRN',16 'root',17 'uk@currency=EURO',18 'Hindi',19//Simple language subtag20 'de',21 'fr',22 'ja',23 'i-enochian', //(example of a grandfathered tag)24//Language subtag plus Script subtag:25 'zh-Hant',26 'zh-Hans',27 'sr-Cyrl',28 'sr-Latn',29//Language-Script-Region30 'zh-Hans-CN',31 'sr-Latn-CS',32//Language-Variant33 'sl-rozaj',34 'sl-nedis',35//Language-Region-Variant36 'de-CH-1901',37 'sl-IT-nedis',38//Language-Script-Region-Variant39 'sl-Latn-IT-nedis',40//Language-Region:41 'de-DE',42 'en-US',43 'es-419',44//Private use subtags:45 'de-CH-x-phonebk',46 'az-Arab-x-AZE-derbend',47//Extended language subtags48 'zh-min',49 'zh-min-nan-Hant-CN',50//Private use registry values51 'x-whatever',52 'qaa-Qaaa-QM-x-southern',53 'sr-Latn-QM',54 'sr-Qaaa-CS',55//Tags that use extensions (examples ONLY: extensions MUST be defined56// by revision or update to this document or by RFC): 57 'en-US-u-islamCal',58 'zh-CN-a-myExt-x-private',59 'en-a-myExt-b-another',60//Some Invalid Tags:61 'de-419-DE',62 'a-DE',63 'ar-a-aaa-b-bbb-a-ccc'64 );65/*66 $locales = array( 67 'es'68 );69*/70 $res_str = '';71 foreach( $locales as $locale )72 {73 $isSuccessful = ut_loc_set_default( $locale);74 if ($isSuccessful ){75 $lang = ut_loc_get_default( );76 $res_str .= "$locale: set locale '$lang'";77 }78 else{79 $res_str .= "$locale: Error in set locale";80 }81 $res_str .= "\n";82 }83 return $res_str;84}85include_once( 'ut_common.inc' );86ut_run();87?>88--EXPECT--89uk-ua_CALIFORNIA@currency=;currency=GRN: set locale 'uk-ua_CALIFORNIA@currency=;currency=GRN'90root: set locale 'root'91uk@currency=EURO: set locale 'uk@currency=EURO'92Hindi: set locale 'Hindi'93de: set locale 'de'94fr: set locale 'fr'95ja: set locale 'ja'96i-enochian: set locale 'i-enochian'97zh-Hant: set locale 'zh-Hant'98zh-Hans: set locale 'zh-Hans'99sr-Cyrl: set locale 'sr-Cyrl'100sr-Latn: set locale 'sr-Latn'101zh-Hans-CN: set locale 'zh-Hans-CN'102sr-Latn-CS: set locale 'sr-Latn-CS'103sl-rozaj: set locale 'sl-rozaj'104sl-nedis: set locale 'sl-nedis'105de-CH-1901: set locale 'de-CH-1901'106sl-IT-nedis: set locale 'sl-IT-nedis'107sl-Latn-IT-nedis: set locale 'sl-Latn-IT-nedis'108de-DE: set locale 'de-DE'109en-US: set locale 'en-US'110es-419: set locale 'es-419'111de-CH-x-phonebk: set locale 'de-CH-x-phonebk'112az-Arab-x-AZE-derbend: set locale 'az-Arab-x-AZE-derbend'113zh-min: set locale 'zh-min'114zh-min-nan-Hant-CN: set locale 'zh-min-nan-Hant-CN'115x-whatever: set locale 'x-whatever'116qaa-Qaaa-QM-x-southern: set locale 'qaa-Qaaa-QM-x-southern'117sr-Latn-QM: set locale 'sr-Latn-QM'118sr-Qaaa-CS: set locale 'sr-Qaaa-CS'119en-US-u-islamCal: set locale 'en-US-u-islamCal'120zh-CN-a-myExt-x-private: set locale 'zh-CN-a-myExt-x-private'121en-a-myExt-b-another: set locale 'en-a-myExt-b-another'122de-419-DE: set locale 'de-419-DE'123a-DE: set locale 'a-DE'124ar-a-aaa-b-bbb-a-ccc: set locale 'ar-a-aaa-b-bbb-a-ccc'...
ResolverTest.php
Source:ResolverTest.php
...13 /**14 * @var \Magento\Framework\Locale\ResolverInterface15 */16 protected $_model;17 protected function setUp()18 {19 parent::setUp();20 $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(21 \Magento\Backend\Model\Locale\Resolver::class22 );23 }24 /**25 * @covers \Magento\Backend\Model\Locale\Resolver::setLocale26 */27 public function testSetLocaleWithDefaultLocale()28 {29 $this->_checkSetLocale(Resolver::DEFAULT_LOCALE);30 }31 /**32 * @covers \Magento\Backend\Model\Locale\Resolver::setLocale33 */34 public function testSetLocaleWithBaseInterfaceLocale()35 {36 $user = new \Magento\Framework\DataObject();37 $session = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(38 \Magento\Backend\Model\Auth\Session::class39 );40 $session->setUser($user);41 \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(42 \Magento\Backend\Model\Auth\Session::class43 )->getUser()->setInterfaceLocale(44 'fr_FR'45 );46 $this->_checkSetLocale('fr_FR');47 }48 /**49 * @covers \Magento\Backend\Model\Locale\Resolver::setLocale50 */51 public function testSetLocaleWithSessionLocale()52 {53 \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(54 \Magento\Backend\Model\Session::class55 )->setSessionLocale(56 'es_ES'57 );58 $this->_checkSetLocale('es_ES');59 }60 /**61 * @covers \Magento\Backend\Model\Locale\Resolver::setLocale62 */63 public function testSetLocaleWithRequestLocale()64 {65 $request = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()66 ->get(\Magento\Framework\App\RequestInterface::class);67 $request->setPostValue(['locale' => 'de_DE']);68 $this->_checkSetLocale('de_DE');69 }70 /**71 * Check set locale72 *73 * @param string $localeCodeToCheck74 * @return void75 */76 protected function _checkSetLocale($localeCodeToCheck)77 {78 $this->_model->setLocale();79 $localeCode = $this->_model->getLocale();80 $this->assertEquals($localeCode, $localeCodeToCheck);81 }82}...
set
Using AI Code Generation
1$locale = new Zend_Locale('en_US');2$locale->setLocale('de_DE');3echo $locale;4$locale = new Zend_Locale('en_US');5$locale->setLocale('de_DE');6echo $locale;7$locale = new Zend_Locale('en_US');8Zend_Locale::setDefault('de_DE');9echo $locale;10$locale = new Zend_Locale('en_US');11Zend_Locale::setDefault('de_DE');12echo $locale;13$locale = new Zend_Locale('en_US');14Zend_Locale::setDefault('de_DE');15echo $locale;16$locale = new Zend_Locale('en_US');17Zend_Locale::setDefault('de_DE');18echo $locale;19$locale = new Zend_Locale('en_US');20Zend_Locale::setDefault('de_DE');21echo $locale;22$locale = new Zend_Locale('en_US');23Zend_Locale::setDefault('de_DE');24echo $locale;25$locale = new Zend_Locale('en_US');26Zend_Locale::setDefault('de_DE');27echo $locale;28$locale = new Zend_Locale('en_US');29Zend_Locale::setDefault('de_DE');30echo $locale;31$locale = new Zend_Locale('en_US');32Zend_Locale::setDefault('de_DE');33echo $locale;34$locale = new Zend_Locale('en_US');35Zend_Locale::setDefault('de_DE');36echo $locale;
set
Using AI Code Generation
1$locale = new Zend_Locale('en_US');2$locale->setLocale('en_GB');3$locale = new Zend_Locale();4$locale->getLocale();5$locale = new Zend_Locale();6$locale->getBrowser();7$locale = new Zend_Locale();8$locale->getEnvironment();9$locale = new Zend_Locale();10$locale->getTranslation('January', 'dateitem', 'en_US');11$locale = new Zend_Locale();12$locale->isLocale('en_US');13$locale = new Zend_Locale();14$locale->setCache(new Zend_Cache_Core());15$locale = new Zend_Locale();16$locale->setDefault('en_US');17$locale = new Zend_Locale();18$locale->setLocale('en_US');19$locale = new Zend_Locale();20$locale->setTranslation(array('January' => 'January'), 'dateitem', 'en_US');21$locale = new Zend_Locale();22$locale->setTranslationList(array('January' => 'January'), 'dateitem', 'en_US');23$locale = new Zend_Locale();24$locale->setTranslationList(array('January' => 'January'), 'dateitem', 'en_US');25$locale = new Zend_Locale();26$locale->setTranslation(array('January' => 'January'), 'dateitem', 'en_US');
set
Using AI Code Generation
1$locale = new Zend_Locale('en_US');2$locale->setLocale('fr_FR');3echo $locale;4$translate = new Zend_Translate('array', array('Hello World' => 'Bonjour le monde'), 'en_US');5$translate->setLocale('fr_FR');6echo $translate->translate('Hello World');7$date = new Zend_Date('2009-12-25', Zend_Date::ISO_8601, 'en_US');8$date->setLocale('fr_FR');9echo $date->toString('d MMMM yyyy');10$currency = new Zend_Currency('en_US');11$currency->setLocale('fr_FR');12echo $currency->toCurrency(1000);13$number = new Zend_Locale_Format('en_US');14$number->setLocale('fr_FR');15echo $number->toNumber(1000);16$timezone = new Zend_Date('2009-12-25', Zend_Date::ISO_8601, 'en_US');17$timezone->setLocale('fr_FR');18echo $timezone->get(Zend_Date::TIMEZONE);19$calendar = new Zend_Date('2009-12-25', Zend_Date::ISO_8601, 'en_US');20$calendar->setLocale('fr_FR');21echo $calendar->get(Zend_Date::ERA);22$measurement = new Zend_Measure_Length('100', Zend_Measure_Length::METER, 'en_US');23$measurement->setLocale('fr_FR');24echo $measurement->toString();
set
Using AI Code Generation
1$locale = new Zend_Locale('en_US');2Zend_Locale::setDefault($locale);3$locale = Zend_Locale::getDefault();4echo $locale;5$locale = new Zend_Locale('en_US');6Zend_Locale::setDefault($locale);7$locale = Zend_Locale::getDefault();8Fatal error: Call to undefined method Zend_Locale::getDefault() in /var/www/ZendFramework-1.8.1-demos/library/Zend/Locale.php on line 2019$locale = new Zend_Locale('en_US');10Zend_Locale::setDefault($locale);11$locale = Zend_Locale::getDefault();12Fatal error: Call to undefined method Zend_Locale::getDefault() in /var/www/ZendFramework-1.8.1-demos/library/Zend/Locale.php on line 20113$locale = new Zend_Locale('en_US');14Zend_Locale::setDefault($locale);15$locale = Zend_Locale::getDefault();16Fatal error: Call to undefined method Zend_Locale::getDefault() in /var/www/ZendFramework-1.8.1-demos/library/Zend/Locale.php on line 20117$locale = new Zend_Locale('en_US');18Zend_Locale::setDefault($locale);19$locale = Zend_Locale::getDefault();20Fatal error: Call to undefined method Zend_Locale::getDefault() in /var/www/ZendFramework-
set
Using AI Code Generation
1require_once 'Locale.php';2$locale = new Locale('en_US');3$locale->setLocale('fr_FR');4echo $locale->getLocale();5require_once 'Locale.php';6$locale = new Locale('en_US');7echo $locale->getLocale();8require_once 'Locale.php';9$locale = new Locale('en_US');10echo $locale->getLocale();11require_once 'Locale.php';12$locale = new Locale('en_US');13echo $locale->getLocale();14require_once 'Locale.php';15$locale = new Locale('en_US');16echo $locale->getLocale();17require_once 'Locale.php';18$locale = new Locale('en_US');19echo $locale->getLocale();20require_once 'Locale.php';21$locale = new Locale('en_US');22echo $locale->getLocale();23require_once 'Locale.php';24$locale = new Locale('en_US');25echo $locale->getLocale();26require_once 'Locale.php';27$locale = new Locale('en_US');28echo $locale->getLocale();29require_once 'Locale.php';30$locale = new Locale('en_US');31echo $locale->getLocale();32require_once 'Locale.php';33$locale = new Locale('en_US');34echo $locale->getLocale();
set
Using AI Code Generation
1$locale = new Zend_Locale('en');2$locale->setLocale('fr');3echo $locale->getLanguage();4$locale = new Zend_Locale('en');5$locale->setLocale('fr');6echo $locale->getLanguage();7$locale = new Zend_Locale('en');8$locale->setLocale('fr');9echo $locale->getLanguage();10$locale = new Zend_Locale('en');11$locale->setLocale('fr');12echo $locale->getLanguage();13$locale = new Zend_Locale('en');14$locale->setLocale('fr');15echo $locale->getLanguage();16$locale = new Zend_Locale('en');17$locale->setLocale('fr');18echo $locale->getLanguage();19$locale = new Zend_Locale('en');20$locale->setLocale('fr');21echo $locale->getLanguage();22$locale = new Zend_Locale('en');23$locale->setLocale('fr');24echo $locale->getLanguage();25$locale = new Zend_Locale('en');26$locale->setLocale('fr');27echo $locale->getLanguage();28$locale = new Zend_Locale('en');29$locale->setLocale('fr');30echo $locale->getLanguage();
set
Using AI Code Generation
1$locale->set('de_DE');2$locale->get();3$locale->getDisplayLanguage();4$locale->getDisplayScript();5$locale->getDisplayCountry();6$locale->getDisplayVariant();7$locale->getDisplayName();8$locale->getDisplayLanguage('en_US');9$locale->getDisplayScript('en_US');10$locale->getDisplayCountry('en_US');11$locale->getDisplayVariant('en_US');12$locale->getDisplayName('en_US');13$locale->getDisplayLanguage('en_US', 'de_DE');14$locale->getDisplayScript('en_US', 'de_DE');15$locale->getDisplayCountry('en_US', 'de_DE');16$locale->getDisplayVariant('en_US', 'de_DE');17$locale->getDisplayName('en_US
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with set on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!