mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 17:57:04 +08:00
Update APIs
This commit is contained in:
parent
c98444382d
commit
4be8270c1a
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Flarum\Events\RegisterLocales;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Flarum\Core\Application;
|
use Flarum\Event\ConfigureLocales;
|
||||||
|
|
||||||
return function (Application $app) {
|
return function (Dispatcher $events) {
|
||||||
$app->make('events')->listen(RegisterLocales::class, function(RegisterLocales $event) {
|
$events->listen(ConfigureLocales::class, function(ConfigureLocales $event) {
|
||||||
$name = $title = basename(__DIR__);
|
$name = $title = basename(__DIR__);
|
||||||
|
|
||||||
if (file_exists($manifest = __DIR__.'/composer.json')) {
|
if (file_exists($manifest = __DIR__.'/composer.json')) {
|
||||||
|
@ -22,23 +22,23 @@ return function (Application $app) {
|
||||||
throw new RuntimeException("Language pack $name must define \"extra.flarum-locale.code\" in composer.json.");
|
throw new RuntimeException("Language pack $name must define \"extra.flarum-locale.code\" in composer.json.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$event->addLocale($locale, $title);
|
$event->locales->addLocale($locale, $title);
|
||||||
|
|
||||||
if (! is_dir($localeDir = __DIR__.'/locale')) {
|
if (! is_dir($localeDir = __DIR__.'/locale')) {
|
||||||
throw new RuntimeException("Language pack $name must have a \"locale\" subdirectory.");
|
throw new RuntimeException("Language pack $name must have a \"locale\" subdirectory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists($file = $localeDir.'/config.js')) {
|
if (file_exists($file = $localeDir.'/config.js')) {
|
||||||
$event->addJsFile($locale, $file);
|
$event->locales->addJsFile($locale, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists($file = $localeDir.'/config.php')) {
|
if (file_exists($file = $localeDir.'/config.php')) {
|
||||||
$event->addConfig($locale, $file);
|
$event->locales->addConfig($locale, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (new DirectoryIterator($localeDir) as $file) {
|
foreach (new DirectoryIterator($localeDir) as $file) {
|
||||||
if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
|
if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
|
||||||
$event->addTranslations($locale, $file->getPathname());
|
$event->locales->addTranslations($locale, $file->getPathname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user