/** * Renders the language selector * @return string */ public function render($twBoot = false) { /** @var array $locales */ $locales = Config::get('laravel-gettext.supported-locales'); /** @var string $currentLocale */ $currentLocale = $this->gettext->getLocale(); switch ($twBoot) { case true: return $this->renderBootstrap($locales, $currentLocale); break; default: return $this->render($locales, $currentLocale); } }
/** * Renders the language selector * @return String */ public function render() { $html = '<ul class="language-selector">'; foreach (Config::get('laravel-gettext.supported-locales') as $locale) { if (count($this->labels) && array_key_exists($locale, $this->labels)) { $localeLabel = $this->labels[$locale]; } else { $localeLabel = $locale; } if ($locale == $this->gettext->getLocale()) { $html .= '<li><strong class="active ' . $locale . '">' . $localeLabel . '</strong></li>'; } else { $html .= '<li><a href="/lang/' . $locale . '" class="' . $locale . '">' . $localeLabel . '</a></li>'; } } $html .= '</ul>'; return $html; }
/** * Renders the language selector * @return string */ public function render() { /** @var string $currentLocale */ $currentLocale = $this->gettext->getLocale(); $html = '<ul class="language-selector">'; foreach ($this->gettext->getSupportedLocales() as $locale) { $localeLabel = $locale; // Check if label exists if (array_key_exists($locale, $this->labels)) { $localeLabel = $this->labels[$locale]; } $link = '<a href="/lang/' . $locale . '" class="' . $locale . '">' . $localeLabel . '</a>'; if ($locale == $currentLocale) { $link = '<strong class="active ' . $locale . '">' . $localeLabel . '</strong>'; } $html .= '<li>' . $link . '</li>'; } $html .= '</ul>'; return $html; }
/** * @expectedException \Xinax\LaravelGettext\Exceptions\UndefinedDomainException */ public function testTranslations() { /** @var \Xinax\LaravelGettext\Session\SessionHandler|\Mockery\MockInterface $session */ $session = m::mock('Xinax\\LaravelGettext\\Session\\SessionHandler'); $session->shouldReceive('get')->andReturn('es_AR'); $session->shouldReceive('set'); /** @var \Xinax\LaravelGettext\Adapters\LaravelAdapter|\Mockery\MockInterface $adapter */ $adapter = m::mock('Xinax\\LaravelGettext\\Adapters\\LaravelAdapter'); $adapter->shouldReceive('setLocale'); $adapter->shouldReceive('getApplicationPath')->andReturn(dirname(__FILE__)); $config = $this->configManager->get(); // Static traslation files $config->setTranslationsPath("translations"); $gettext = new Gettext($config, $session, $adapter, $this->fileSystem); $laravelGettext = new LaravelGettext($gettext); $laravelGettext->setLocale("es_AR"); $this->assertSame("Cadena general con echo de php", _("general string with php echo")); $laravelGettext->setDomain("backend"); $this->assertSame("backend", $laravelGettext->getDomain()); $this->assertSame("Cadena en el backend con echo de php", _("Backend string with php echo")); $laravelGettext->setDomain("frontend"); $this->assertSame("frontend", $laravelGettext->getDomain()); $this->assertSame("Cadena de controlador", _("Controller string")); $this->assertSame("Cadena de frontend con echo de php", _("Frontend string with php echo")); $laravelGettext->setLocale("en_US"); $this->assertSame("Frontend string with php echo", _("Frontend string with php echo")); // Expected exception $laravelGettext->setDomain("wrong-domain"); }
/** * Test getLocale() method. */ public function testGetLocale() { $this->assertEquals('en_US', $this->laravelGettext->getLocale()); }