Extend translations to generate log entries for missing translations.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Translation\Translator;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -14,6 +15,12 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
if ($this->app->environment() === 'local') {
|
if ($this->app->environment() === 'local') {
|
||||||
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
|
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
|
||||||
$this->app->register(TelescopeServiceProvider::class);
|
$this->app->register(TelescopeServiceProvider::class);
|
||||||
|
|
||||||
|
$this->app->extend('translator', function (Translator $translator) {
|
||||||
|
$trans = new \App\Translator($translator->getLoader(), $translator->getLocale());
|
||||||
|
$trans->setFallback($translator->getFallback());
|
||||||
|
return $trans;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
app/Translator.php
Normal file
31
app/Translator.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Translation\Translator as BaseTranslator;
|
||||||
|
class Translator extends BaseTranslator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @param array $replace
|
||||||
|
* @param null $locale
|
||||||
|
* @param bool $fallback
|
||||||
|
*
|
||||||
|
* @return array|null|string|void
|
||||||
|
*/
|
||||||
|
public function get($key, array $replace = [], $locale = null, $fallback = true)
|
||||||
|
{
|
||||||
|
$translation = parent::get($key, $replace, $locale, $fallback);
|
||||||
|
|
||||||
|
if ($translation === $key) {
|
||||||
|
Log::warning('Language item could not be found.', [
|
||||||
|
'language' => $locale ?? config('app.locale'),
|
||||||
|
'id' => $key,
|
||||||
|
'url' => config('app.url')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $translation;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user