public function compose($view) { // Application language $view->with('appLanguage', $appLanguage = app('language')); // All languages (for implementing https://support.google.com/webmasters/answer/189077) $url = parse_url(Request::url()); $domain = preg_replace('/^[a-z][a-z]\\./', '', $url['host']); $languages = Language::getAllByPriority(); foreach ($languages as &$l) { // Regenerate URL $url['host'] = $l->code . '.' . $domain; $l->url = http_build_url($url); } $view->with('allLanguages', $languages); // All languages but current one $view->with('allLanguagesButCurrent', $languages->filter(function ($l) use($appLanguage) { return $l->id != $appLanguage->id; })); }
/** * Define the secondary sections of the menu. * * @param User $user User to checked permissions against * * @return array (of Menu\Node) */ public static function makeSecondarySections(User $user) { // Section: Change application language $currentLanguage = app('language'); $allLanguages = Language::getAllByPriority(); $changeLanguage = new Node($currentLanguage); if ($allLanguages->count() > 1) { $newLanguages = new Flat(_('Change language')); foreach ($allLanguages as $l) { if ($l->id != $currentLanguage->id) { // Do not add current language $newLanguages->addChild(new Link(route('language.set', ['code' => $l->code]), $l->name)); } } $changeLanguage->addChild($newLanguages); } // Section: User panel $userPanel = new Node($user->getName()); $userPanel->addChild(new Link(route('user.options'), _('Options'))); $userPanel->addChild(new Link(route('logout'), _('Logout'), ['class' => 'button alert expanded', 'style' => 'height:auto;'])); return compact('changeLanguage', 'userPanel'); }