zoutapps/laravel-lang-vendornamespace

Use a translation namespace vor mutliple translation files.

v1.0.4 2020-11-10 17:01 UTC

This package is auto-updated.

Last update: 2024-10-11 02:11:56 UTC


README

Latest Version on Packagist Total Downloads Build Status StyleCI

This package is aimed at package developers that want multiple packages translations under one namespace.

It's currently not easily possible to gather all your packages translations under one namespace which can bloat up the calls to your translations as well as your resources/lang/vendor folder when publishing the files.

For example having packages:

  • zoutapps/awesome-package
  • zoutapps/nice-package

you can't register the translations to be able to use them like this:

trans('zoutapps::awesome-package')
trans('zoutapps::nice-package')

With this package you now can do this!

Installation

Via Composer

$ composer require zoutapps/laravel-lang-vendornamespace

Usage

In your PackageServiceProvider instead of using
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', '<your-vendor-name>')
make a call to
VendorNamespace::loadTranslationsFrom(__DIR__ . '/../resources/lang', '<your-vendor-name>') in your boot() method.

Publishing your translations is the same as before:

$this->publishes([
    __DIR__ . '/../resources/lang' => resource_path('lang/vendor/<your-vendor-name>'),
], 'lang');

What it does

All paths you register will be added to your translation namespace.
For this to happen, we wait for the application booted callback and:

  • we will create a folder for every namespace
  • symlink all your provided translation files in the namespace folder
  • add the generated folder to the laravel TranslationLoader namespaces

Development

While your app environment is set to local we will always regenerate the links. When your app is in any other environment, we will check for existence of the lang folder inside our package and only generate the links if it is not present.

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email oliver.ziegler@zoutapps.de instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.