Added Translations api endpoint
This commit is contained in:
parent
b360c71979
commit
61602e32ec
74
app/Http/Controllers/Api/Common/Translations.php
Normal file
74
app/Http/Controllers/Api/Common/Translations.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Common;
|
||||
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Models\Module\Module;
|
||||
use Dingo\Api\Http\Response;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Translations extends ApiController
|
||||
{
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $file
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function file($locale, $file)
|
||||
{
|
||||
App::setLocale($locale);
|
||||
|
||||
return response()->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,
|
||||
]);
|
||||
}
|
||||
}
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user