mirror of
https://github.com/flarum/framework.git
synced 2024-11-27 19:13:37 +08:00
Load only translations for enabled extensions from language packs (#2020)
fix #1837 Co-authored-by: Daniel Klabbers <daniel+git@klabbers.email>
This commit is contained in:
parent
b9fb92d49a
commit
ee7a4627d8
|
@ -11,6 +11,7 @@ namespace Flarum\Extend;
|
|||
|
||||
use DirectoryIterator;
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Locale\LocaleManager;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use InvalidArgumentException;
|
||||
|
@ -18,6 +19,11 @@ use RuntimeException;
|
|||
|
||||
class LanguagePack implements ExtenderInterface, LifecycleInterface
|
||||
{
|
||||
private const CORE_LOCALE_FILES = [
|
||||
'core',
|
||||
'validation',
|
||||
];
|
||||
|
||||
private $path;
|
||||
|
||||
/**
|
||||
|
@ -49,13 +55,13 @@ class LanguagePack implements ExtenderInterface, LifecycleInterface
|
|||
|
||||
$container->resolving(
|
||||
LocaleManager::class,
|
||||
function (LocaleManager $locales) use ($extension, $locale, $title) {
|
||||
$this->registerLocale($locales, $extension, $locale, $title);
|
||||
function (LocaleManager $locales) use ($extension, $locale, $title, $container) {
|
||||
$this->registerLocale($container, $locales, $extension, $locale, $title);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private function registerLocale(LocaleManager $locales, Extension $extension, $locale, $title)
|
||||
private function registerLocale(Container $container, LocaleManager $locales, Extension $extension, $locale, $title)
|
||||
{
|
||||
$locales->addLocale($locale, $title);
|
||||
|
||||
|
@ -75,8 +81,17 @@ class LanguagePack implements ExtenderInterface, LifecycleInterface
|
|||
$locales->addCssFile($locale, $file);
|
||||
}
|
||||
|
||||
/** @var ExtensionManager $extensions */
|
||||
$extensions = $container->make(ExtensionManager::class);
|
||||
|
||||
foreach (new DirectoryIterator($directory) as $file) {
|
||||
if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
|
||||
$slug = $file->getBasename(".{$file->getExtension()}");
|
||||
|
||||
if (
|
||||
$file->isFile()
|
||||
&& in_array($file->getExtension(), ['yml', 'yaml'], true)
|
||||
&& (in_array($slug, self::CORE_LOCALE_FILES, true) || $extensions->isEnabled($slug))
|
||||
) {
|
||||
$locales->addTranslations($locale, $file->getPathname());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user