hyperRail
                                
                                 hyperRail copied to clipboard
                                
                                    hyperRail copied to clipboard
                            
                            
                            
                        Set user language from browser header if no cookie is available
The language selection is an additional screen between navigating to irail.be and performing a search. Selecting a language takes almost as long as taking a train, the language selection is intrusive and does not feel really user-friendly
Current situation:
- Visit irail.be for the first time, or with cleared cookies.
- Language selection is shown. The user needs to select a language before he can search for trains.
- User selects language and continues.
Proposed improvement:
- Visit irail.be for the first time, or with cleared cookies.
- Language is deducted from Accept-Language header. If Dutch or French is not found in the header, English is used as fall-back.
- User can instantly search for trains
- (optional) a notification bar is shown asking the user if he wants to change his language. This does not hinder searching for trains
When the user has already visited irail.be, the previous language is used. (This is already the case)
There's also the navigator.language(s) that can be used (https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language)
Also, we should move away from this laravel session thing. It's really awkward... We should be able to just use a cookie for this imo.
Can we fix this? I like the proposal of @bertware in each case!
https://github.com/iRail/hyperRail/blob/master/app/Http/Middleware/Language.php#L32 should be appended with $request->server('HTTP_ACCEPT_LANGUAGE'); (and then be parsed)
This functionality was implemented using locale_lookup. This means the php_intl module is required. This function was chosen as it implements the search protocol for languages and keeps the weights in mind. http://php.net/manual/en/locale.lookup.php
Note: Users can change between languages using the "Language" link on the bottom of the page. This link was already there. However, this link is always shown in the current language, meaning an Englishman looking at the site won't recognize it if it's in Dutch for some reason. Since there are only 3 languages, maybe this could be changed to "Nederlands - Francais - English". Or maybe it could be in a more visible place? (e.g. flags in the header)