mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2025-12-14 12:06:46 +00:00
✨ Add storage configuration, localization updates, and feed generation
- Added `publicDisk` configuration to `filesystems.php`. - Expanded locale translations in `es.json` and `de.json`. - Implemented RSS, Atom, and JSON feed views. - Added `feed.php` configuration for feed generation. - Introduced `ImageController` for image handling. - Updated application routing to include `api.php`.
This commit is contained in:
103
app/Http/Controllers/Api/LanguageController.php
Normal file
103
app/Http/Controllers/Api/LanguageController.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use JoeDixon\Translation\Language;
|
||||
use JoeDixon\Translation\Translation;
|
||||
|
||||
class LanguageController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$array = Language::query()
|
||||
->select('id', 'name', 'language')
|
||||
->orderBy('name')
|
||||
->when(
|
||||
$request->search,
|
||||
fn(Builder $query)
|
||||
=> $query
|
||||
->where('name', 'ilike', "%{$request->search}%")
|
||||
->orWhere('language', 'ilike', "%{$request->search}%"),
|
||||
)
|
||||
->when(
|
||||
$request->exists('selected'),
|
||||
fn(Builder $query) => $query->whereIn('language', $request->input('selected', [])),
|
||||
fn(Builder $query) => $query->limit(10),
|
||||
)
|
||||
->get()
|
||||
->map(function ($language) {
|
||||
$language->translatedCount = Translation::query()
|
||||
->where('language_id', $language['id'])
|
||||
->whereNotNull('value')
|
||||
->where('value', '<>', '')
|
||||
->count();
|
||||
$language->toTranslate = Translation::query()
|
||||
->where('language_id', $language['id'])
|
||||
->count();
|
||||
|
||||
return $language;
|
||||
})
|
||||
->toArray();
|
||||
foreach ($array as $key => $item) {
|
||||
$translated = $item['translatedCount'] > 0 ? $item['translatedCount'] : 1;
|
||||
$itemToTranslate = $item['toTranslate'] > 0 ? $item['toTranslate'] : 1;
|
||||
|
||||
$array[$key]['name'] = empty($item['name']) ? $item['language'] : $item['name'];
|
||||
$array[$key]['description'] = $item['language'] === 'en'
|
||||
? '100% translated'
|
||||
: round($translated / $itemToTranslate * 100).'% translated';
|
||||
}
|
||||
|
||||
return response()->json($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param $language
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Language $language)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $language
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Language $language)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param $language
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Language $language)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user