Generating hooking into the loading of translations for VueJs

parent 895aa02b
...@@ -63,6 +63,7 @@ class EntityGenerator extends Generator ...@@ -63,6 +63,7 @@ class EntityGenerator extends Generator
$this->appendResourceRoutesToRoutesFileFor($entity); $this->appendResourceRoutesToRoutesFileFor($entity);
$this->appendPermissionsFor($entity); $this->appendPermissionsFor($entity);
$this->appendSidebarLinksFor($entity); $this->appendSidebarLinksFor($entity);
$this->appendBackendTranslations($entity);
} }
} }
...@@ -242,6 +243,18 @@ class EntityGenerator extends Generator ...@@ -242,6 +243,18 @@ class EntityGenerator extends Generator
$this->finder->put($this->getModulesPath("Events/Handlers/Register{$this->name}Sidebar.php"), $sidebarComposerContent); $this->finder->put($this->getModulesPath("Events/Handlers/Register{$this->name}Sidebar.php"), $sidebarComposerContent);
} }
/**
* @param string $entity
*/
private function appendBackendTranslations($entity)
{
$moduleProviderContent = $this->finder->get($this->getModulesPath("Providers/{$this->name}ServiceProvider.php"));
$translations = $this->getContentForStub('translations-append.stub', $entity);
$moduleProviderContent = str_replace('// append translations', $translations, $moduleProviderContent);
$this->finder->put($this->getModulesPath("Providers/{$this->name}ServiceProvider.php"), $moduleProviderContent);
}
/** /**
* Generate a filled sidebar view composer * Generate a filled sidebar view composer
* Or an empty one of no entities * Or an empty one of no entities
......
...@@ -5,6 +5,7 @@ namespace Modules\$MODULE$\Providers; ...@@ -5,6 +5,7 @@ namespace Modules\$MODULE$\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Modules\Core\Traits\CanPublishConfiguration; use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Core\Events\BuildingSidebar; use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Events\LoadingBackendTranslations;
use Modules\$MODULE$\Events\Handlers\$SIDEBAR_LISTENER_NAME$; use Modules\$MODULE$\Events\Handlers\$SIDEBAR_LISTENER_NAME$;
class $MODULE$ServiceProvider extends ServiceProvider class $MODULE$ServiceProvider extends ServiceProvider
...@@ -26,6 +27,10 @@ class $MODULE$ServiceProvider extends ServiceProvider ...@@ -26,6 +27,10 @@ class $MODULE$ServiceProvider extends ServiceProvider
{ {
$this->registerBindings(); $this->registerBindings();
$this->app['events']->listen(BuildingSidebar::class, $SIDEBAR_LISTENER_NAME$::class); $this->app['events']->listen(BuildingSidebar::class, $SIDEBAR_LISTENER_NAME$::class);
$this->app['events']->listen(LoadingBackendTranslations::class, function (LoadingBackendTranslations $event) {
// append translations
});
} }
public function boot() public function boot()
......
$event->load('$PLURAL_LOWERCASE_CLASS_NAME$', array_dot(trans('$LOWERCASE_MODULE_NAME$::$PLURAL_LOWERCASE_CLASS_NAME$')));
// append translations
...@@ -287,6 +287,11 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -287,6 +287,11 @@ class ModuleScaffoldTest extends BaseTestCase
'$this->app[\'events\']->listen(BuildingSidebar::class, ' . $sidebarEventListenerName . '::class);' '$this->app[\'events\']->listen(BuildingSidebar::class, ' . $sidebarEventListenerName . '::class);'
), 'Sidebar event handler was not present'); ), 'Sidebar event handler was not present');
$this->assertTrue(str_contains(
$file,
'$this->app[\'events\']->listen(LoadingBackendTranslations::class,'
), 'Translations registering was not present');
$this->cleanUp(); $this->cleanUp();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment