Elgg  Version master
Locale.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\I18n;
4 
6 
13 final class Locale {
14 
20  private function __construct(private string $locale) {
21  }
22 
26  public function __toString() {
27  return $this->locale;
28  }
29 
39  public static function parse(string $locale): Locale {
40  if (!preg_match('~^[a-z0-9_]{2,20}$~', $locale)) {
41  throw new InvalidLocaleException("Unrecognized locale: {$locale}");
42  }
43 
44  return new Locale($locale);
45  }
46 }
Indicated an invalid Locale was given.
Language class to ensure only valid languages are used.
Definition: Locale.php:13
static parse(string $locale)
Create a language, asserting that the language code is valid.
Definition: Locale.php:39