Made it possible to override translations via theme system
This commit is contained in:
parent
1366fc45ce
commit
4763b899b6
|
@ -96,7 +96,6 @@ return [
|
||||||
Illuminate\Redis\RedisServiceProvider::class,
|
Illuminate\Redis\RedisServiceProvider::class,
|
||||||
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
|
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
|
||||||
Illuminate\Session\SessionServiceProvider::class,
|
Illuminate\Session\SessionServiceProvider::class,
|
||||||
Illuminate\Translation\TranslationServiceProvider::class,
|
|
||||||
Illuminate\Validation\ValidationServiceProvider::class,
|
Illuminate\Validation\ValidationServiceProvider::class,
|
||||||
Illuminate\View\ViewServiceProvider::class,
|
Illuminate\View\ViewServiceProvider::class,
|
||||||
Illuminate\Notifications\NotificationServiceProvider::class,
|
Illuminate\Notifications\NotificationServiceProvider::class,
|
||||||
|
@ -107,9 +106,9 @@ return [
|
||||||
Barryvdh\DomPDF\ServiceProvider::class,
|
Barryvdh\DomPDF\ServiceProvider::class,
|
||||||
Barryvdh\Snappy\ServiceProvider::class,
|
Barryvdh\Snappy\ServiceProvider::class,
|
||||||
|
|
||||||
|
|
||||||
// BookStack replacement service providers (Extends Laravel)
|
// BookStack replacement service providers (Extends Laravel)
|
||||||
BookStack\Providers\PaginationServiceProvider::class,
|
BookStack\Providers\PaginationServiceProvider::class,
|
||||||
|
BookStack\Providers\TranslationServiceProvider::class,
|
||||||
|
|
||||||
// BookStack custom service providers
|
// BookStack custom service providers
|
||||||
BookStack\Providers\AuthServiceProvider::class,
|
BookStack\Providers\AuthServiceProvider::class,
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php namespace BookStack\Providers;
|
||||||
|
|
||||||
|
use BookStack\Translation\FileLoader;
|
||||||
|
use Illuminate\Translation\TranslationServiceProvider as BaseProvider;
|
||||||
|
|
||||||
|
class TranslationServiceProvider extends BaseProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the translation line loader.
|
||||||
|
* Overrides the default register action from Laravel so a custom loader can be used.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function registerLoader()
|
||||||
|
{
|
||||||
|
$this->app->singleton('translation.loader', function ($app) {
|
||||||
|
return new FileLoader($app['files'], $app['path.lang']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php namespace BookStack\Translation;
|
||||||
|
|
||||||
|
use Illuminate\Translation\FileLoader as BaseLoader;
|
||||||
|
|
||||||
|
class FileLoader extends BaseLoader
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Load the messages for the given locale.
|
||||||
|
* Extends Laravel's translation FileLoader to look in multiple directories
|
||||||
|
* so that we can load in translation overrides from the theme file if wanted.
|
||||||
|
* @param string $locale
|
||||||
|
* @param string $group
|
||||||
|
* @param string|null $namespace
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function load($locale, $group, $namespace = null)
|
||||||
|
{
|
||||||
|
if ($group === '*' && $namespace === '*') {
|
||||||
|
return $this->loadJsonPaths($locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($namespace) || $namespace === '*') {
|
||||||
|
$themeTranslations = $this->loadPath(theme_path('lang'), $locale, $group);
|
||||||
|
$originalTranslations = $this->loadPath($this->path, $locale, $group);
|
||||||
|
return array_merge($originalTranslations, $themeTranslations);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->loadNamespaced($locale, $group, $namespace);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue