PHPackages                             jbboehr/phpstan-lost-in-translation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. jbboehr/phpstan-lost-in-translation

ActivePhpstan-extension[Localization &amp; i18n](/categories/localization)

jbboehr/phpstan-lost-in-translation
===================================

Helps find missing translation strings in Laravel applications

261[3 issues](https://github.com/jbboehr/phpstan-lost-in-translation/issues)PHPCI passing

Since May 26Pushed 11mo agoCompare

[ Source](https://github.com/jbboehr/phpstan-lost-in-translation)[ Packagist](https://packagist.org/packages/jbboehr/phpstan-lost-in-translation)[ RSS](/packages/jbboehr-phpstan-lost-in-translation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (6)Used By (0)

phpstan-lost-in-translation
===========================

[](#phpstan-lost-in-translation)

[![ci](https://github.com/jbboehr/phpstan-lost-in-translation/actions/workflows/ci.yml/badge.svg)](https://github.com/jbboehr/phpstan-lost-in-translation/actions/workflows/ci.yml)[![License: AGPL v3+](https://camo.githubusercontent.com/804e16c3c0324eb20ab6b4366bc15bd122b822188a5d6d0d057675a242577b73/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4147504c5f76332532622d626c75652e737667)](https://www.gnu.org/licenses/agpl-3.0)[![stability-experimental](https://camo.githubusercontent.com/0daa00e91aa931aeb2d321edc5a2ce6fe8fb4037fc35c084c4a01cde1621ac98/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73746162696c6974792d6578706572696d656e74616c2d6f72616e67652e737667)](https://camo.githubusercontent.com/0daa00e91aa931aeb2d321edc5a2ce6fe8fb4037fc35c084c4a01cde1621ac98/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73746162696c6974792d6578706572696d656e74616c2d6f72616e67652e737667)

Installation
------------

[](#installation)

To use this extension, require it in [Composer](https://getcomposer.org/):

```
composer require --dev jbboehr/phpstan-lost-in-translation
```

If you also install [phpstan/extension-installer](https://github.com/phpstan/extension-installer) then you're all set!

### Manual installation

[](#manual-installation)

If you don't want to use `phpstan/extension-installer`, include `extension.neon` in your project's PHPStan config:

```
includes:
    - vendor/jbboehr/phpstan-lost-in-translation/extension.neon
```

Additional Requirements
-----------------------

[](#additional-requirements)

While there is not a strict requirement, this extension will likely not function as expected without the following extra PHPStan extensions installed:

- [Larastan](https://github.com/larastan/larastan) - Provides better type inference for Laravel applications
- [Bladestan](https://github.com/bladestan/bladestan) - Provides static analysis of Blade templates

Features
--------

[](#features)

### Type inference

[](#type-inference)

Note that for most of the features below, we can only analyze any potential constant strings in the type of the variable passed into the translation function. **This takes advantage of [PHPStan](https://phpstan.org/)'s type inference.**For example, these should all be able to be analyzed correctly:

```
$key = 'foo';
__($key);

foreach (['foo', 'bar'] as $key) {
    __($key);
}

// this one seems to not be working atm :shrug:
/** @return "foo"|"bar" */
function getKey(): string {}
__(getKey());

const KEY = 'foo';
__(KEY);

/** @var array{foo: mixed, bar: mixed} $map */
foreach ($map as $key => $value) {
    __($key);
}
```

### Find missing translation strings

[](#find-missing-translation-strings)

Your application's source files will be scanned for calls to the Laravel translator and checked for undefined translation strings. **Enabled by default.**

```
parameters:
    lostInTranslation:
        missingTranslationStrings: true
```

```
