Allow overriding translations
This commit is contained in:
parent
02ba6ed3df
commit
aa149f4f3e
16
app/Providers/TranslationServiceProvider.php
Normal file
16
app/Providers/TranslationServiceProvider.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Services\TranslationLoader;
|
||||
use Illuminate\Translation\TranslationServiceProvider as IlluminateTranslationServiceProvider;
|
||||
|
||||
class TranslationServiceProvider extends IlluminateTranslationServiceProvider
|
||||
{
|
||||
protected function registerLoader()
|
||||
{
|
||||
$this->app->singleton('translation.loader', function ($app) {
|
||||
return new TranslationLoader($app['files'], $app['path.lang']);
|
||||
});
|
||||
}
|
||||
}
|
41
app/Services/TranslationLoader.php
Normal file
41
app/Services/TranslationLoader.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Devitek\Core\Translation\YamlFileLoader;
|
||||
|
||||
class TranslationLoader extends YamlFileLoader
|
||||
{
|
||||
/**
|
||||
* Load the messages for the given locale.
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $group
|
||||
* @param string $namespace
|
||||
* @return array
|
||||
*/
|
||||
public function load($locale, $group, $namespace = null)
|
||||
{
|
||||
if (is_null($namespace) || $namespace == '*') {
|
||||
// Overrides original translations with custom ones
|
||||
return array_replace_recursive(
|
||||
$this->loadPath($this->path, $locale, $group),
|
||||
$this->loadPathOverrides($locale, $group)
|
||||
);
|
||||
}
|
||||
|
||||
return $this->loadNamespaced($locale, $group, $namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load custom messages from /resources/lang/overrides path.
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $group
|
||||
* @return array
|
||||
*/
|
||||
protected function loadPathOverrides($locale, $group)
|
||||
{
|
||||
return $this->loadPath("$this->path/overrides", $locale, $group);
|
||||
}
|
||||
}
|
@ -159,7 +159,6 @@ return [
|
||||
/**
|
||||
* Third-party libraries
|
||||
*/
|
||||
Devitek\Core\Translation\TranslationServiceProvider::class,
|
||||
Swiggles\Memcache\MemcacheServiceProvider::class,
|
||||
Yajra\Datatables\DatatablesServiceProvider::class,
|
||||
Mews\Captcha\CaptchaServiceProvider::class,
|
||||
@ -174,6 +173,7 @@ return [
|
||||
App\Providers\MemoryServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
App\Providers\ResponseMacroServiceProvider::class,
|
||||
App\Providers\TranslationServiceProvider::class,
|
||||
App\Providers\ValidatorExtendServiceProvider::class,
|
||||
|
||||
],
|
||||
|
2
resources/lang/overrides/.gitignore
vendored
Normal file
2
resources/lang/overrides/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
Loading…
Reference in New Issue
Block a user