ARTICLE AD BOX
Laravel has localization for authorization, validation and other types of messages. validation.php returns an array which contains error messages for validation rules. It can also have custom validation messages and custom attribute names. Attributes are interpolated in validation error messages.
// lang/en/validation.php return [ 'alpha' => 'The :attribute field must only contain letters.', // ... 'attributes' => [], ]; // lang/rs/validation.php return [ "alpha" => "Polje :attribute mora sadržati samo slova.", // ... "attributes" => [ "first_name" => "Ime", "last_name" => "Prezime", // ... ], ];When an validation error happens, Laravel automatically embeds attribute names inside the messages, so I get error messages such as Polje Ime mora sadržati samo slova, where Ime is attributes.first_name .
I recreated the file in JSON for i18next in my Express project (`lang/rs/validation.js`):
{ "alpha": "Polje {{attr}} mora sadržati samo slova.", "attributes": { "firstName": "Ime", "lastName": "Prezime", } }Can I make i18next to automatically embed attribute names error messages in this schema like in Laravel or do I have to add them explicitly?
export const registerSchema = checkSchema({ // ... firstName: { // ... Automatically? isAlpha: { errorMessage: i18next.t("alpha") } }, lastName: { // ... Explicitly? isAlpha: { errorMessage: i18next.t("alpha", { attr: "Prezime" }) } }, });