Skip to content

Commit

Permalink
Merge pull request #1940 from alissn/TypoFix
Browse files Browse the repository at this point in the history
fix function name
  • Loading branch information
dcblogdev authored Sep 13, 2024
2 parents 2ae1381 + 35873cd commit f183d64
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@
*/
'migrations' => true,

/*
|--------------------------------------------------------------------------
| Translations
|--------------------------------------------------------------------------
|
| This option for register lang file automatically.
|
*/
'translations' => false,

],

/*
Expand Down
29 changes: 29 additions & 0 deletions src/LaravelModulesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace Nwidart\Modules;

use Composer\InstalledVersions;
use Illuminate\Contracts\Translation\Translator as TranslatorContract;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Event;
use Illuminate\Translation\Translator;
use Nwidart\Modules\Constants\ModuleEvent;
use Nwidart\Modules\Contracts\RepositoryInterface;
use Nwidart\Modules\Exceptions\InvalidActivatorClass;
Expand Down Expand Up @@ -51,6 +53,7 @@ public function register()
$this->registerProviders();

$this->registerMigrations();
$this->registerTranslations();

$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'modules');
}
Expand Down Expand Up @@ -116,6 +119,32 @@ protected function registerMigrations(): void
});
}

protected function registerTranslations(): void
{
if (! $this->app['config']->get('modules.auto-discover.translations', true)) {
return;
}
$this->callAfterResolving('translator', function (TranslatorContract $translator) {
if (! $translator instanceof Translator) {
return;
}

$path = implode(DIRECTORY_SEPARATOR, [
$this->app['config']->get('modules.paths.modules'),
'*',
'lang',
]);

collect(glob($path, GLOB_ONLYDIR))
->each(function (string $path) use ($translator) {
preg_match('/\/([^\/]+)\/lang/', $path, $matches);
$translator->addNamespace(strtolower($matches[1]), $path);
$translator->addJsonPath($path);
});
});
}


private function registerEvents(): void
{
Event::listen(
Expand Down

0 comments on commit f183d64

Please sign in to comment.