42 lines
1.0 KiB
PHP
42 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Translation\Providers;
|
|
|
|
use App\Domains\Translation\Models\Translation;
|
|
use Illuminate\Contracts\Translation\Loader;
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
class DatabaseTranslationLoader implements Loader
|
|
{
|
|
public function load($locale, $group, $namespace = null): array
|
|
{
|
|
$cacheKey = "lang:{$locale}:{$group}";
|
|
|
|
$cached = Redis::hGetAll($cacheKey);
|
|
if (! empty($cached)) {
|
|
return $cached;
|
|
}
|
|
|
|
$translations = Translation::where('locale', $locale)
|
|
->where('group', $group)
|
|
->pluck('value', 'key')
|
|
->toArray();
|
|
|
|
if (! empty($translations)) {
|
|
Redis::hMSet($cacheKey, $translations);
|
|
Redis::expire($cacheKey, 3600);
|
|
}
|
|
|
|
return $translations;
|
|
}
|
|
|
|
public function addNamespace($namespace, $hint): void {}
|
|
public function addPath($path): void {}
|
|
public function addJsonPath($path): void {}
|
|
|
|
public function namespaces(): array
|
|
{
|
|
return [];
|
|
}
|
|
}
|