2017 © Pedro Peláez
 

library localechooser

Locale chooser based on common browser headers

image

arosemena/localechooser

Locale chooser based on common browser headers

  • Tuesday, February 24, 2015
  • by arosemena
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Locale Chooser for PHP

This is a simple class to detect the locale that the user preffers., (*1)

Installation

The easiest way to install this is through composer, inside your composer.json require block add, (*2)

"arosemena/localechooser": "1.0.1"

and then do composer update, otherwise you could grab the class itself and autoload it with the method of your choosing., (*3)

Usage

You will need an instance of the LocaleChooser class, the constructor takes 3 parameters, first an array of the available language, ['en', 'es', 'fr'] for example, the second parameter is a string of the default language in case nothing can be matched, the third parameter is the name of the cookie that contains the language that overrides all the normal priority., (*4)

    $chooser = new Arosemena\LanguageChooser\LanguageChooser(['en', 'es'], 'en', 'language');

After the class has been instanciated do $chooser->obtain() to get the appropiate locale., (*5)

Examples

    $chooser = new Arosemena\LanguageChooser\LanguageChooser(['en', 'es', 'fr'], 'es', 'language');
    // if the browser says that the user prefers french (fr)
    $chooser->obtain(); // returns 'fr'
    // if the browser says that the user prefers german (de)
    $chooser->obtain(); // returns 'es' because it is the default language and german isn't supported
    // if the browser says that the user prefers spanish (es) and sends a cookie named language with the value 'fr'
    $chooser->obtain(); // returns 'fr' because the cookie overrides the browser preferred language

How does it work?

The class will read the $_SERVER['HTTP_ACCEPT_LANGUAGE'] variable which is a header sent by most modern browsers and it will be parsed and evaluated against the available languages to determine the most appropiate one., (*6)

The Versions

24/02 2015

dev-master

9999999-dev https://github.com/arosemena/localechooser

Locale chooser based on common browser headers

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

language localchooser

23/02 2015

1.0.1

1.0.1.0 https://github.com/arosemena/localechooser

Locale chooser based on common browser headers

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

language localchooser

23/02 2015

1.0.0

1.0.0.0 https://github.com/arosemena/localechooser

Locale chooser based on common browser headers

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

language localchooser