nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.5k stars 954 forks source link

Auto-Register Module Language Files #1920

Closed alissn closed 1 month ago

alissn commented 1 month ago

Hi,

This Pull Request introduces a method to automatically register language files for modules. By default, this option is enabled, but it can be managed by the client based on their needs from config.

When automatic registration of translations is enabled, the following section can be removed from all modules: 🚀

public function registerTranslations(): void
{
    $langPath = resource_path('lang/modules/'.$this->moduleNameLower);

    if (is_dir($langPath)) {
        $this->loadTranslationsFrom($langPath, $this->moduleNameLower);
        $this->loadJsonTranslationsFrom($langPath);
    } else {
        $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
        $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
    }
}

After this pull request is merged, I will create another pull request to update the stubs for service providers and perform some cleanup to prevent the registration of duplicate processes.

Please note that this update does not support language files located at resource_path('lang/modules/'.$this->moduleNameLower). Clients will need to register this path manually if needed.

Please review and provide your feedback.

alissn commented 1 month ago

Hi @dcblogdev,

It looks like the changes from this PR are not present in the master version of the package. Please review and, if necessary, merge this PR again.

You can check the relevant sections here: