|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EasyPanel\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\File; |
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
|
|
8
|
|
|
class LangManager |
|
9
|
|
|
{ |
|
10
|
|
|
public static function get() |
|
11
|
|
|
{ |
|
12
|
|
|
$files = collect(static::getFiles()); |
|
13
|
|
|
|
|
14
|
|
|
return $files->mapWithKeys(function ($file, $key){ |
|
|
|
|
|
|
15
|
|
|
preg_match('/(\w+)_panel\.json/i', $file, $m); |
|
16
|
|
|
$key = "$m[1]_panel"; |
|
17
|
|
|
$value = Str::upper($m[1]); |
|
18
|
|
|
return [$key => $value]; |
|
19
|
|
|
})->toArray(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public static function update($texts) |
|
23
|
|
|
{ |
|
24
|
|
|
foreach (static::getFiles() as $file) { |
|
25
|
|
|
$decodedFile = json_decode(File::get($file), 1); |
|
26
|
|
|
foreach ($texts as $key => $text) { |
|
27
|
|
|
if (array_key_exists($key, $decodedFile)){ |
|
28
|
|
|
unset($texts[$text]); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
$array = array_merge($decodedFile, $texts); |
|
32
|
|
|
File::put($file, json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function getFiles() |
|
37
|
|
|
{ |
|
38
|
|
|
return File::glob(resource_path('lang/*_panel.json')); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public static function getTexts($lang) |
|
42
|
|
|
{ |
|
43
|
|
|
return json_decode(static::getLang($lang), true); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function updateLanguage($lang, $texts) |
|
47
|
|
|
{ |
|
48
|
|
|
$file = static::getLang($lang); |
|
49
|
|
|
|
|
50
|
|
|
$decodedFile = json_decode($file, 1); |
|
51
|
|
|
|
|
52
|
|
|
$array = array_merge($decodedFile, $texts); |
|
53
|
|
|
|
|
54
|
|
|
File::put(static::getPath($lang), json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public static function getLang($lang) |
|
58
|
|
|
{ |
|
59
|
|
|
return File::get(static::getPath($lang)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function getPath($lang) |
|
63
|
|
|
{ |
|
64
|
|
|
return resource_path("lang/{$lang}.json"); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.