Create two files in app/Extended (the folder must be created if doesn't exist):
ExtendedTranslationServiceProvider.php
<?php
namespace AppExtended;
use IlluminateTranslationTranslationServiceProvider;
class ExtendedTranslationServiceProvider extends TranslationServiceProvider
{
public function register()
{
$this->registerLoader();
$this->app->singleton('translator', function ($app) {
$loader = $app['translation.loader'];
$locale = $app['config']['app.locale'];
$trans = new ExtendedTranslator($loader, $locale);
$trans->setFallback($app['config']['app.fallback_locale']);
return $trans;
});
}
}
ExtendedTranslator.php
<?php
namespace AppExtended;
use IlluminateTranslationTranslator;
class ExtendedTranslator extends Translator
{
public function get($key, array $replace = [], $locale = null, $fallback = true)
{
$trans = parent::get($key, $replace, $locale, $fallback);
if(parent::get($key, [], $locale, $fallback) === $key){
return 'STRING NOT FOUND';
}
return $trans;
}
}
And add a new item in the providers
array, on app.php:
'providers' => [
...
AppExtendedExtendedTranslationServiceProvider::class,
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…