https://github.com/stevegrunwell/lost-in-translation
Uncover missing translations and localization strings in Laravel applications.
https://github.com/stevegrunwell/lost-in-translation
laravel laravel-package localization translation
Last synced: about 2 months ago
JSON representation
Uncover missing translations and localization strings in Laravel applications.
- Host: GitHub
- URL: https://github.com/stevegrunwell/lost-in-translation
- Owner: stevegrunwell
- License: mit
- Created: 2017-10-15T23:55:37.000Z (over 7 years ago)
- Default Branch: develop
- Last Pushed: 2022-09-14T08:58:09.000Z (over 2 years ago)
- Last Synced: 2024-10-13T08:43:20.344Z (7 months ago)
- Topics: laravel, laravel-package, localization, translation
- Language: PHP
- Homepage: https://stevegrunwell.com/blog/find-missing-laravel-translations/
- Size: 98.6 KB
- Stars: 36
- Watchers: 5
- Forks: 8
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Lost in Translation
[](https://travis-ci.org/stevegrunwell/lost-in-translation)
[](https://coveralls.io/github/stevegrunwell/lost-in-translation?branch=develop)Lost in Translation is designed to help developers locate instances of [localization strings within a Laravel application](https://laravel.com/docs/5.5/localization) that haven't been provided translations.
## Installation
Lost in Translation can be installed into your Laravel project via Composer:
```sh
$ composer require stevegrunwell/lost-in-translation
```By default, this will replace the default `TranslationServiceProvider` class with a sub-class that adds additional logic when a translation isn't found. To resume default behavior (even in a production environment), see [the "Configuration" section below](#configuration).
## Configuration
By default, Lost in Translation will catch missing translations in two ways:
1. In environments where `APP_DEBUG` is true, a `LostInTranslation\MissingTranslationException` will be found if the application attempts to load a translation that hasn't been defined.
2. Missing translations will be written to `storage/logs/lost-in-translation.log`.Either of these can be disabled via the package's configuration, making Lost in Translation safe to use in production. These values can be set using the following environment variables:
- TRANS_LOG_MISSING
- Determines whether or not missing translations should be logged. Default is "true".
- TRANS_ERROR_ON_MISSING
- Should
MissingTranslationException
exceptions be thrown when a translation is missing? Default is "false".
To override package configuration, run the following to copy the configuration to your app's `config/` directory:
```sh
$ php artisan vendor:publish --provider="LostInTranslation\Providers\TranslationServiceProvider"
```
This will create a new file in `config/lostintranslation.php`, where default values for your application can be set.
## Extending
When a missing translation is found, the a `LostInTranslation\MissingTranslationFound` event will be dispatched. This event makes it easy to do something (send an email, open a GitHub issue, etc.)when a missing translation is encountered.
First, create a new event listener in your application; in this example, we're using `app/Listeners/NotifyOfMissingTranslation.php`:
```php
[
'App\Listeners\NotifyOfMissingTranslation',
],
];
```
For more on event listeners, [please see the Laravel Events documentation](https://laravel.com/docs/5.5/events).