Elgg  Version 5.1
Locale.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\I18n;
4 
6 
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  if (!preg_match('~^[a-z0-9_]{2,20}$~', $locale)) {
45  throw new InvalidLocaleException("Unrecognized locale: $locale");
46  }
47 
48  return new Locale($locale);
49  }
50 }
static parse($locale)
Create a language, asserting that the language code is valid.
Definition: Locale.php:43
Indicated an invalid Locale was given.
Language class to ensure only valid languages are used.
Definition: Locale.php:13