Elgg  Version 3.0
Locale.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\I18n;
4 
13 final class Locale {
14 
16  private $locale;
17 
23  private function __construct($locale) {
24  $this->locale = $locale;
25  }
26 
30  public function __toString() {
31  return $this->locale;
32  }
33 
43  public static function parse($locale) {
44  // TODO(evan): Better sanitizing of locales using \Locale perhaps
45  if (!preg_match('~^[a-z0-9_]{2,20}$~', $locale)) {
46  throw new InvalidLocaleException("Unrecognized locale: $locale");
47  }
48 
49  return new Locale($locale);
50  }
51 }
static parse($locale)
Create a language, asserting that the language code is valid.
Definition: Locale.php:43
WARNING: API IN FLUX.
Definition: Locale.php:13
Indicated an invalid Locale was given.