Instead of having registerTranslations method on provider stub; I think it might be much better if we use
$this->loadTranslationsFrom(__DIR__ .'/../$PATH_LANG$', '$LOWER_NAME$')
as Laravel supports overriding package language files. https://laravel.com/docs/5.5/localization#overriding-package-language-files
What do you think about it?
This is already the case https://github.com/nWidart/laravel-modules/blob/master/src/Commands/stubs/scaffold/provider.stub#L81
I mean instead of having
$langPath = resource_path('lang/modules/$LOWER_NAME$');
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, '$LOWER_NAME$');
} else {
$this->loadTranslationsFrom(__DIR__ .'/../$PATH_LANG$', '$LOWER_NAME$');
}
just $this->loadTranslationsFrom($langPath, '$LOWER_NAME$'); seems enough for anyone as Laravel automatically looks for lang/vendor/modulename as it's said on documentation.
`Some packages may ship with their own language files. Instead of changing the package's core files to tweak these lines, you may override them by placing files in the resources/lang/vendor/{package}/{locale} directory.
So, for example, if you need to override the English translation strings in messages.php for a package named skyrim/hearthfire, you should place a language file at: resources/lang/vendor/hearthfire/en/messages.php. Within this file, you should only define the translation strings you wish to override. Any translation strings you don't override will still be loaded from the package's original language files.`
Briefly we're referring 'lang/modules/modulename' unnecessarily because it's already set as a fallback to lang/vendor/modulename by Laravel with the loadTranslationsFrom method.
Oh I see what you mean, will check it out, thanks!
Hi Nico,
Maybe helps, i added in service provider the following lines in order to add json language package from module.
if (is_dir($langPath)) {
$this->loadJsonTranslationsFrom($langPath, 'lang');
} else {
$this->loadJsonTranslationsFrom(__DIR__ .'/../Resources/lang', 'lang');
}
Most helpful comment
Hi Nico,
Maybe helps, i added in service provider the following lines in order to add json language package from module.