has('set_locale') && isset($locales[$request->input('set_locale')])) { $_SESSION['locale'] = $request->input('set_locale'); } elseif (!isset($_SESSION['locale'])) { $_SESSION['locale'] = config('default_locale'); } gettext_locale(); bindtextdomain('default', realpath(__DIR__ . '/../../locale')); bind_textdomain_codeset('default', 'UTF-8'); textdomain('default'); } /** * Swich gettext locale. * * @param string $locale */ function gettext_locale($locale = null) { if ($locale == null) { $locale = $_SESSION['locale']; } putenv('LC_ALL=' . $locale); setlocale(LC_ALL, $locale); } /** * Renders language selection. * * @return array */ function make_langselect() { $url = $_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') > 0 ? '&' : '?') . 'set_locale='; $items = []; foreach (config('locales') as $locale => $name) { $items[] = toolbar_item_link( htmlspecialchars($url) . $locale, '', '' . $name . ' ' . $name ); } return $items; }