mirror of
https://github.com/flarum/framework.git
synced 2024-11-24 05:11:56 +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 DirectoryIterator;
|
||||||
use Flarum\Extension\Extension;
|
use Flarum\Extension\Extension;
|
||||||
|
use Flarum\Extension\ExtensionManager;
|
||||||
use Flarum\Locale\LocaleManager;
|
use Flarum\Locale\LocaleManager;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
@ -18,6 +19,11 @@ use RuntimeException;
|
||||||
|
|
||||||
class LanguagePack implements ExtenderInterface, LifecycleInterface
|
class LanguagePack implements ExtenderInterface, LifecycleInterface
|
||||||
{
|
{
|
||||||
|
private const CORE_LOCALE_FILES = [
|
||||||
|
'core',
|
||||||
|
'validation',
|
||||||
|
];
|
||||||
|
|
||||||
private $path;
|
private $path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,13 +55,13 @@ class LanguagePack implements ExtenderInterface, LifecycleInterface
|
||||||
|
|
||||||
$container->resolving(
|
$container->resolving(
|
||||||
LocaleManager::class,
|
LocaleManager::class,
|
||||||
function (LocaleManager $locales) use ($extension, $locale, $title) {
|
function (LocaleManager $locales) use ($extension, $locale, $title, $container) {
|
||||||
$this->registerLocale($locales, $extension, $locale, $title);
|
$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);
|
$locales->addLocale($locale, $title);
|
||||||
|
|
||||||
|
@ -75,8 +81,17 @@ class LanguagePack implements ExtenderInterface, LifecycleInterface
|
||||||
$locales->addCssFile($locale, $file);
|
$locales->addCssFile($locale, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var ExtensionManager $extensions */
|
||||||
|
$extensions = $container->make(ExtensionManager::class);
|
||||||
|
|
||||||
foreach (new DirectoryIterator($directory) as $file) {
|
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());
|
$locales->addTranslations($locale, $file->getPathname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user