alternateBasePath = __DIR__ . $s . 'i18nTest' . $s . "_fakewebroot"; Director::config()->update('alternate_base_folder', $this->alternateBasePath); // Replace old template loader with new one with alternate base path $this->oldThemeResourceLoader = ThemeResourceLoader::instance(); ThemeResourceLoader::set_instance($loader = new ThemeResourceLoader($this->alternateBasePath)); $loader->addSet( '$default', new ThemeManifest( $this->alternateBasePath, project(), false, true ) ); SSViewer::set_themes([ 'testtheme1', '$default', ]); $this->originalLocale = i18n::get_locale(); i18n::set_locale('en_US'); // Set new manifest against the root $classManifest = new ClassManifest($this->alternateBasePath, true, true, false); $this->pushManifest($classManifest); // Setup uncached translator // This should pull the module list from the above manifest $translator = new Translator('en'); $translator->setFallbackLocales(['en']); $loader = new ModuleYamlLoader(); $loader->setReader(new YamlReader()); $translator->addLoader('ss', $loader); // Standard ss module loader $translator->addLoader('array', new ArrayLoader()); // Note: array loader isn't added by default $provider = new SymfonyMessageProvider(); $provider->setTranslator($translator); Injector::inst()->registerService($provider, MessageProvider::class); } public function tearDownManifest() { ThemeResourceLoader::set_instance($this->oldThemeResourceLoader); i18n::set_locale($this->originalLocale); // Reset any manifests pushed during this test $this->popManifests(); } /** * Safely push a new class manifest. * These will be cleaned up on tearDown() * * @param ClassManifest $manifest */ protected function pushManifest(ClassManifest $manifest) { $this->manifests++; ClassLoader::instance()->pushManifest($manifest); } /** * Pop off all extra manifests */ protected function popManifests() { // Reset any manifests pushed during this test while ($this->manifests > 0) { ClassLoader::instance()->popManifest(); $this->manifests--; } } }