/** * 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; }
/** * Test getLocale() method. */ public function testGetLocale() { $this->assertEquals('en_US', $this->laravelGettext->getLocale()); }