I'm currently building a Vue.js SPA with laravel as the backend where I need to support multiple locales. I'm therefore considering using Lang.js alongside laravel's built-in translation system to manage the translated stings. I basicly want to manage all the strings in laravel (on the backend) but let the frontend handle the actual translations, to allow the user to switch language dynamicly with a language switcher ui component.
The problem is that when I submit a form request that is validated on the server, the error messages are already translated, thus not allowing the frontend to pick a language on-the-fly.
My question is how I can disable the translation for a given request (preferably using headers in middleware or something like that) and instead print the raw translation keys
For example for the given validation
<?php
function store() {
request()->validate(['test' => 'required'])
}
The server returns
{
'message': 'The given data was invalid',
'errors': {
'test': 'The test field is required'
}
}
instead of
{
'message': 'The given data was invalid',
'errors': {
'test': 'validation.required',
}
}
I have already tried using \App::setLocale('somethinginvalidandrandom')
which should technically try to translate the key into a language that doesn't exist, thus returning the key, but besides feeling wrong and hacky, this approach won't work if I want to preserve the fallback language funcionality of laravel, since the key would be found in the fallback language (en).