internal/xgettext, cmd/xgettext-go: add an xgettext-go command #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is based on the xgettext-go utility in the snapd tree with some refinements. The main improvements are:
Multiple keywords can be specified via
-k
/--keyword
. This uses the same syntax as GNU xgettext to declare plural or context keywords, so e.g.--keyword-plural=i18n.DG
would now be written as--keyword=i18n.DG:1,2
. As with normal xgettext, the builtin keywords can be disabled by passing-k
without an argument.Multiple comment tags can be registered with
-c
/--add-comments
. Used without a value, all comments before translatable strings are collected.We use
strconv.Unquote
to decode string constants andstrconv.Quote
to quote them for inclusion in the template. This simplifies the handling, and means we correctly handle string constants like"hello "+`world`
.