-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathLocale.php
47 lines (38 loc) · 912 Bytes
/
Locale.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace App\Localization;
use Exception;
class Locale
{
protected $locales = [
'en' => 'English',
'es' => 'Español',
'pt_pt' => 'Português',
'sv' => 'Svenska',
'de' => 'Deutsch',
'da' => 'Dansk',
'cs' => 'Čeština',
'id' => 'Bahasa',
'fr' => 'French',
'pl' => 'Polski',
];
public function all()
{
return $this->locales;
}
public function slugs()
{
asort($this->locales);
return array_keys($this->locales);
}
public function isValid($locale)
{
return array_key_exists($locale, $this->locales);
}
public function languageForLocale(string $locale)
{
if (! $this->isValid($locale)) {
throw new Exception("Cannot resolve language for locale: {$locale}");
}
return $this->locales[$locale];
}
}