Mark "help" subcommand and "--help" flag for translation #628

Closed
opened 2025-08-29 20:25:57 +00:00 by 3wordchant · 7 comments
Owner

Currently:

➜ docker run -it -e LANG=es -v $HOME/.abra:/root/.abra:z git.coopcloud.tech/toolshed/abra:latest 
La varita de mágica de Co-op Cloud 🪄🎩🐇

...

  actualizar    Actualizar abra
  autocompletar Genera un script de autocompletado
  catalogo      Administrar la catálogo de recetas
  help          Help about any command
  manual        Manual de uso

Note that "help", and the explanation "Help about any command" are not translated.

This is because they don't appear in the Gettext catalogue.

Pending merge of https://github.com/spf13/cobra/pull/2090, it's possible that we can work around this by defining our own helpCommand and helpFlag – but how to do this without huge repetition is not immediately obvious to me.

Currently: ``` ➜ docker run -it -e LANG=es -v $HOME/.abra:/root/.abra:z git.coopcloud.tech/toolshed/abra:latest La varita de mágica de Co-op Cloud 🪄🎩🐇 ... actualizar Actualizar abra autocompletar Genera un script de autocompletado catalogo Administrar la catálogo de recetas help Help about any command manual Manual de uso ``` Note that "help", and the explanation "Help about any command" are not translated. This is because they don't appear in the Gettext catalogue. Pending merge of https://github.com/spf13/cobra/pull/2090, it's possible that we can work around this by defining our own `helpCommand` and `helpFlag` – but how to do this without huge repetition is not immediately obvious to me.
3wordchant added the
i18n
label 2025-08-29 20:25:57 +00:00
3wordchant added this to the Language translation project 2025-08-29 20:25:57 +00:00
Owner

If you set it once on the rootCmd the implementation in cobra will walk back up the command tree to run it 🎉

If you set it once on the `rootCmd` the implementation in `cobra` will walk back up the command tree to run it 🎉
decentral1se moved this to Done in Language translation on 2025-08-30 08:48:27 +00:00
Author
Owner

@decentral1se I still don't see "Help about any command" or "help for" in the translation catalogue on main, halp

@decentral1se I still don't see "Help about any command" or "help for" in the translation catalogue on `main`, halp
Author
Owner

Full current output of abra -h in case that helps:

➜ LANG=es abra -h
The Co-op Cloud command-line utility belt 🎩🐇

Config:
  $ABRA_DIR: /home/f/.abra

Usage:
  abra [command]

Available Commands:
  actualizar    📨 Actualizar abra 🪄🎩🐇
  autocompletar 🤖 Genera un script de autocompletado
  catalogo      ⚙️ Administrar catálogo 📋 de recetas 🧑‍🍳
  help          Help about any command
  manual        📒 Manual de uso
  plataforma    ⚙️ Administrar plataformas 🚀
  receta        ⚙️ Administrar recetas 🧑‍🍳
  servidor      ⚙️ Administrar servidores (huertas digitales) 🕋

Flags:
  -d, --debug      show debug messages
  -h, --help       help for abra
  -n, --no-input   toggle non-interactive mode
  -o, --offline    prefer offline & filesystem access
  -v, --version    version for abra

Use "abra [command] --help" for more information about a command.
Full current output of `abra -h` in case that helps: ``` ➜ LANG=es abra -h The Co-op Cloud command-line utility belt 🎩🐇 Config: $ABRA_DIR: /home/f/.abra Usage: abra [command] Available Commands: actualizar 📨 Actualizar abra 🪄🎩🐇 autocompletar 🤖 Genera un script de autocompletado catalogo ⚙️ Administrar catálogo 📋 de recetas 🧑‍🍳 help Help about any command manual 📒 Manual de uso plataforma ⚙️ Administrar plataformas 🚀 receta ⚙️ Administrar recetas 🧑‍🍳 servidor ⚙️ Administrar servidores (huertas digitales) 🕋 Flags: -d, --debug show debug messages -h, --help help for abra -n, --no-input toggle non-interactive mode -o, --offline prefer offline & filesystem access -v, --version version for abra Use "abra [command] --help" for more information about a command. ```
Owner

Oh dear dog, i see 🤦 Digging into this...

Aight, for "Help about any command", it looks like we also need to override the help command itself:

And that seems like quite some copy/pasta but I don't think we can avoid that? Meh.

And to smash the "help for abra", I think we need to set our own help flag and mark it translatable?

That seems like less code, just defining it ourselves and then it's done.

Oh dear dog, i see 🤦 Digging into this... Aight, for "Help about any command", it looks like we also need to override the help command itself: * https://github.com/spf13/cobra/blob/7da941c3547e93b8c9f70bbd3befca79c6335388/command.go#L337-L340 * https://github.com/spf13/cobra/blob/7da941c3547e93b8c9f70bbd3befca79c6335388/command.go#L1269-L1310 And that seems like quite some copy/pasta but I don't think we can avoid that? Meh. And to smash the "help for abra", I think we need to set our own help flag and mark it translatable? * https://github.com/spf13/cobra/blob/7da941c3547e93b8c9f70bbd3befca79c6335388/command.go#L1216-L1232 That seems like less code, just defining it ourselves and then it's done.
decentral1se moved this to In Progress in Language translation on 2025-09-02 21:52:50 +00:00
Author
Owner

Aight, for "Help about any command", it looks like we also need to override the help command itself:
And to smash the "help for abra", I think we need to set our own help flag and mark it translatable?

Yep 💯, I started looking into this last week but quailed at how many places it might need to be copypasta'd and ran away.

> Aight, for "Help about any command", it looks like we also need to override the help command itself: > And to smash the "help for abra", I think we need to set our own help flag and mark it translatable? Yep 💯, I started looking into this last week but quailed at how many places it might need to be copypasta'd and ran away.
Owner

Oh shit, while I'm still here, we also need to override that "version for" bit:

I think it's the same as before, we just need to set it once on the rootCmd and it will propagate.

Will take a pass at it next hacking run unless someone else gets there first 🤸

Oh shit, while I'm still here, we also need to override that "version for" bit: * https://github.com/spf13/cobra/blob/7da941c3547e93b8c9f70bbd3befca79c6335388/command.go#L1234-L1257 I think it's the same as before, we just need to set it once on the `rootCmd` and it will propagate. Will take a pass at it next hacking run unless someone else gets there first 🤸
Owner
https://git.coopcloud.tech/toolshed/abra/pulls/641
decentral1se moved this to Done in Language translation on 2025-09-06 06:19:20 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: toolshed/abra#628
No description provided.