|
8 | 8 | use Hexadog\ThemesManager\Events\ThemeEnabling;
|
9 | 9 | use Hexadog\ThemesManager\Traits\ComposerTrait;
|
10 | 10 | use Illuminate\Container\Container;
|
| 11 | +use Illuminate\Contracts\Translation\Translator; |
11 | 12 | use Illuminate\Filesystem\Filesystem;
|
12 | 13 | use Illuminate\Mail\Markdown;
|
13 | 14 | use Illuminate\Support\Facades\Config;
|
@@ -127,6 +128,29 @@ public function getViewPaths($path = ''): array
|
127 | 128 | return array_reverse($paths);
|
128 | 129 | }
|
129 | 130 |
|
| 131 | + /** |
| 132 | + * Get theme translations paths. |
| 133 | + * |
| 134 | + * @param string $path |
| 135 | + */ |
| 136 | + public function getTransaltionPaths($path = ''): array |
| 137 | + { |
| 138 | + // Build Paths array. |
| 139 | + // All paths are relative to Config::get('themes-manager.directory') |
| 140 | + $paths = []; |
| 141 | + $theme = $this; |
| 142 | + |
| 143 | + do { |
| 144 | + $translationsPath = $theme->getPath('lang' . ($path ? "/{$path}" : '')); |
| 145 | + |
| 146 | + if (File::exists($translationsPath) && !in_array($translationsPath, $paths)) { |
| 147 | + $paths[] = $translationsPath; |
| 148 | + } |
| 149 | + } while ($theme = $theme->getParent()); |
| 150 | + |
| 151 | + return array_reverse($paths); |
| 152 | + } |
| 153 | + |
130 | 154 | /**
|
131 | 155 | * Set path.
|
132 | 156 | *
|
@@ -244,6 +268,7 @@ public function enable(bool $withEvent = true, $defaultViewPaths = null, $defaul
|
244 | 268 |
|
245 | 269 | $this->setStatus(true);
|
246 | 270 | $this->registerViews($defaultViewPaths, $defaultMailViewPaths);
|
| 271 | + $this->registerTranlastions(); |
247 | 272 |
|
248 | 273 | if ($withEvent) {
|
249 | 274 | event(new ThemeEnabled($this->getName()));
|
@@ -365,6 +390,24 @@ protected function createPublicAssetsStructure()
|
365 | 390 | }
|
366 | 391 | }
|
367 | 392 |
|
| 393 | + /** |
| 394 | + * Register theme's translations. |
| 395 | + */ |
| 396 | + protected function registerTranlastions() |
| 397 | + { |
| 398 | + // Register Translation paths |
| 399 | + $paths = $this->getTransaltionPaths(); |
| 400 | + $translator = app()->make(Translator::class); |
| 401 | + |
| 402 | + $paths = array_map(function ($path) use ($translator) { |
| 403 | + $path = rtrim($path, DIRECTORY_SEPARATOR); |
| 404 | + |
| 405 | + $translator->addNamespace('theme', $path); |
| 406 | + |
| 407 | + return $path; |
| 408 | + }, $paths); |
| 409 | + } |
| 410 | + |
368 | 411 | /**
|
369 | 412 | * Register theme's views in ViewFinder.
|
370 | 413 | *
|
|
0 commit comments