diff --git a/src/Generators/LangFileGenerator.php b/src/Generators/LangFileGenerator.php index b0aae58..0d9a882 100644 --- a/src/Generators/LangFileGenerator.php +++ b/src/Generators/LangFileGenerator.php @@ -68,6 +68,15 @@ class LangFileGenerator extends BaseGenerator */ private function getAppLangFileContent() { - return $this->files->get(__DIR__.'/../stubs/lang-app.stub'); + $locale = config('app.locale'); + + $langStubPath = __DIR__.'/../stubs/lang-app-'.$locale.'.stub'; + + if ($this->files->exists($langStubPath)) { + $stub = $this->files->get($langStubPath); + } else { + $stub = $this->files->get(__DIR__.'/../stubs/lang-app.stub'); + } + return $stub; } } diff --git a/src/stubs/lang-app-id.stub b/src/stubs/lang-app-id.stub new file mode 100644 index 0000000..83781db --- /dev/null +++ b/src/stubs/lang-app-id.stub @@ -0,0 +1,18 @@ + '#', + 'total' => 'Total', + 'action' => 'Pilihan', + 'show_detail_title' => 'Lihat detail :type :name', + + // Actions + 'show' => 'Lihat Detail', + 'edit' => 'Edit', + 'delete' => 'Hapus', + 'cancel' => 'Batal', + 'reset' => 'Reset', + 'delete_confirm' => 'Anda yakin akan menghapus?', + 'delete_confirm_button' => 'YA, hapus saja!', +]; diff --git a/src/stubs/lang-app.stub b/src/stubs/lang-app.stub index c966d78..a8eaf4b 100644 --- a/src/stubs/lang-app.stub +++ b/src/stubs/lang-app.stub @@ -5,8 +5,6 @@ return [ 'table_no' => '#', 'total' => 'Total', 'action' => 'Actions', - 'views' => 'Views', - 'downloads' => 'Downloads', 'show_detail_title' => 'View :name :type detail', // Actions diff --git a/tests/Generators/LangGeneratorTest.php b/tests/Generators/LangGeneratorTest.php index eba6629..9bc7f2f 100644 --- a/tests/Generators/LangGeneratorTest.php +++ b/tests/Generators/LangGeneratorTest.php @@ -109,8 +109,6 @@ return [ 'table_no' => '#', 'total' => 'Total', 'action' => 'Actions', - 'views' => 'Views', - 'downloads' => 'Downloads', 'show_detail_title' => 'View :name :type detail', // Actions @@ -125,4 +123,36 @@ return [ "; $this->assertEquals($appLangContent, file_get_contents($langPath)); } + + /** @test */ + public function it_creates_app_lang_based_on_locale_if_stub_exists() + { + config(['app.locale' => 'id']); + $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); + + $locale = config('app.locale'); + $langPath = resource_path('lang/'.$locale.'/app.php'); + + $this->assertFileExists($langPath); + $appLangContent = " '#', + 'total' => 'Total', + 'action' => 'Pilihan', + 'show_detail_title' => 'Lihat detail :type :name', + + // Actions + 'show' => 'Lihat Detail', + 'edit' => 'Edit', + 'delete' => 'Hapus', + 'cancel' => 'Batal', + 'reset' => 'Reset', + 'delete_confirm' => 'Anda yakin akan menghapus?', + 'delete_confirm_button' => 'YA, hapus saja!', +]; +"; + $this->assertEquals($appLangContent, file_get_contents($langPath)); + } }