Disambiguate identical alias strings (e.g. "a" for "app" and "add") #647
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For example, this string is showing up with 2 translation notes:
abra app
aliases. use a comma separated list of aliases with no spaces in betweenabra server add
aliases. use a comma separated list of aliases with no spaces in betweenSo, it's really just a coincidence that both strings are "a" in the English version; both should be translated separately.
It seems like the most gettext-y way to handle this is with "contexts" – in our case, using
GetC
instead ofGet
.Ouch, could be wrong but I think
snapd
'sxgettext-go
doesn't support context at all? 🫠Not seeing it here: https://github.com/canonical/snapd/blob/master/i18n/xgettext-go/main.go
Hmmmmm, maybe we need to do like incus in
092990416a/internal/i18n/i18n_linux.go (L9-L12)
and wrap our call:In a function istead of a direct
var
and do some finagling there? I think you could dostring...
variable arguments in a function which takes 0 or more strings? There's no optional arguments in Go but you can do it by using what is called the "functional options" approach. I would hope this would be easy to sort... then we could do one of these two?https://golang.cafe/blog/golang-functional-options-pattern.html
Yep the function side makes sense, I had tried out this but indeed functional options is maybe cleaner:
The problem is that, although
xgettext-go
will pick up all thei18n.G
invocations, it won't add the context; we should be seeing an extra line in the POT file.i.e. with the above, making this change:
Should produce this POT content:
But,
msgctxt
doesn't get added.@3wordchant thanks! That makes sense 🧗
Fuck me, we really have been backed into a wall on this one. It's not our fault ofc and is due to the Go ecosystem being so shaky on translation support. I have a work-around which is not actually the worst thing ever but it's pretty damn bad. It's a migration back to
xgotext
(😱)We would need to chaos fork it (😱) and override
270f280ba5/cli/xgotext/parser/pkg-tree/golang.go (L88-L90)
(i'm guessing) to matchcoopcloud.tech/abra/pkg/gotext
and then define aGet
/GetC
function there (therefore hacking thegotext.Get/GetC
matching but being our version ofGet
/GetC
and not the upstream (😱). We need to do this because we need to initialise the locale once and read the translations from the embedded filesystem and have a central import from there. Then we justsed -i
all uses ifi18n
in the import URLs and function calls...You could theoretically hack the matching on the function name but I tried to dive into this and ran into an inscrutable list of integers for which there is no explanation for yet https://github.com/leonelquinteros/gotext/issues/124#issuecomment-3211589971 (😱)
I noticed that the
-pkg-tree
option (instead of-in
) onxgotext
is much faster so it might not be such a massive slow down for our automation. It is however a noticeably slow down however compared to the zippyxgettext-go
...I could take a run at the migration but this seems like a pretty drastic / nuclear option... especially the need to re-work our CI automation also once more...
Wow full-on magical software numerology incantation 😅
Oh very nice 👏
I don't mind doing that part.
Obviously forking does seem pretty last-resort, but I'm not sure what else we do? The only alternative I can think of would be to establish our own (cursed) convention of e.g.
u#upgrade
in the string, then we strip#
and everything after it? Basically rebuilding gettext contexts ourselves.@3wordchant hahaha
u#uppgrade
that would be spectacularly cursed 😂 love it. OK and I guess option 3 is really diving intoxgettext-go
and trying to patch it also to make it work. Bearing in mind we're running an ancient verison of the software also. I feel like getting back onxgotext
is maybe more future-proof as it is the "new kid on the block" but at the same time, the maintainer hasn't replied to my issue and i don't see much activity... so pros/cons everywhere... any preferences? will hopefully have time to dive into this next week unless you take a run at it!OK, I couldn't resist and have managed to get a working prototype with
xgotext
and managed to test / patchabra
and see themsgctxt
turn up! I've submitted a PR. If they don't accept it, we can fork but hopefully we can get this merged upstream. If we want to go in this direction, I can clean it all up and temporarily fork so we can make progress...Incredible 🤩
Decision from Monday: we play the waiting game, hope that
leonelquinteros
merges the PR by the time we need to launch, decide between various unsavoury forking options if not.Wait I'm confused, this was our plan for #629 - does it apply here too?
I think for this we do need a temporary fork to make progress and have those translations put in place for testing? Sorry, I think I wasn't that clear... I can arrange this and it's not much work. No reason to hold up the new release of
abra
now, I'd say. This can be punted into "abra next next" as we improve the translation situation...Fuck me,
xgotext
doesn't support comments 😱 I'm going back to a final wildcard attempt to just forkxgettext-go
and add context support somehow. I think it might be the best way forward and maybe we'll need to add more stuff also in the future... will be poking at this in the coming days...OK, I think I've got a lead on a fix: #672
I've just realised that the latest
gettext
actually supports Go natively 😱 It's not really conveniently available in most distros, so maybe we can hold off on that for now and migrate to it in a few months. Then things should be much simpler. I did compile it from source but it was pretty gnarly, so I'm not sure if worth the effort to docker-ize it right now. Feel free to take a run at it if you want! I assume it supports everything we need as it is the OG upstream.Serious yak shaving going down here!