PHP code example of mfn / phpstan-lost-in-translation
1. Go to this page and download the library: Download mfn/phpstan-lost-in-translation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mfn / phpstan-lost-in-translation example snippets
$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);
}
/* has a replacement that doesn't exist in the translation key */
__('exists in all locales', ['foo' => 'bar', 'bar' => 'bat'], 'en');
/* has multiple replacement variants */
__(':foo :FOO', ['foo' => 'bar'], 'en');
trans_choice('{0} There are none|{1} There is one|[2] There are :count', 3, [], 'en');
bladehtml
@lang('blade at directive')
{{ __('blade double underscore') }}
{{ __('exists in all locales') }}
{{ __('only in ja') }}
@php
// these may slation\Translator::class)->get('via app function with class');
@endphp
console
$ phpstan analyse --configuration=e2e/phpstan-e2e.neon --no-progress -v e2e/src/invalid-choice.php
------ ------------------------------------------------------------------------------------------------------------------
Line invalid-choice.php
------ ------------------------------------------------------------------------------------------------------------------
3 Translation choice does not cover all possible cases for number of type: 3
🪪 lostInTranslation.invalidChoice.missingCase
💡 Locale: "en", Key: "{0} There are none|{1} There is one|[2] There are :count", Value: "{0} There are none|{1}
There is one|[2] There are :count"
------ ------------------------------------------------------------------------------------------------------------------
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.