Getting the locale from browser data
In order to improve the user experience on a website, it's important to display information in a format that is acceptable in the user's locale. Locale is a generic term used to indicate an area of the world. An effort in the I.T. community has been made to codify locales using a two-part designation consisting of codes for both language and country. But when a person visits your website, how do you know their locale? Probably the most useful technique involves examining the HTTP language header.
How to do it...
In order to encapsulate locale functionality, we will assume a class,
Application\I18n\Locale
. We will have this class extend an existing class,Locale
, which is part of the PHPIntl
extension.Note
I18n is a common abbreviation for Internationalization. (Count the number of letters!)
namespace Application\I18n; use Locale as PhpLocale; class Locale extends PhpLocale { const FALLBACK_LOCALE = 'en'; // some code }
To get an idea of what an incoming...