|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Laravel MultiLang package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Longman\LaravelMultiLang; |
|
12
|
|
|
|
|
13
|
|
|
use Blade; |
|
14
|
|
|
use Illuminate\Routing\Events\RouteMatched; |
|
15
|
|
|
use Illuminate\Support\ServiceProvider; |
|
16
|
|
|
use Longman\LaravelMultiLang\Console\ExportCommand; |
|
17
|
|
|
use Longman\LaravelMultiLang\Console\ImportCommand; |
|
18
|
|
|
use Longman\LaravelMultiLang\Console\MigrationCommand; |
|
19
|
|
|
use Longman\LaravelMultiLang\Console\TextsCommand; |
|
20
|
|
|
|
|
21
|
|
|
class MultiLangServiceProvider extends ServiceProvider |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Indicates if loading of the provider is deferred. |
|
25
|
|
|
* |
|
26
|
|
|
* @var bool |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $defer = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Bootstrap any application services. |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
42 |
|
public function boot() |
|
36
|
|
|
{ |
|
37
|
|
|
// Publish config files |
|
38
|
42 |
|
$this->publishes( |
|
39
|
|
|
[ |
|
40
|
42 |
|
__DIR__ . '/../config/config.php' => config_path('multilang.php'), |
|
41
|
42 |
|
__DIR__ . '/../views' => base_path('resources/views/vendor/multilang'), |
|
42
|
|
|
] |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
// Append the country settings |
|
46
|
42 |
|
$this->mergeConfigFrom( |
|
47
|
42 |
|
__DIR__ . '/../config/config.php', |
|
48
|
42 |
|
'multilang' |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
// Register blade directives |
|
52
|
|
|
Blade::directive('t', function ($expression) { |
|
53
|
|
|
return "<?php echo e(t({$expression})); ?>"; |
|
54
|
42 |
|
}); |
|
55
|
|
|
|
|
56
|
|
|
$this->app['events']->listen(RouteMatched::class, function () { |
|
57
|
|
|
$scope = $this->app['config']->get('app.scope'); |
|
58
|
|
|
if ($scope && $scope != 'global') { |
|
59
|
|
|
$this->app['multilang']->setScope($scope); |
|
60
|
|
|
} |
|
61
|
|
|
$this->app['multilang']->setLocale($this->app->getLocale()); |
|
62
|
42 |
|
}); |
|
63
|
|
|
|
|
64
|
42 |
|
$this->loadViewsFrom(__DIR__ . '/../views', 'multilang'); |
|
65
|
42 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Register any application services. |
|
69
|
|
|
* |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
42 |
|
public function register() |
|
73
|
|
|
{ |
|
74
|
42 |
|
$configPath = __DIR__ . '/../config/config.php'; |
|
75
|
42 |
|
$this->mergeConfigFrom($configPath, 'debugbar'); |
|
76
|
|
|
|
|
77
|
|
|
$this->app->singleton('multilang', function ($app) { |
|
78
|
3 |
|
$environment = $app->environment(); |
|
79
|
3 |
|
$config = $app['config']->get('multilang'); |
|
80
|
|
|
|
|
81
|
3 |
|
$multilang = new \Longman\LaravelMultiLang\MultiLang( |
|
82
|
3 |
|
$environment, |
|
83
|
3 |
|
$config, |
|
84
|
3 |
|
$app['cache'], |
|
85
|
3 |
|
$app['db'] |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
3 |
|
if ($multilang->autoSaveIsAllowed()) { |
|
89
|
|
|
$app->terminating(function () use ($multilang) { |
|
90
|
|
|
$scope = $this->app['config']->get('app.scope'); |
|
91
|
|
|
if ($scope && $scope != 'global') { |
|
92
|
|
|
$multilang->setScope($scope); |
|
93
|
|
|
} |
|
94
|
|
|
return $multilang->saveTexts(); |
|
95
|
|
|
}); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
3 |
|
return $multilang; |
|
99
|
42 |
|
}); |
|
100
|
|
|
|
|
101
|
42 |
|
$this->app->alias('multilang', 'Longman\LaravelMultiLang\MultiLang'); |
|
102
|
|
|
|
|
103
|
42 |
|
$this->app->singleton( |
|
104
|
42 |
|
'command.multilang.migration', |
|
105
|
|
|
function () { |
|
106
|
5 |
|
return new MigrationCommand(); |
|
107
|
42 |
|
} |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
42 |
|
$this->app->singleton( |
|
111
|
42 |
|
'command.multilang.texts', |
|
112
|
|
|
function () { |
|
113
|
5 |
|
return new TextsCommand(); |
|
114
|
42 |
|
} |
|
115
|
|
|
); |
|
116
|
|
|
|
|
117
|
42 |
|
$this->app->singleton( |
|
118
|
42 |
|
'command.multilang.import', |
|
119
|
|
|
function () { |
|
120
|
5 |
|
return new ImportCommand(); |
|
121
|
42 |
|
} |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
42 |
|
$this->app->singleton( |
|
125
|
42 |
|
'command.multilang.export', |
|
126
|
42 |
|
function () { |
|
127
|
5 |
|
return new ExportCommand(); |
|
128
|
42 |
|
} |
|
129
|
|
|
); |
|
130
|
|
|
|
|
131
|
42 |
|
$this->commands( |
|
132
|
|
|
[ |
|
133
|
42 |
|
'command.multilang.migration', |
|
134
|
|
|
'command.multilang.texts', |
|
135
|
|
|
'command.multilang.import', |
|
136
|
|
|
'command.multilang.export', |
|
137
|
|
|
] |
|
138
|
|
|
); |
|
139
|
42 |
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Get the services provided by the provider. |
|
143
|
|
|
* |
|
144
|
|
|
* @return array |
|
145
|
|
|
*/ |
|
146
|
3 |
|
public function provides() |
|
147
|
|
|
{ |
|
148
|
|
|
return [ |
|
149
|
3 |
|
'multilang', |
|
150
|
|
|
'command.multilang.migration', |
|
151
|
|
|
'command.multilang.texts', |
|
152
|
|
|
'command.multilang.import', |
|
153
|
|
|
'command.multilang.export', |
|
154
|
|
|
'Longman\LaravelMultiLang\MultiLang', |
|
155
|
|
|
]; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|