Skip to content

Commit ef127be

Browse files
committed
재번역을 위해서 기존파일 모두 삭제하는 기능 추가
1 parent 828fdf9 commit ef127be

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
namespace OPGG\LaravelEssentialsEntry\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\File;
7+
use Illuminate\Support\Facades\Config;
8+
9+
class CleanLanguageFilesCommand extends Command
10+
{
11+
/**
12+
* 명령어 시그니처
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'lang:clean';
17+
18+
/**
19+
* 명령어 설명
20+
*
21+
* @var string
22+
*/
23+
protected $description = '기본 언어를 제외한 모든 언어 파일 삭제';
24+
25+
/**
26+
* 명령어 실행
27+
*
28+
* @return int
29+
*/
30+
public function handle()
31+
{
32+
// 기본 언어 가져오기
33+
$defaultLang = Config::get('essentials-entry.language.default');
34+
35+
// 환경 변수에서 직접 가져오는 경우 처리
36+
if (empty($defaultLang)) {
37+
$defaultLang = env('APP_LOCALE', 'en');
38+
}
39+
40+
$this->info("기본 언어: {$defaultLang}");
41+
42+
// 언어 디렉토리 경로
43+
$langPath = base_path('lang');
44+
45+
// 언어 디렉토리가 없으면 생성
46+
if (!File::exists($langPath)) {
47+
$this->warn("언어 디렉토리({$langPath})가 존재하지 않습니다.");
48+
return 0;
49+
}
50+
51+
// 모든 언어 디렉토리 가져오기
52+
$langDirs = File::directories($langPath);
53+
54+
if (empty($langDirs)) {
55+
$this->info("언어 디렉토리가 비어있습니다.");
56+
return 0;
57+
}
58+
59+
$deletedFiles = 0;
60+
61+
foreach ($langDirs as $langDir) {
62+
$langCode = basename($langDir);
63+
64+
// 기본 언어인 경우 건너뛰기
65+
if ($langCode === $defaultLang) {
66+
$this->info("기본 언어({$langCode}) 디렉토리 유지");
67+
continue;
68+
}
69+
70+
// 해당 언어 디렉토리의 모든 PHP 파일 가져오기
71+
$langFiles = File::glob("{$langDir}/*.php");
72+
73+
if (empty($langFiles)) {
74+
$this->info("{$langCode} 디렉토리에 PHP 파일이 없음");
75+
continue;
76+
}
77+
78+
// 해당 언어의 PHP 파일 삭제
79+
foreach ($langFiles as $file) {
80+
File::delete($file);
81+
$deletedFiles++;
82+
$this->line("삭제됨: {$file}");
83+
}
84+
85+
$this->info("{$langCode} 디렉토리의 모든 PHP 파일 삭제 완료");
86+
}
87+
88+
$this->info("{$deletedFiles}개 파일 삭제 완료");
89+
90+
return 0;
91+
}
92+
}

src/LaravelEssentialsEntryServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Facades\App;
88
use Illuminate\Support\Facades\Config;
99
use Illuminate\Support\Facades\Route;
10+
use OPGG\LaravelEssentialsEntry\Console\Commands\CleanLanguageFilesCommand;
1011
use OPGG\LaravelEssentialsEntry\Console\Commands\GenerateRobots;
1112
use OPGG\LaravelEssentialsEntry\Console\Commands\GenerateSitemap;
1213
use OPGG\LaravelEssentialsEntry\Http\Controllers\FaviconController;
@@ -76,6 +77,7 @@ public function boot(): void
7677
// 명령어 등록
7778
if ($this->app->runningInConsole()) {
7879
$this->commands([
80+
CleanLanguageFilesCommand::class,
7981
GenerateSitemap::class,
8082
GenerateRobots::class,
8183
]);

0 commit comments

Comments
 (0)