Laravel-modules: LoadTranslationsFrom

Created on 24 Oct 2017  路  5Comments  路  Source: nWidart/laravel-modules

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?

Most helpful comment

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');
        }

All 5 comments

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');
        }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

NexxusPlexx picture NexxusPlexx  路  4Comments

pawlox picture pawlox  路  4Comments

vdjkelly picture vdjkelly  路  4Comments

invaders-xx picture invaders-xx  路  3Comments

ojasseh picture ojasseh  路  3Comments