]> BookStack Code Mirror - bookstack/blob - app/Translation/FileLoader.php
Lexical: Media form improvements
[bookstack] / app / Translation / FileLoader.php
1 <?php
2
3 namespace BookStack\Translation;
4
5 use Illuminate\Translation\FileLoader as BaseLoader;
6
7 class FileLoader extends BaseLoader
8 {
9     /**
10      * Load the messages for the given locale.
11      *
12      * Extends Laravel's translation FileLoader to look in multiple directories
13      * so that we can load in translation overrides from the theme file if wanted.
14      *
15      * Note: As of using Laravel 10, this may now be redundant since Laravel's
16      * file loader supports multiple paths. This needs further testing though
17      * to confirm if Laravel works how we expect, since we specifically need
18      * the theme folder to be able to partially override core lang files.
19      *
20      * @param string      $locale
21      * @param string      $group
22      * @param string|null $namespace
23      *
24      * @return array
25      */
26     public function load($locale, $group, $namespace = null): array
27     {
28         if ($group === '*' && $namespace === '*') {
29             return $this->loadJsonPaths($locale);
30         }
31
32         if (is_null($namespace) || $namespace === '*') {
33             $themePath = theme_path('lang');
34             $themeTranslations = $themePath ? $this->loadPaths([$themePath], $locale, $group) : [];
35             $originalTranslations = $this->loadPaths($this->paths, $locale, $group);
36
37             return array_merge($originalTranslations, $themeTranslations);
38         }
39
40         return $this->loadNamespaced($locale, $group, $namespace);
41     }
42 }