2017 © Pedro Peláez
 

library lost-in-translation

Uncover missing translations and localization strings in Laravel applications

image

stevegrunwell/lost-in-translation

Uncover missing translations and localization strings in Laravel applications

  • Thursday, April 26, 2018
  • by stevegrunwell
  • Repository
  • 2 Watchers
  • 14 Stars
  • 2,952 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 5 Open issues
  • 4 Versions
  • 8 % Grown

The README.md

Lost in Translation

Build Status Coverage Status, (*1)

Lost in Translation is designed to help developers locate instances of localization strings within a Laravel application that haven't been provided translations., (*2)

Installation

Lost in Translation can be installed into your Laravel project via Composer:, (*3)

$ 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., (*4)

Configuration

By default, Lost in Translation will catch missing translations in two ways:, (*5)

  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:, (*6)

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:, (*7)

$ 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., (*8)

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., (*9)

First, create a new event listener in your application; in this example, we're using app/Listeners/NotifyOfMissingTranslation.php:, (*10)

<?php

namespace App\Listeners;

use LostInTranslation\Events\MissingTranslationFound;

class NotifyOfMissingTranslation
{
    /**
     * Handle the event.
     *
     * @param MissingTranslationFound $event
     *
     * @return void
     */
    public function handle(MissingTranslationFound $event)
    {
        // Do something with the event.
    }
}

The MissingTranslationFound event has four public properties of note:, (*11)

  1. $key - The translation key that was not found.
  2. $replacements - Any replacements that were passed to the translation call.
  3. $locale - The locale that was being used.
  4. $fallback - The fallback locale, if defined.

Then, in app/Providers/EventServiceProvider.php, add the following to register NotifyOfMissingTranslation as a callback when a MissingTranslationFound event occurs:, (*12)

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'LostInTranslation\Events\MissingTranslationFound' => [
        'App\Listeners\NotifyOfMissingTranslation',
    ],
];

For more on event listeners, please see the Laravel Events documentation., (*13)

The Versions

26/04 2018

dev-fix/monolog-use-files

dev-fix/monolog-use-files

Uncover missing translations and localization strings in Laravel applications

  Sources   Download

MIT

The Development Requires

laravel translation qa laravel package

17/10 2017

dev-master

9999999-dev

Uncover missing translations and localization strings in Laravel applications

  Sources   Download

MIT

The Development Requires

laravel translation qa laravel package

17/10 2017

dev-develop

dev-develop

Uncover missing translations and localization strings in Laravel applications

  Sources   Download

MIT

The Development Requires

laravel translation qa laravel package

17/10 2017

v1.0.0

1.0.0.0

Uncover missing translations and localization strings in Laravel applications

  Sources   Download

MIT

The Development Requires

laravel translation qa laravel package