Hosmel Quintana/
Introduction
Installation
Configuration
Basic usage
Discovering Messages
Sample Data
Previewing Messages
Checks
Test Emails and Exports
Advanced usage
Registering Messages
Locales and Translations
Checking Messages in CI
Security
View on GitHub

Locales and Translations

Preview a message in another locale and find the translations it is missing.

Each message renders in one locale, and the Message check reports the translation keys and placeholders that locale is missing. The locale menu renders the message in another locale, and the check command renders it in all of them.

Set the locale of a message

With Auto selected in the locale menu, the preview picks the locale the way Laravel does when it sends the message:

  • A mailable renders in the locale set with its locale() method, otherwise in the application locale.
  • A notification renders in the locale set with its locale() method, then in the notifiable's preferredLocale() when the notifiable implements HasLocalePreference, then in the application locale.

To preview a message in the locale your application sends it in, set that locale in its sample data:

php
->withMessage(fn (): self => new self(Order::factory()->make())->locale('es'))

Switch locales in the preview

The locale menu in the toolbar lists the application locale, the fallback locale, and every locale in the lang directory, whether it is a folder or a JSON file. Package translations in lang/vendor add no locales. The menu appears when the list has more than one locale.

Choosing a locale other than Auto overrides the message's own locale and stays selected while you move between messages. Test emails and downloads use the selected locale too.

Missing translations

A missing translation is a key the rendered locale does not define, so the message shows the fallback locale's text or the key itself. The check counts keys used through __(), trans(), trans_choice(), and @lang while the message renders, including:

  • File keys, such as orders.subject, even when the fallback locale defines them.
  • JSON strings, such as Regards, in Laravel's notification template.
  • Namespaced package keys, such as courier::messages.title.

In the fallback locale, JSON strings are their own source text, so only file and namespaced keys that resolve nowhere are reported.

Select a key in the Message check to highlight the text the email shows for it.

The Message check open on a missing Spanish translation, with the English text the message falls back to highlighted in the email

Missing replacements

A missing replacement is a placeholder a translation kept as text because no value was passed for it. With 'greeting' => 'Hi :name, here is what is new this week.' in lang/en/newsletter.php, __('newsletter.greeting') reports :name, and __('newsletter.greeting', ['name' => $user->name]) does not. Placeholders that trans_choice() fills with the count are not reported.

Check every locale

The preview checks the locale you are viewing. To check every message in every locale, run the check command with --all-locales:

bash
php artisan message-preview:check --all-locales

It renders in the same locales the menu lists. See checking messages in CI for the other options.

Registering MessagesChecking Messages in CI