I have a package which is reusable but also needs translations. For the first binary that uses it, all is well - for the second one I may forget some tokens that need translations. Subsequentially this leads to texts not being translated.
Therefore I am looking for a way to have translations, that enables the compiler (or something else) to find all translation-tokens that are used in any of the to-be compiled packages.
I have thought of maybe using go:generate. This would make a translation look like so:
//go:generate collectTranslation "TOKEN_FOR_TEXT" "Default text"
translator.Translate("TOKEN_FOR_TEXT", "Default text")
This approach however has two problems:
Problem 1) Redundancy - I have to remember to add a go:generate everywhere I use a translation. I would REALLY prefer a way that is more robust against human error.
Problem 2) go generate does not automatically dereference dependencies. I need to get fancy with go list -f '{{ .Deps }}'
to get the dependencies and then run go generate for those. (Obviously I don't do this by hand but automated.)
Anyways my solutions while working feel like patchworks to the problem. Is there a cleaner solution?