Localize Errors

default discord avatar
zakoullast year
5

Hi there!



Is there any possibility to localize the errors given back from the REST API?



I tried with "locale=de" for example, but it still gives me back the error in english.



If that's not possible, is there any possibility to get error codes instead of only messages so that I can create a way of translating it in the front-end?

  • discord user avatar
    jesschow
    last year

    Hi @zakoul do you still need help here?

  • default discord avatar
    zakoullast year

    Hi @jesschow thank you for your answer! Yes, help would still be appreciated 🙂

  • discord user avatar
    jmikrut
    last year

    this is possible and the errors are already localized i believe



    @dribbens will have detail there on how this is accomplished, but regardless, we need to get this in the docs

  • discord user avatar
    dribbens
    last year

    Yeah, the trick to remember here is that the

    locale

    param refers to the language for the data being accessed, but instead you're looking to set the

    Accept-Language

    on the request header. That is used to tell Payload what language the user expects.


    More info on the header can be found here:

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language


    You can see it in action from the admin UI if you change your language in the account settings and then look at your http requests Headers:



    I hope this helps you @zakoul

    image.png
  • default discord avatar
    zelenovsky12 months ago

    thank you @dribbens you solved my problem too. It would be nice to get this in the doc

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.