|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\I18n; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider; |
|
6
|
|
|
use Nip\I18n\Translator\Backend\AbstractBackend; |
|
7
|
|
|
use Nip\I18n\Translator\Backend\File; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class MailServiceProvider |
|
11
|
|
|
* @package Nip\Mail |
|
12
|
|
|
*/ |
|
13
|
|
|
class TranslatorServiceProvider extends AbstractSignatureServiceProvider |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @inheritdoc |
|
17
|
|
|
*/ |
|
18
|
|
|
public function register() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->registerTranslator(); |
|
21
|
|
|
$this->registerLanguages(); |
|
22
|
|
|
$this->registerLoader(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Register the session manager instance. |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function registerTranslator() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->getContainer()->share('translator', Translator::class) |
|
33
|
|
|
->withArgument(AbstractBackend::class); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Register the translation line loader. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function registerLoader() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->getContainer()->share('translation.loader', function () { |
|
44
|
|
|
$backend = $this->createFileBackend(); |
|
|
|
|
|
|
45
|
|
|
return $backend; |
|
46
|
|
|
}); |
|
47
|
|
|
|
|
48
|
|
|
$this->getContainer()->alias('translation.loader', AbstractBackend::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function registerLanguages() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->getContainer()->share('translation.languages', function () { |
|
54
|
|
|
$languages = config('app.locale.enabled'); |
|
55
|
|
|
return is_array($languages) ? $languages : explode(',', $languages); |
|
56
|
|
|
}); |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function createFileBackend() |
|
61
|
|
|
{ |
|
62
|
|
|
$backend = $this->getContainer()->get(File::class); |
|
63
|
|
|
$languages = $this->getContainer()->get('translation.languages'); |
|
64
|
|
|
|
|
65
|
|
|
foreach ($languages as $lang) { |
|
66
|
|
|
$backend->addLanguage($lang, app('path.lang') . DIRECTORY_SEPARATOR . $lang); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @inheritdoc |
|
72
|
|
|
*/ |
|
73
|
|
|
public function provides() |
|
74
|
|
|
{ |
|
75
|
|
|
return ['translator', 'translator.languages', 'translation.loader']; |
|
76
|
|
|
} |
|
77
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.