stevegrunwell / lost-in-translation

Uncover missing translations and localization strings in Laravel applications.
https://stevegrunwell.com/blog/find-missing-laravel-translations/
MIT License
36 stars 8 forks source link

Upgrade to Laravel 5.6 #6

Open mitchellklijs opened 6 years ago

mitchellklijs commented 6 years ago

Hi,

Thanks for the great package! I've used it with much pleasure in a couple of projects.

However, when upgrading my projects to Laravel 5.6 I noticed that this package doens't play nice with it due to the new way logging works with Laravel (https://laravel.com/docs/5.6/logging). I got the following error every time a missing translation was found: Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Call to undefined method Monolog\Logger::useFiles()".

After some debugging; I found out a way to fix this. The new logging method (using Monolog) doesn't allow for changing the file "on the fly" anymore. This is not the intended use of the new logging system. Therefore, the issue originates in the Translator.php file on line 71 where the logging file location is changed (https://github.com/stevegrunwell/lost-in-translation/blob/develop/src/Translator.php#L71).

This could be fixed by changing the logMissingTranslation method to:

    protected function logMissingTranslation($key, $replace, $locale, $fallback)
    {
        if (! $this->logger) {
            $this->logger = logger()->channel('lost-in-translation')->getLogger();
        }

        $this->logger->notice('Missing translation: ' . $key, [
            'replacements' => $replace,
            'locale' => $locale ? $locale : config('app.locale'),
            'fallback' => $fallback ? config('app.fallback_locale') : '',
        ]);
    }

and adding the following to the channels array of the config/logging.php configuration file:

        'lost-in-translation' => [
            'driver' => 'single',
            'path' => storage_path('logs/lost-in-translation.log'),
            'level' => 'debug',
        ],

I started making a PR for this. When creating this PR (and modifying the README) I noticed that some of the functionality of this package can (and should?) now be handled by the new Laravel Logging. The MissingTranslationException can be added to a stack channel in the channels array of theconfig/logging.php configuration file. Furthermore, extending the logging can be make use of the new system as well. The whole Event based approach can be replaced by making use of custom Monolog Handler Channels (https://laravel.com/docs/5.6/logging#creating-monolog-handler-channels).

So I started making a small PR but quickly noticed that the whole package could be refactored, benefiting from the new logging system. With such a big change it could be very useful to discuss it first before making the changes. So I'ld like to hear what you think.

mitchellklijs commented 6 years ago

I see you've already started on this in https://github.com/stevegrunwell/lost-in-translation/pull/5. Maybe it still helps ;)

stevegrunwell commented 6 years ago

This definitely helps, and I appreciate you digging in. Things have been a bit bonkers lately, but I'm hoping to circle back around to this work soon!

nickfla1 commented 5 years ago

Any news?

RobinBastiaan commented 2 years ago

Am I correct to assume this package to be abandoned?

stevegrunwell commented 2 years ago

It's not abandoned, but definitely in need of some love — really, a full rewrite. It's still on my radar for the near-future, but this last two years has been a helluva decade 🙃