Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move translation of some enumerations to backend #362

Closed
jpmckinney opened this issue Aug 16, 2024 · 8 comments · Fixed by #395
Closed

Move translation of some enumerations to backend #362

jpmckinney opened this issue Aug 16, 2024 · 8 comments · Fixed by #395
Assignees
Labels

Comments

@jpmckinney
Copy link
Member

jpmckinney commented Aug 16, 2024

Follow-up #342

Presently, most error messages are returned in English. A few are returned as codes, that get mapped to Spanish by the frontend. (See Frontend page in docs.)

This is unnecessary coupling. If we use gettext #357 (or even stick with Transifex), we can return good error messages in the default language (neither the frontend or backend have any language switching features) from the backend.

If i18n is implemented, we can remove the documentation, the ERROR_CODES enum, and the corresponding logic in the frontend. That said, we can add i18n without touching the frontend at all – we'd only need to touch it to remove the unnecessary logic.

@yolile
Copy link
Member

yolile commented Aug 21, 2024

As part of this, we could also create endpoints to return:

  • borrower_size
  • borrower_sector
  • document_types

So we can get rid of that unnecessary coupling as well.

@jpmckinney jpmckinney changed the title Translate more error messages Move translation of error messages and some enumerations to backend Aug 21, 2024
@jpmckinney
Copy link
Member Author

Cool. Blocked by #357 which implements gettext (I could separate it from that PR if needed).

@yolile
Copy link
Member

yolile commented Aug 21, 2024

I'm reviewing that PR now so it should be merged soon

@jpmckinney
Copy link
Member Author

@yolile For your comment, you can also update the part of frontend.rst that lists enums for:

Credere frontend's src/constants/index.ts constants should match app.models enumerations.

@jpmckinney
Copy link
Member Author

jpmckinney commented Aug 21, 2024

With #382 you can generate a mapping from database name to translated text with e.g.:

from app import models
from app.i18n import _

{name: _(name) for name in models.ApplicationStatus}
# {'PENDING': 'Pendiente', 'DECLINED': 'Declinado', 'ACCEPTED': 'Aceptado', 'SUBMITTED': 'Enviado', 'STARTED': 'Empezado', 'REJECTED': 'Rechazado', 'INFORMATION_REQUESTED': 'Información solicitada', 'LAPSED': 'Caducado', 'APPROVED': 'Precalificado', 'CONTRACT_UPLOADED': 'Contrato cargado', 'COMPLETED': 'Completado'}

@jpmckinney jpmckinney assigned yolile and unassigned jpmckinney Aug 22, 2024
@jpmckinney jpmckinney changed the title Move translation of error messages and some enumerations to backend Move translation of some enumerations to backend Aug 22, 2024
@jpmckinney
Copy link
Member Author

Renaming issue for remaining task

@yolile
Copy link
Member

yolile commented Aug 23, 2024

Any preference for where to put this new endpoint? I'm thinking of a generic get_settings one, that receives a key as a parameter and returns labels and values. The different settings belong to different forms, including public and private ones. I could create a new file and put the new endpoint there, and make it public.

@jpmckinney
Copy link
Member Author

For inspiration, GitHub uses /meta for metadata: https://docs.github.com/en/rest/meta/meta?apiVersion=2022-11-28

One option is to just have one endpoint /meta for all our constants. I don't think any of the constants we want to return are insecure or private (document types, etc.).

If so, we can have a routers/guest/meta.py file (since even if accessed to render a private page, the endpoint itself doesn't require authentication/authorization).

Or, we can have individual endpoints for each constant...

But, I think it'll be easier going forward to just have one endpoint. It will require fewer changes across the two repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants