coding-socks / lost-in-translation

This package helps to find missing translation strings in your Laravel blade files.
MIT License
6 stars 1 forks source link

Lost in Translation

This package helps to find missing translation strings in your Laravel blade files.

Installation

You can easily install this package using Composer, by running the following command:

composer require coding-socks/lost-in-translation --dev

Usage

You can list all missing translation for a specific location using the command below.

php artisan lost-in-translation:find {locale}

Example:

php artisan lost-in-translation:find nl

It is sometimes recommended to increase the verbosity using -v flag. In verbose mode the command will print warnings and errors to the standard output.

Publish

Publish the configuration file only:

php artisan vendor:publish --tag=lost-in-translation-config

Publish the Command class only:

php artisan vendor:publish --tag=lost-in-translation-commands

Defaults

The command considers app.locale as your applications default locale.

The command scans your lang directory for comparison with the default and target locale.

The command scans your app, and resources/views directory for translation retrieval.

The command detects the following in your blade and application files:

Help

Description:
  Find missing translation strings in your Laravel blade files

Usage:
  lost-in-translation:find [options] [--] <locale>

Arguments:
  locale                The locale to be checked

Options:
      --sorted          Sort the values before printing
      --no-progress     Do not show the progress bar
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Implementation

This implementation reads all your blade files, compiles them to PHP (illuminate/view), parses them as PHP (nikic/php-parser), and then finds the relevant nodes in the AST.

This, in my opinion, is a cleaner and less error-prone than using regular expressions.