1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Support; |
4
|
|
|
|
5
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Logger; |
6
|
|
|
use Helldar\LaravelLangPublisher\Constants\Locales as LocalesList; |
7
|
|
|
use Helldar\LaravelLangPublisher\Facades\Config as ConfigFacade; |
8
|
|
|
|
9
|
|
|
final class Path |
10
|
|
|
{ |
11
|
|
|
use Logger; |
12
|
|
|
|
13
|
|
|
public function source(string $locale): string |
14
|
|
|
{ |
15
|
|
|
$this->log('Getting the path to the source files of the localization: ' . $locale); |
16
|
|
|
|
17
|
|
|
if ($this->isEnglish($locale)) { |
18
|
|
|
return ConfigFacade::basePath(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
return $this->locales($locale); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function target(string $locale, bool $is_json = false): string |
25
|
|
|
{ |
26
|
|
|
$this->log('Getting the path to the target files of the localization: ' . $locale); |
27
|
|
|
|
28
|
|
|
$path = ConfigFacade::resourcesPath(); |
29
|
|
|
|
30
|
|
|
$suffix = $is_json ? '' : '/' . $locale; |
31
|
|
|
|
32
|
|
|
return $this->clean($path) . $suffix; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function locales(string $locale = null): string |
36
|
|
|
{ |
37
|
|
|
$this->log('Getting the path to excluding English localization: ' . $locale); |
38
|
|
|
|
39
|
|
|
$path = ConfigFacade::localesPath(); |
40
|
|
|
|
41
|
|
|
return $this->clean($path) . '/' . $locale; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function filename(string $path): string |
45
|
|
|
{ |
46
|
|
|
$this->log('Getting file name without extension and path: ' . $path); |
47
|
|
|
|
48
|
|
|
$path = pathinfo($path, PATHINFO_FILENAME); |
49
|
|
|
|
50
|
|
|
return $this->clean($path); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function directory(string $path): string |
54
|
|
|
{ |
55
|
|
|
$this->log('Getting the path to a directory: ' . $path); |
56
|
|
|
|
57
|
|
|
$path = pathinfo($path, PATHINFO_DIRNAME); |
58
|
|
|
|
59
|
|
|
return $this->clean($path); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function extension(string $path): string |
63
|
|
|
{ |
64
|
|
|
$this->log('Getting file extension from path: ' . $path); |
65
|
|
|
|
66
|
|
|
$path = pathinfo($path, PATHINFO_EXTENSION); |
67
|
|
|
|
68
|
|
|
return $this->clean($path); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function clean(string $path = null): ?string |
72
|
|
|
{ |
73
|
|
|
$this->log('Clearing the path from the trailing character: ' . $path); |
74
|
|
|
|
75
|
|
|
return ! empty($path) ? rtrim($path, '\\/') : $path; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function isEnglish(string $locale): bool |
79
|
|
|
{ |
80
|
|
|
$this->log('Check if localization is English: ' . $locale); |
81
|
|
|
|
82
|
|
|
return $locale === LocalesList::ENGLISH; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|