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

Add translations for helps. #18

Closed
bckohan opened this issue Feb 19, 2024 · 13 comments
Closed

Add translations for helps. #18

bckohan opened this issue Feb 19, 2024 · 13 comments
Assignees
Labels
enhancement New feature or request

Comments

@bckohan
Copy link
Member

bckohan commented Feb 19, 2024

Should make a good faith effort to provide translations for all the languages Django provides translations for.

@bckohan bckohan added the enhancement New feature or request label Feb 19, 2024
@bckohan bckohan self-assigned this Feb 19, 2024
@bckohan bckohan added this to the Version 1.3 milestone Apr 23, 2024
@bckohan bckohan modified the milestones: Version 2.2, Version 3.0 Jun 10, 2024
@bckohan
Copy link
Member Author

bckohan commented Oct 5, 2024

One wrinkle here is that typer adds some of the help text for (i.e. --help) - that may eventually be wrapped in gettext and if it is - how do the native python translation and django translation systems work together?

@bckohan
Copy link
Member Author

bckohan commented Oct 13, 2024

Does django have translations for the common options?

@oliverandrich oliverandrich self-assigned this Oct 14, 2024
@bckohan bckohan changed the title Add translations for error messages and helps. Add translations for helps. Jan 21, 2025
@bckohan
Copy link
Member Author

bckohan commented Jan 21, 2025

We will not translate error messages presented on the terminal per Django's practice. I do think translating the default CLI helps is important because the CLI interface may be used by non-devs. Consider using google translate: https://github.com/ankitpopli1891/django-autotranslate

@oliverandrich
Copy link
Member

What is the rationale behind including it? Will it be an optional dependency? And shouldn't it be up to the project, including django-typer to supply the translation? I would use django-translate either for all of my project or not at all. But it would surprise me, if one third-party library handles it on its own.

@bckohan
Copy link
Member Author

bckohan commented Jan 23, 2025

It would only be a development dependency, it wouldn't register on pypi at all. Translations would be produced at package time.

Django's stance toward translation so far as I can tell is that if it's language that only developers are exposed to the strings are not translated and if it's language downstream users are exposed to it is translated. Django does not offer translations out of the box for the helps for default command parameters. Probably because this language is thought of as in the first category. I'm not sure I agree with this. I think the CLI interface of a Django site probably falls somewhere between the developer only audience and the user audience. As such I think it makes sense to provide translations out of the box for the common parameters.

@oliverandrich
Copy link
Member

Thanks for the clarification. I am a bit torn whether to translate commands or not. Lately, I have switched to skipping this extra step and go with English text there. The reason is, that most of the system we are deploying to are either C.UTF-8 or en_US.UTF-8. Just a handful uses de_DE.UTF-8 and would profit from a translation. Maybe the stance of Django is reasonable and pragmatic.

@bckohan
Copy link
Member Author

bckohan commented Jan 28, 2025

Yeah, I wrestled with it too. I'm leaning towards yes for a few reasons:

  1. It's pretty easy to use a different settings module when using the CLI, so even if your production site was configured for a default language other than english and you still wanted the CLI to render in english, you could just switch the default language for management mode.
  2. I have this notion that one could use the type hints in the CLI to automagically build an admin web UI for configuring and scheduling management commands (think crontab but through the admin) and if you did that it'd be nice to have the translations available.

@bckohan
Copy link
Member Author

bckohan commented Jan 28, 2025

Also further clarification. I'm not talking about building translation infrastructure for commands that use django-typer, only including a .po file that contains google translate generated translations for the help strings of the common parameters. Params like --verbosity or --settings

@oliverandrich
Copy link
Member

Ah. Now I am in sync with you. The last comment closed a gap in my mind and the mentioning of the dev dependency also makes sense. This makes total sense.

bckohan added a commit that referenced this issue Feb 4, 2025
@bckohan
Copy link
Member Author

bckohan commented Feb 4, 2025

@oliverandrich sanity check, does this make any sense?

Image

original english:

Image

bckohan added a commit that referenced this issue Feb 4, 2025
bckohan added a commit that referenced this issue Feb 4, 2025
@oliverandrich
Copy link
Member

They look pretty good to me. I would have translated "settings modul" as "Modul für Einstellungen" instead of "Einstellungsmodul". But this is basically a stylistic question and not incorrect.

@bckohan
Copy link
Member Author

bckohan commented Feb 6, 2025

The remaining task here is to figure out how to get stdlib gettext translations in upstream Typer to work with the django translation system 🤔

bckohan added a commit that referenced this issue Feb 13, 2025
@bckohan
Copy link
Member Author

bckohan commented Feb 15, 2025

Both click and typer wrap strings in stdlib gettext. These are mostly error strings and help markers (things like [OPTIONS]). The only way to really incorporate these is to monkey patch the gettext function calls upstream. This works but is icky/brittle. Because the use case here is generating translated UIs from the helps for an admin command runner or something like that - it's not critical that the markers/errors to be translated because they wouldn't appear in that UI anyway.

I'm considering the help translations to be good enough and kicking the rest of this can down the road. No reason it should hold up a 3.0 release.

There should probably be an official Django supported mechanism for dealing with dependency libraries that use stdlib gettext. Perhaps even monkey patching the stdlib gettext calls....

bckohan added a commit that referenced this issue Feb 15, 2025
@bckohan bckohan closed this as completed Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants