2017-05-30 21:30:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Locale class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube;
|
|
|
|
|
|
|
|
use Teto\HTTP\AcceptLanguage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class used to represent locales.
|
|
|
|
*/
|
|
|
|
class Locale
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Locale language.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $language;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Locale region.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $region;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Locale constructor.
|
|
|
|
*
|
|
|
|
* @param string $locale ISO 15897 code
|
|
|
|
*/
|
|
|
|
public function __construct($locale)
|
|
|
|
{
|
|
|
|
$parse = AcceptLanguage::parse($locale);
|
|
|
|
$this->language = $parse[1]['language'];
|
|
|
|
$this->region = $parse[1]['region'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the locale to a string.
|
|
|
|
*
|
|
|
|
* @return string ISO 15897 code
|
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->getIso15897();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the full name of the locale.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-05-30 21:49:49 +00:00
|
|
|
public function getFullName()
|
2017-05-30 21:30:21 +00:00
|
|
|
{
|
2017-05-30 21:49:49 +00:00
|
|
|
return \Locale::getDisplayName($this->getIso15897(), $this->getIso15897());
|
2017-05-30 21:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ISO 15897 code.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getIso15897()
|
|
|
|
{
|
|
|
|
return $this->language.'_'.$this->region;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the BCP 47 code.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getBcp47()
|
|
|
|
{
|
|
|
|
return $this->language.'-'.$this->region;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ISO 3166 code.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getIso3166()
|
|
|
|
{
|
|
|
|
return strtolower($this->region);
|
|
|
|
}
|
2017-05-31 14:26:00 +00:00
|
|
|
|
2017-10-02 18:29:09 +00:00
|
|
|
/**
|
|
|
|
* Get country information from locale.
|
|
|
|
*
|
2017-10-26 09:03:30 +00:00
|
|
|
* @return \Rinvex\Country\Country|array
|
2017-10-02 18:29:09 +00:00
|
|
|
*/
|
2017-05-31 14:26:00 +00:00
|
|
|
public function getCountry()
|
|
|
|
{
|
|
|
|
return country($this->getIso3166());
|
|
|
|
}
|
2017-05-30 21:30:21 +00:00
|
|
|
}
|