1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Locale; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Thinktomorrow\Locale\Parsers\RouteParser; |
7
|
|
|
use Thinktomorrow\Locale\Parsers\UrlParser; |
8
|
|
|
use Thinktomorrow\Locale\Values\Config; |
9
|
|
|
|
10
|
|
|
class LocaleServiceProvider extends ServiceProvider |
11
|
|
|
{ |
12
|
77 |
|
public function register() |
13
|
|
|
{ |
14
|
77 |
|
require_once __DIR__.'/helpers.php'; |
15
|
|
|
|
16
|
77 |
|
$this->publishes([ |
17
|
77 |
|
__DIR__.'/config/locale.php' => config_path('thinktomorrow/locale.php'), |
18
|
|
|
]); |
19
|
|
|
|
20
|
77 |
|
$this->mergeConfigFrom( |
21
|
77 |
|
__DIR__.'/config/locale.php', 'thinktomorrow.locale' |
22
|
|
|
); |
23
|
|
|
|
24
|
77 |
|
$config = Config::from($this->getConfigValues()); |
25
|
|
|
|
26
|
77 |
|
$this->app->singleton(Detect::class, function ($app) use($config) { |
27
|
|
|
return new Detect($app['request'], $config); |
28
|
77 |
|
}); |
29
|
|
|
|
30
|
77 |
|
$this->app->singleton(UrlParser::class, function ($app) { |
31
|
70 |
|
return new UrlParser( |
32
|
70 |
|
$app['Illuminate\Contracts\Routing\UrlGenerator'] |
33
|
|
|
); |
34
|
77 |
|
}); |
35
|
|
|
|
36
|
77 |
|
$this->app->singleton(RouteParser::class, function ($app) { |
37
|
70 |
|
return new RouteParser( |
38
|
70 |
|
$app['Thinktomorrow\Locale\Parsers\UrlParser'], |
39
|
70 |
|
$app['translator'] |
40
|
|
|
); |
41
|
77 |
|
}); |
42
|
|
|
|
43
|
77 |
|
$this->app->singleton(LocaleUrl::class, function ($app) use($config) { |
44
|
|
|
return new LocaleUrl( |
45
|
|
|
$app['Thinktomorrow\Locale\Detect'], |
46
|
|
|
$app['Thinktomorrow\Locale\Parsers\UrlParser'], |
47
|
|
|
$app['Thinktomorrow\Locale\Parsers\RouteParser'], |
48
|
|
|
$config |
49
|
|
|
); |
50
|
77 |
|
}); |
51
|
|
|
|
52
|
|
|
/* |
53
|
|
|
* Facade for getting current active scope |
54
|
|
|
*/ |
55
|
77 |
|
$this->app->singleton('tt-locale-scope', function ($app) { |
56
|
10 |
|
return $app->make(Detect::class)->detectLocale()->getScope(); |
57
|
77 |
|
}); |
58
|
77 |
|
} |
59
|
|
|
|
60
|
77 |
|
private function getConfigValues() |
61
|
|
|
{ |
62
|
77 |
|
if (file_exists(config_path('thinktomorrow/locale.php'))) { |
63
|
|
|
return require config_path('thinktomorrow/locale.php'); |
64
|
|
|
} |
65
|
|
|
|
66
|
77 |
|
return require __DIR__.'/config/locale.php'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|