2017 © Pedro Peláez
 

library phplocale

PHPLocale: Get available locale based on HTTP "Accept-Language" header

image

rocketip/phplocale

PHPLocale: Get available locale based on HTTP "Accept-Language" header

  • Sunday, July 10, 2016
  • by ChoiZ
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHPLocale

StyleCI Status Build Status Software License, (*1)

PHPLocale: Get available locale based on HTTP "Accept-Language" header, (*2)

Composer

composer require rocketip/phplocale

Methods

getLanguage

<?php
use PHPLocale\HttpAcceptLanguage;

// Force HTTP_ACCEPT_LANGUAGE with values: fr-BE,fr;q=0.8,en-us;q=0.5,en;q=0.4,es;q=0.3
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr-BE,fr;q=0.8,en-us;q=0.5,en;q=0.4,es;q=0.3';

$acceptLanguages = new HttpAcceptLanguage();
echo $acceptLanguages->getLanguage();

The above example will output:, (*3)

fr-BE

getLanguages

<?php
use PHPLocale\HttpAcceptLanguage;

// Force HTTP_ACCEPT_LANGUAGE with values: fr-BE,fr;q=0.8,en-us;q=0.5,en;q=0.4,es;q=0.3
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr-BE,fr;q=0.8,en-us;q=0.5,en;q=0.4,es;q=0.3';

$acceptLanguages = new HttpAcceptLanguage();
print_r($acceptLanguages->getLanguages());

The above example will output:, (*4)

Array
(
    [0] => fr-BE
    [1] => fr
    [2] => en-US
    [3] => en
    [4] => es
)

getRawLanguages

<?php
use PHPLocale\HttpAcceptLanguage;

// Force HTTP_ACCEPT_LANGUAGE with values: fr-BE,fr;q=0.8,en-us;q=0.5,en;q=0.4,es;q=0.3
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr-BE,fr;q=0.8,en-us;q=0.5,en;q=0.4,es;q=0.3';

$acceptLanguages = new HttpAcceptLanguage();
print_r($acceptLanguages->getRawLanguages());

The above example will output:, (*5)

Array
(
    [0] => Array
        (
            [ISO639-1] => fr
            [ISO3166-1] => BE
            [RFC1766] => fr-BE
            [q] => 1
        )

    [1] => Array
        (
            [ISO639-1] => fr
            [q] => 0.8
        )

    [2] => Array
        (
            [ISO639-1] => en
            [ISO3166-1] => US
            [RFC1766] => en-US
            [q] => 0.5
        )

    [3] => Array
        (
            [ISO639-1] => en
            [q] => 0.4
        )

    [4] => Array
        (
            [ISO639-1] => es
            [q] => 0.3
        )

)

Requirements

PHP 5 (>= 5.4.0), (*6)

Coding Style

PHPLocale follows the PSR-2 coding standard and the PSR-4 autoloading standard., (*7)

PHPDoc

Below is an example of a valid PHPLocale documentation block. Note that the @param attribute is followed by two spaces, the argument type, two more spaces, and finally the variable name:, (*8)

/**
 * Parse a language and return language like: 'fr' or 'fr-BE'.
 *
 * @param  array  $language
 *
 * @return string
 */
public function parseLanguage($language)
{
    //
}

StyleCI

If your code style isn't perfect, don't worry! StyleCI will automatically merge any style fixes into the PHPLocale repository after any pull requests are merged. This allows us to focus on the content of the contribution and not the code style., (*9)

Contributing

Thank you for considering contributing to PHPLocale * To report an issue or a feature request use: GitHub Issues. * To make a Pull Request: check if the same pull request exist, fork this project, create a new branch for each issue or feature., (*10)

License

PHPLocale is open-sourced software licensed under the MIT license., (*11)

The Versions

10/07 2016

dev-master

9999999-dev http://www.github.com/RocketIP/PHPLocale

PHPLocale: Get available locale based on HTTP "Accept-Language" header

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

locale class secure