| @@ 9-71 (lines=63) @@ | ||
| 6 | use RafaHernandez\LaravelIntl\Concerns\WithLocales; |
|
| 7 | use RafaHernandez\LaravelIntl\Contracts\Intl; |
|
| 8 | ||
| 9 | class Country extends Intl |
|
| 10 | { |
|
| 11 | use WithLocales; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * Loaded localized country data. |
|
| 15 | * |
|
| 16 | * @var array |
|
| 17 | */ |
|
| 18 | protected $data; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Get a localized record by key. |
|
| 22 | * |
|
| 23 | * @param string $key |
|
| 24 | * @return string |
|
| 25 | */ |
|
| 26 | public function get($key) |
|
| 27 | { |
|
| 28 | return Arr::get($this->all(), $key); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Alias of get(). |
|
| 33 | * |
|
| 34 | * @param string $key |
|
| 35 | * @return string |
|
| 36 | */ |
|
| 37 | public function name($key) |
|
| 38 | { |
|
| 39 | return $this->get($key); |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Get all localized records. |
|
| 44 | * |
|
| 45 | * @return array |
|
| 46 | */ |
|
| 47 | public function all() |
|
| 48 | { |
|
| 49 | $default = $this->data($this->getLocale()); |
|
| 50 | $fallback = $this->data($this->getFallbackLocale()); |
|
| 51 | ||
| 52 | return $default + $fallback; |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Get the data for the given locale. |
|
| 57 | * |
|
| 58 | * @param string $locale |
|
| 59 | * @return array |
|
| 60 | */ |
|
| 61 | protected function data($locale) |
|
| 62 | { |
|
| 63 | if (! isset($this->data[$locale])) { |
|
| 64 | $path = base_path('vendor/umpirsky/country-list/data/'.$locale.'/country.php'); |
|
| 65 | ||
| 66 | $this->data[$locale] = is_file($path) ? require $path : []; |
|
| 67 | } |
|
| 68 | ||
| 69 | return $this->data[$locale]; |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||
| @@ 9-71 (lines=63) @@ | ||
| 6 | use RafaHernandez\LaravelIntl\Concerns\WithLocales; |
|
| 7 | use RafaHernandez\LaravelIntl\Contracts\Intl; |
|
| 8 | ||
| 9 | class Language extends Intl |
|
| 10 | { |
|
| 11 | use WithLocales; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * Loaded localized country data. |
|
| 15 | * |
|
| 16 | * @var array |
|
| 17 | */ |
|
| 18 | protected $data; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Get a localized record by key. |
|
| 22 | * |
|
| 23 | * @param string $key |
|
| 24 | * @return mixed |
|
| 25 | */ |
|
| 26 | public function get($key) |
|
| 27 | { |
|
| 28 | return Arr::get($this->all(), $key); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Alias of get(). |
|
| 33 | * |
|
| 34 | * @param string $key |
|
| 35 | * @return string |
|
| 36 | */ |
|
| 37 | public function name($key) |
|
| 38 | { |
|
| 39 | return $this->get($key); |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Get all localized records. |
|
| 44 | * |
|
| 45 | * @return array |
|
| 46 | */ |
|
| 47 | public function all() |
|
| 48 | { |
|
| 49 | $default = $this->data($this->getLocale()); |
|
| 50 | $fallback = $this->data($this->getFallbackLocale()); |
|
| 51 | ||
| 52 | return $default + $fallback; |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Load the data for the given locale. |
|
| 57 | * |
|
| 58 | * @param string $locale |
|
| 59 | * @return array |
|
| 60 | */ |
|
| 61 | protected function data($locale) |
|
| 62 | { |
|
| 63 | if (! isset($this->data[$locale])) { |
|
| 64 | $path = base_path('vendor/umpirsky/locale-list/data/'.$locale.'/locales.php'); |
|
| 65 | ||
| 66 | $this->data[$locale] = is_file($path) ? require $path : []; |
|
| 67 | } |
|
| 68 | ||
| 69 | return $this->data[$locale]; |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||