diff --git a/app/Http/Controllers/Api/Common/Translations.php b/app/Http/Controllers/Api/Common/Translations.php new file mode 100644 index 000000000..172de67f7 --- /dev/null +++ b/app/Http/Controllers/Api/Common/Translations.php @@ -0,0 +1,74 @@ +json([ + 'success' => true, + 'error' => false, + 'message' => 'Get file translation', + 'data' => trans($file), + ]); + } + + /** + * Display the specified resource. + * + * @param string $locale + * @return \Dingo\Api\Http\Response + */ + public function all($locale) + { + App::setLocale($locale); + + $translations = []; + + $filesystem = app(Filesystem::class); + + $path = base_path('resources/lang/' . $locale); + + foreach ($filesystem->glob("{$path}/*") as $file_system) { + $file = str_replace('.php', '', basename($file_system)); + + $translations[$file] = trans($file); + } + + $modules = Module::enabled()->get(); + + foreach ($modules as $module) { + $path = base_path('modules/' . Str::studly($module->alias) . '/Resources/lang/' . $locale); + + foreach ($filesystem->glob("{$path}/*") as $file_system) { + $file = str_replace('.php', '', basename($file_system)); + + $translations[$module->alias . '::' . $file] = trans($file); + } + } + + return response()->json([ + 'success' => true, + 'error' => false, + 'message' => 'Get all translation', + 'data' => $translations, + ]); + } +} diff --git a/routes/api.php b/routes/api.php index 8b60666d4..f7ee9a081 100644 --- a/routes/api.php +++ b/routes/api.php @@ -49,6 +49,10 @@ $api->version('v3', ['middleware' => ['api']], function($api) { // Reports $api->resource('reports', 'Common\Reports'); + // Translations + $api->get('translations/{locale}/all', 'Common\Translations@all')->name('.translations.all'); + $api->get('translations/{locale}/{file}', 'Common\Translations@file')->name('.translations.file'); + // Settings $api->get('categories/{category}/enable', 'Settings\Categories@enable')->name('.categories.enable'); $api->get('categories/{category}/disable', 'Settings\Categories@disable')->name('.categories.disable');