diff --git a/src/Extend/LanguagePack.php b/src/Extend/LanguagePack.php index 13599acad..cb74d1cac 100644 --- a/src/Extend/LanguagePack.php +++ b/src/Extend/LanguagePack.php @@ -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()); } }