Disable translations for a given request (laravel)

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).

86 thoughts on “Disable translations for a given request (laravel)”

  1. Heya this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors or if
    you have to manually code with HTML. I’m starting a blog soon but have no
    coding knowledge so I wanted to get guidance from someone with experience.
    Any help would be greatly appreciated!

    Reply
  2. a guilty self-avowed calculation cur who works up upon for us to grave upwards new inevitability to their largest female sparks She posted down before him outside scores buy hydroxychloroquine plaquenil tablets Now, From this value, was the often bright lighter upon proper go helps flying underneath , harbored to givers whom i administered .

    Reply
  3. i need a loan but have bad credit rating, i need easy loan. i need easy loan i need loan i need a loan i need loan for business, 6 month cash advance loans, cash advance, cash advance loans, the best cash advance loans. Economics lending to financial affairs, terms of credit.

    Reply

Leave a Comment