Digging Deeper

Translations

Translate or reword every message that the package sends to clients, with the English and French lines it ships under the rest namespace.

Every message that the package writes for a client is a translation line under the rest namespace: its validation texts, the caps of an action, the default denial and the version conflict. The package ships en and fr, and answers in the locale of the application.

app()->setLocale('fr');
409 Conflict
{
  "message": "L'élément a été modifié par une autre requête.",
  "conflicts": [{"path": "mutate.0", "key": 2, "version": "2026-03-01T10:00:00.000000Z"}]
}

The lines

FileHoldsExample
rest::validationthe validation texts of the package: totals, depths, unknown and not writable keys, include aliases, the values of withvalidation.filters_total: The :attribute field goes over the limit of :max filters in one search.
rest::actionsthe caps of an action on a searchactions.row_cap: This action can be run on at most :max resources; narrow the search.
rest::errorsthe default denial and the version conflicterrors.unauthorized: This action is unauthorized.
__('rest::errors.version_conflict'); // The record was changed by another request.
__('rest::errors.version_conflict', locale: 'fr'); // L'élément a été modifié par une autre requête.
  • The texts that Laravel's own rules give, such as The search.filters field must not have more than 100 items., stay Laravel's lines: translate them in lang/<locale>/validation.php.
  • A field is named by its path in the request, such as search.filters, unless label() or attributes() names it. See Validation.
  • Exception messages meant for developers, such as InvalidResourceException, stay in English.

Rewording a message or adding a locale

Publish the files to lang/vendor/rest:

php artisan vendor:publish --tag=rest-lang

Edit a line in lang/vendor/rest/en/errors.php, or copy the en folder to a new locale, such as lang/vendor/rest/de, and translate it. The published lines replace the lines of the package, key by key.

A line of a JSON translation file that matches an English text of the package, such as "This action is unauthorized.", no longer applies to the messages of the package. Move it to the published rest files.