[Python] Strategy for implementing multilingual support in the API

Discussão em 'Python' iniciado por Stack, Maio 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm facing a problem where I need to restructure all my API return messages to support multiple languages. My frontend is written in Svelte and already has i18n implemented. Now it's time to update the API, which currently returns messages only in English. My goal is to return API messages dynamically based on the user's language. I'm using falcon-async as the backend, so there isn't a global request object available. This makes it difficult to implement efficient inline i18n, since I would need to pass the language parameter to every function or class starting from the entry point. I'm looking for a solution that is flexible and doesn't reduce code quality. I considered returning message codes ("You have successfully signed in" > "USER_SIGN_IN_OK") and translating them on the frontend, but I'm not sure if that's the best approach.

    Please keep in mind that my code can raise HTTP errors deep in nested functions, so passing the lang parameter from the entry point isn't solution.

    My question is: What's your approach to making an API multilingual in a situation like mine?

    Continue reading...

Compartilhe esta Página