| title | MissingTranslation |
|---|---|
| parent | Custom Issues |
| nav_order | 5 |
Emitted when __() or trans() references a translation key that does not exist in the application's language files.
If the translation key doesn't exist, Laravel returns the key itself as a string instead of the translated text. This silently produces untranslated output at runtime. This check catches typos and missing keys during static analysis.
// Bad -- typo in the translation key
echo __('mesages.welcome'); // MissingTranslation
// Good -- the key exists in lang/en/messages.php
echo __('messages.welcome');// Bad -- key was removed from language files
echo trans('auth.old_message'); // MissingTranslation
// Good
echo trans('auth.failed');- Check that the translation key exists in your language files (e.g.,
lang/en/messages.phporlang/en.json) - Fix any typos in the key name
- If the translation is provided by a package, use the namespaced syntax (e.g.,
__('package::file.key')) -- namespaced keys are not checked by this rule
This check is disabled by default. Enable it in your psalm.xml:
<plugins>
<pluginClass class="Psalm\LaravelPlugin\Plugin">
<findMissingTranslations value="true" />
</pluginClass>
</plugins>- Only string literal keys are checked -- dynamic or concatenated keys are skipped
- Namespaced package keys (e.g.,
pagination::pages.next) are skipped - Only
__()andtrans()are checked --trans_choice(),Lang::get(), and Blade@langdirectives are not detected - Uses Laravel's Translator to resolve keys, which respects the configured locale and fallback locale