Example #1
0
 /**
  * Set locale of input data
  *
  * @param string $locale Name of locale, the same format of setlocale php function
  *
  * @return Localize Current instance of that class, for chaining methods
  */
 public static function setLocale($locale)
 {
     $locales = array($locale . '.utf-8', $locale . '.UTF-8', $locale);
     $os = strtolower(php_uname('s'));
     if (strpos($os, 'windows') !== false) {
         $locales = array(Formats::$windowsLocaleMap[$locale]);
     }
     if (!setlocale(LC_ALL, $locales)) {
         throw new LocaleException("Locale {$locale} não disponível no seu sistema.");
     }
     if (!isset(Formats::$input[$locale])) {
         throw new LocaleException("Localização '{$locale}' não possuí formatação definida. Tente adicionar o formato antes de usa-lo.");
     }
     self::$currentLocale = $locale;
     return new static();
 }