Best Atoum code snippet using locale
class-wp-locale-switcher.php
Source:class-wp-locale-switcher.php
...6 * @subpackage i18n7 * @since 4.7.08 */9/**10 * Core class used for switching locales.11 *12 * @since 4.7.013 */14class WP_Locale_Switcher {15 /**16 * Locale stack.17 *18 * @since 4.7.019 * @access private20 * @var string[]21 */22 private $locales = array();23 /**24 * Original locale.25 *26 * @since 4.7.027 * @access private28 * @var string29 */30 private $original_locale;31 /**32 * Holds all available languages.33 *34 * @since 4.7.035 * @access private36 * @var array An array of language codes (file names without the .mo extension).37 */38 private $available_languages = array();39 /**40 * Constructor.41 *42 * Stores the original locale as well as a list of all available languages.43 *44 * @since 4.7.045 */46 public function __construct() {47 $this->original_locale = is_admin() ? get_user_locale() : get_locale();48 $this->available_languages = array_merge( array( 'en_US' ), get_available_languages() );49 }50 /**51 * Initializes the locale switcher.52 *53 * Hooks into the {@see 'locale'} filter to change the locale on the fly.54 */55 public function init() {56 add_filter( 'locale', array( $this, 'filter_locale' ) );57 }58 /**59 * Switches the translations according to the given locale.60 *61 * @since 4.7.062 *63 * @param string $locale The locale to switch to.64 * @return bool True on success, false on failure.65 */66 public function switch_to_locale( $locale ) {67 $current_locale = is_admin() ? get_user_locale() : get_locale();68 if ( $current_locale === $locale ) {69 return false;70 }71 if ( ! in_array( $locale, $this->available_languages, true ) ) {72 return false;73 }74 $this->locales[] = $locale;75 $this->change_locale( $locale );76 /**77 * Fires when the locale is switched.78 *79 * @since 4.7.080 *81 * @param string $locale The new locale.82 */83 do_action( 'switch_locale', $locale );84 return true;85 }86 /**87 * Restores the translations according to the previous locale.88 *89 * @since 4.7.090 *91 * @return string|false Locale on success, false on failure.92 */93 public function restore_previous_locale() {94 $previous_locale = array_pop( $this->locales );95 if ( null === $previous_locale ) {96 // The stack is empty, bail.97 return false;98 }99 $locale = end( $this->locales );100 if ( ! $locale ) {101 // There's nothing left in the stack: go back to the original locale.102 $locale = $this->original_locale;103 }104 $this->change_locale( $locale );105 /**106 * Fires when the locale is restored to the previous one.107 *108 * @since 4.7.0109 *110 * @param string $locale The new locale.111 * @param string $previous_locale The previous locale.112 */113 do_action( 'restore_previous_locale', $locale, $previous_locale );114 return $locale;115 }116 /**117 * Restores the translations according to the original locale.118 *119 * @since 4.7.0120 *121 * @return string|false Locale on success, false on failure.122 */123 public function restore_current_locale() {124 if ( empty( $this->locales ) ) {125 return false;126 }127 $this->locales = array( $this->original_locale );128 return $this->restore_previous_locale();129 }130 /**131 * Whether switch_to_locale() is in effect.132 *133 * @since 4.7.0134 *135 * @return bool True if the locale has been switched, false otherwise.136 */137 public function is_switched() {138 return ! empty( $this->locales );139 }140 /**141 * Filters the WordPress install's locale.142 *143 * @since 4.7.0144 *145 * @param string $locale The WordPress install's locale.146 * @return string The locale currently being switched to.147 */148 public function filter_locale( $locale ) {149 $switched_locale = end( $this->locales );150 if ( $switched_locale ) {151 return $switched_locale;152 }153 return $locale;154 }155 /**156 * Load translations for a given locale.157 *158 * When switching to a locale, translations for this locale must be loaded from scratch.159 *160 * @since 4.7.0161 * @access private162 *163 * @global Mo[] $l10n An array of all currently loaded text domains.164 *165 * @param string $locale The locale to load translations for.166 */167 private function load_translations( $locale ) {168 global $l10n;169 $domains = $l10n ? array_keys( $l10n ) : array();170 load_default_textdomain( $locale );171 foreach ( $domains as $domain ) {172 if ( 'default' === $domain ) {173 continue;174 }175 unload_textdomain( $domain );176 get_translations_for_domain( $domain );177 }178 }179 /**180 * Changes the site's locale to the given one.181 *182 * Loads the translations, changes the global `$wp_locale` object and updates183 * all post type labels.184 *185 * @since 4.7.0186 * @access private187 *188 * @global WP_Locale $wp_locale The WordPress date and time locale object.189 *190 * @param string $locale The locale to change to.191 */192 private function change_locale( $locale ) {193 // Reset translation availability information.194 _get_path_to_translation( null, true );195 $this->load_translations( $locale );196 $GLOBALS['wp_locale'] = new WP_Locale();197 /**198 * Fires when the locale is switched to or restored.199 *200 * @since 4.7.0201 *202 * @param string $locale The new locale.203 */204 do_action( 'change_locale', $locale );205 }206}...
locale
Using AI Code Generation
1$locale = new \mageekguy\atoum\locale();2$locale->setLocale('fr_FR');3$score = new \mageekguy\atoum\score($locale);4$report = new \mageekguy\atoum\reports\realtime\cli();5$report->addWriter(new \mageekguy\atoum\writers\std\out());6$runner = new \mageekguy\atoum\runner();7$runner->addTestsFromDirectory('test');8$runner->setScore($score);9$runner->addReport($report);10$runner->run();11{12 public function test1()13 {14 $this->assert->string('test')->isEqualTo('test');15 }16}
locale
Using AI Code Generation
1$locale = new \mageekguy\atoum\locale();2$locale->setLocale('fr_FR');3$score->setLocale($locale);4$locale = new \mageekguy\atoum\locale();5$locale->setLocale('en_US');6$score->setLocale($locale);7$locale = new \mageekguy\atoum\locale();8$locale->setLocale('fr_FR');9$score->setLocale($locale);10$locale = new \mageekguy\atoum\locale();11$locale->setLocale('en_US');12$score->setLocale($locale);13$locale = new \mageekguy\atoum\locale();14$locale->setLocale('fr_FR');15$score->setLocale($locale);16$locale = new \mageekguy\atoum\locale();17$locale->setLocale('en_US');18$score->setLocale($locale);19$locale = new \mageekguy\atoum\locale();20$locale->setLocale('fr_FR');21$score->setLocale($locale);22$locale = new \mageekguy\atoum\locale();23$locale->setLocale('en_US');24$score->setLocale($locale);25$locale = new \mageekguy\atoum\locale();26$locale->setLocale('fr_FR');27$score->setLocale($locale);28$locale = new \mageekguy\atoum\locale();29$locale->setLocale('en_US');30$score->setLocale($locale);
locale
Using AI Code Generation
1$locale = new \mageekguy\atoum\locale();2$locale->setLocale(LC_ALL, 'en_US');3$locale->setCharset('UTF-8');4$locale = new \mageekguy\atoum\locale();5$locale->setLocale(LC_ALL, 'fr_FR');6$locale->setCharset('UTF-8');7$locale = new \mageekguy\atoum\locale();8$locale->setLocale(LC_ALL, 'de_DE');9$locale->setCharset('UTF-8');10$locale = new \mageekguy\atoum\locale();11$locale->setLocale(LC_ALL, 'es_ES');12$locale->setCharset('UTF-8');13$locale = new \mageekguy\atoum\locale();14$locale->setLocale(LC_ALL, 'pt_BR');15$locale->setCharset('UTF-8');16$locale = new \mageekguy\atoum\locale();17$locale->setLocale(LC_ALL, 'it_IT');18$locale->setCharset('UTF-8');19$locale = new \mageekguy\atoum\locale();20$locale->setLocale(LC_ALL, 'ru_RU');21$locale->setCharset('UTF-8');22$locale = new \mageekguy\atoum\locale();23$locale->setLocale(LC_ALL, 'ja_JP');24$locale->setCharset('UTF-8');25$locale = new \mageekguy\atoum\locale();26$locale->setLocale(LC_ALL, 'zh_CN');27$locale->setCharset('UTF-8');
locale
Using AI Code Generation
1$locale = new \mageekguy\atoum\locale();2$locale->setLocale('fr_FR');3$locale->addTranslations(__DIR__ . '/locales/');4$locale = new \mageekguy\atoum\locale();5$locale->setLocale('fr_FR');6$locale->addTranslations(__DIR__ . '/locales/');7$locale = new \mageekguy\atoum\locale();8$locale->setLocale('fr_FR');9$locale->addTranslations(__DIR__ . '/locales/');10$locale = new \mageekguy\atoum\locale();11$locale->setLocale('fr_FR');12$locale->addTranslations(__DIR__ . '/locales/');13$locale = new \mageekguy\atoum\locale();14$locale->setLocale('fr_FR');15$locale->addTranslations(__DIR__ . '/locales/');16$locale = new \mageekguy\atoum\locale();17$locale->setLocale('fr_FR');18$locale->addTranslations(__DIR__ . '/locales/');19$locale = new \mageekguy\atoum\locale();20$locale->setLocale('fr_FR');21$locale->addTranslations(__DIR__ . '/locales/');22$locale = new \mageekguy\atoum\locale();23$locale->setLocale('fr_FR');24$locale->addTranslations(__DIR__ . '/locales/');25$locale = new \mageekguy\atoum\locale();26$locale->setLocale('fr_FR');27$locale->addTranslations(__DIR__ . '/locales/');
locale
Using AI Code Generation
1$locale = new \mageekguy\atoum\locale();2$locale->setLocale('fr_FR');3$locale->setCharset('UTF-8');4$script->setLocale($locale);5$runner->addTestsFromDirectory(__DIR__ . '/tests');6$runner->run();
locale
Using AI Code Generation
1require_once 'vendor/autoload.php';2use mageekguy\atoum\locale;3$locale = new locale();4$locale->setLocale('fr_FR');5require_once 'vendor/autoload.php';6use mageekguy\atoum\locale;7$locale = new locale();8$locale->setLocale('en_US');9require_once 'vendor/autoload.php';10use mageekguy\atoum\locale;11$locale = new locale();12$locale->setLocale('fr_FR');13require_once 'vendor/autoload.php';14use mageekguy\atoum\locale;15$locale = new locale();16$locale->setLocale('en_US');17require_once 'vendor/autoload.php';18use mageekguy\atoum\locale;19$locale = new locale();20$locale->setLocale('fr_FR');21require_once 'vendor/autoload.php';22use mageekguy\atoum\locale;23$locale = new locale();24$locale->setLocale('en_US');25require_once 'vendor/autoload.php';26use mageekguy\atoum\locale;27$locale = new locale();28$locale->setLocale('fr_FR');29require_once 'vendor/autoload.php';30use mageekguy\atoum\locale;31$locale = new locale();32$locale->setLocale('en_US');33require_once 'vendor/autoload.php';34use mageekguy\atoum\locale;35$locale = new locale();36$locale->setLocale('fr_FR');
locale
Using AI Code Generation
1$locale = new \mageekguy\atoum\locale();2$locale->setLocale('fr_FR');3$locale->addToRunner($runner);4$runner->setLocale($locale);5$locale = new \mageekguy\atoum\locale();6$locale->setLocale('en_US');7$locale->addToRunner($runner);8$runner->setLocale($locale);
locale
Using AI Code Generation
1$locale = new \mageekguy\atoum\locale();2$locale->setLocale('fr_FR');3$locale->addTranslator(__DIR__ . '/locales');4return array(5);6$locale = new \mageekguy\atoum\locale();7$locale->setLocale('fr_FR');8$locale->addTranslator(__DIR__ . '/locales');9return array(10);11$locale = new \mageekguy\atoum\locale();12$locale->setLocale('fr_FR');13$locale->addTranslator(__DIR__ . '/locales');14return array(15);16$locale = new \mageekguy\atoum\locale();17$locale->setLocale('fr_FR');18$locale->addTranslator(__DIR__ . '/locales');19return array(20);21$locale = new \mageekguy\atoum\locale();22$locale->setLocale('fr_FR');23$locale->addTranslator(__DIR__ . '/locales');24return array(25);26$locale = new \mageekguy\atoum\locale();27$locale->setLocale('fr_FR');28$locale->addTranslator(__DIR__ . '/locales');29return array(30);
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.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!