1
|
|
|
<?php namespace Limoncello\Application\Packages\L10n; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015-2017 [email protected] |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use Limoncello\Contracts\Settings\SettingsInterface; |
20
|
|
|
use Limoncello\l10n\Messages\FileBundleEncoder; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @package Limoncello\Application |
24
|
|
|
*/ |
25
|
|
|
abstract class L10nSettings implements SettingsInterface |
26
|
|
|
{ |
27
|
|
|
/** Settings key */ |
28
|
|
|
const KEY_DEFAULT_LOCALE = 0; |
29
|
|
|
|
30
|
|
|
/** Settings key */ |
31
|
|
|
const KEY_LOCALES_FOLDER = self::KEY_DEFAULT_LOCALE + 1; |
32
|
|
|
|
33
|
|
|
/** Settings key */ |
34
|
|
|
const KEY_LOCALES_DATA = self::KEY_LOCALES_FOLDER + 1; |
35
|
|
|
|
36
|
|
|
/** Settings key */ |
37
|
|
|
const KEY_LAST = self::KEY_LOCALES_DATA; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc |
41
|
|
|
*/ |
42
|
1 |
|
final public function get(): array |
43
|
|
|
{ |
44
|
1 |
|
$defaults = $this->getSettings(); |
45
|
|
|
|
46
|
1 |
|
$defaultLocale = $defaults[static::KEY_DEFAULT_LOCALE] ?? null; |
47
|
1 |
|
assert(empty($defaultLocale) === false, "Invalid default locale `$defaultLocale`."); |
48
|
|
|
|
49
|
1 |
|
$localesFolder = $defaults[static::KEY_LOCALES_FOLDER] ?? null; |
50
|
1 |
|
assert( |
51
|
1 |
|
$localesFolder !== null && empty(glob($localesFolder)) === false, |
52
|
1 |
|
"Invalid Locales folder `$localesFolder`." |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
return $defaults + [ |
57
|
1 |
|
static::KEY_LOCALES_DATA => (new FileBundleEncoder($localesFolder))->getStorageData($defaultLocale), |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
1 |
|
protected function getSettings(): array |
65
|
|
|
{ |
66
|
|
|
return [ |
67
|
1 |
|
static::KEY_DEFAULT_LOCALE => 'en', |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|