Skip to content

Instantly share code, notes, and snippets.

@olebedev
Last active April 1, 2016 13:50
Show Gist options
  • Save olebedev/2961f79a9bfacb368f8f to your computer and use it in GitHub Desktop.
Save olebedev/2961f79a9bfacb368f8f to your computer and use it in GitHub Desktop.
Makefile rule to extract gettetx/ngettext calls from Golang templates and source files
XGETTEXT_FLAGS = --no-wrap --language=c --from-code=UTF-8 --output=- -
$(POT_FILE): $(TEMPLATES) $(filter-out $(BINDATA), $(GO_FILES))
@cat $? \
| grep -i gettext \
| sed -e "s/ngettext \"\([^\"]*\)\".\"\([^\"]*\)\".\(.*\) }}/ngettext(\"\1\", \"\2\", \3) }}/g" \
| sed -e "s/[^n]gettext \"\(.*\)\"/ gettext(\"\1\")/g" \
| sed -e "s/NGetText(\([^\)]*\))/ ngettext(\1) /g" \
| sed -e "s/GetText(\([^\)]*\))/ gettext(\1) /g" \
| xgettext $(XGETTEXT_FLAGS) \
| sed -e '1,20d' \
| msguniq > $@
%.po: $(POT_FILE)
@msgmerge -U $@ $<
.INTERMEDIATE: $(POT_FILE)
.PRECIOUS: %.po
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment