Digging Deeper

Translations

Translate or reword every message that the package sends to clients, from the English 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 conflict messages. The package ships these lines in English only, and answers in the locale of the request.

409 Conflict
{
  "message": "The record was changed by another request.",
  "conflicts": [{"reason": "version", "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, the version conflict and the sync conflicterrors.unauthorized: This action is unauthorized.
__('rest::errors.version_conflict'); // The record was changed by another request.
  • 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.

Translating the messages

Publish the files to lang/vendor/rest:

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

Then translate the lines in a folder per locale, such as lang/vendor/rest/de, with the same files and keys as lang/vendor/rest/en:

lang/vendor/rest/de/errors.php
return [
    'version_conflict' => 'Der Datensatz wurde von einer anderen Anfrage geändert.',
    // ...
];
__('rest::errors.version_conflict', locale: 'de'); // Der Datensatz wurde von einer anderen Anfrage geändert.
  • The published lines replace the lines of the package, key by key. A key that a locale leaves out falls back to app.fallback_locale.
  • A request in a locale without lines gets the English line when app.fallback_locale is en, and otherwise the key itself, such as rest::validation.utf8.
  • Keep lang/vendor/rest/en only for the English lines that you reword. A copy of every English line would keep the wording of the version that you published, and hide the rewordings of later versions.
  • A new release can add keys: the upgrade guide lists them, so that you add them to each locale.

Rewording a message

Edit the line in lang/vendor/rest/en, and delete the other lines of that file, so that the package keeps the wording of the lines you did not change:

lang/vendor/rest/en/errors.php
return [
    'unauthorized' => 'You cannot do this.',
];
A line of a JSON translation file that matches an English text of the package, such as "This action is unauthorized.", does not apply to the messages of the package. Move it to the published rest files.