| 1 | APP = bleachbit |
| 2 | POFILES = $(wildcard *.po) |
| 3 | MOFILES = $(patsubst %.po,%.mo,$(POFILES)) |
| 4 | PY_SRC = $(wildcard ../bleachbit/*.py) |
| 5 | UI_SRC = ../share/app-menu.ui |
| 6 | SRC = $(PY_SRC) $(UI_SRC) |
| 7 | POTFILE = $(APP).pot |
| 8 | ITS ?= /usr/share/gettext/its/metainfo.its |
| 9 | PYTHON ?= python3 |
| 10 | |
| 11 | |
| 12 | .PHONY: refresh-po spelling local install clean all require-gettext |
| 13 | |
| 14 | require-gettext: |
| 15 | @missing=0; \ |
| 16 | for c in xgettext msgmerge msgfmt msggrep; do \ |
| 17 | command -v $$c >/dev/null 2>&1 || missing=1; \ |
| 18 | done; \ |
| 19 | if [ $$missing -ne 0 ]; then \ |
| 20 | echo "ERROR: Missing gettext. APT users, try: sudo apt install gettext"; \ |
| 21 | exit 1; \ |
| 22 | fi |
| 23 | |
| 24 | cleanerml.pot: ../bleachbit/CleanerML.py ../cleaners/*xml |
| 25 | $(PYTHON) ../bleachbit.py --pot |
| 26 | |
| 27 | desktop.pot: ../org.bleachbit.BleachBit.desktop |
| 28 | echo "#: ../org.bleachbit.BleachBit.desktop" > desktop.pot |
| 29 | echo "msgid \"`perl -n -e '/GenericName=(.*)$$/ && print "$$1\n"' ../org.bleachbit.BleachBit.desktop`\"" >> desktop.pot |
| 30 | echo "msgstr \"\"" >> desktop.pot |
| 31 | echo >> desktop.pot |
| 32 | echo "#: ../org.bleachbit.BleachBit.desktop" >> desktop.pot |
| 33 | echo "msgid \"`perl -n -e '/Comment=(.*)$$/ && print "$$1\n"' ../org.bleachbit.BleachBit.desktop`\"" >> desktop.pot |
| 34 | echo "msgstr \"\"" >> desktop.pot |
| 35 | echo >> desktop.pot |
| 36 | |
| 37 | metainfo.pot: ../org.bleachbit.BleachBit.metainfo.xml require-gettext |
| 38 | @echo "* Extracting translatable strings from metainfo.xml using xgettext with ITS" |
| 39 | @if [ -f "$(ITS)" ]; then \ |
| 40 | xgettext -o $@ \ |
| 41 | --from-code=UTF-8 \ |
| 42 | --add-comments=TRANSLATORS \ |
| 43 | --add-location=file \ |
| 44 | --its=$(ITS) \ |
| 45 | $<; \ |
| 46 | else \ |
| 47 | echo "WARNING: Required file '$(ITS)' is missing. Skipping metainfo extraction (creating stub)."; \ |
| 48 | echo "APT users, try: sudo apt install appstream"; \ |
| 49 | echo '# metainfo.pot stub (ITS file missing)' > $@; \ |
| 50 | fi |
| 51 | |
| 52 | nsis.pot: ../windows/NsisInclude/NsisMultiUserLang.nsh ../windows/nsis_translations.py |
| 53 | $(PYTHON) ../windows/nsis_translations.py --pot |
| 54 | |
| 55 | $(POTFILE): $(SRC) cleanerml.pot desktop.pot metainfo.pot nsis.pot require-gettext |
| 56 | @echo "* Generating $(POTFILE)" |
| 57 | @if [ -f $(POTFILE) ]; then \ |
| 58 | cp $(POTFILE) $(POTFILE).old; \ |
| 59 | echo " Words before update: "; \ |
| 60 | tail -n +20 $(POTFILE) | grep -v ^# | sed "s/\(msgstr\|msgid\)//g" | sort | uniq | wc -w; \ |
| 61 | fi |
| 62 | cat cleanerml.pot desktop.pot metainfo.pot nsis.pot > $(POTFILE) |
| 63 | # --add-location=file: reduces size of diff |
| 64 | xgettext -o $(POTFILE) \ |
| 65 | --join-existing \ |
| 66 | --add-comments=TRANSLATORS \ |
| 67 | --keyword="_p:1c,2" \ |
| 68 | --default-domain=$(APP) \ |
| 69 | --add-location=file \ |
| 70 | $(PY_SRC) |
| 71 | xgettext -o $(POTFILE) \ |
| 72 | --join-existing \ |
| 73 | --add-comments=TRANSLATORS \ |
| 74 | --default-domain=$(APP) \ |
| 75 | --add-location=file \ |
| 76 | --language=Glade \ |
| 77 | $(UI_SRC) |
| 78 | # While GNU sed requires no argument for -i, BSD sed requires a file extension. |
| 79 | # Both accept empty string with no space after -i. |
| 80 | sed -i'' 's/charset=CHARSET/charset=utf-8/g' $(POTFILE) |
| 81 | echo " Words after update: " \ |
| 82 | `tail -n +20 $(POTFILE) | grep -v ^# | sed "s/\(msgstr\|msgid\)//g" | sort | uniq | wc -w` |
| 83 | if [ -f $(POTFILE).old ]; then \ |
| 84 | echo "msgid added or removed"; \ |
| 85 | msgcomm -u $(POTFILE) $(POTFILE).old > diff.pot; \ |
| 86 | sed -e '1,/^"Plural-Forms:/d' -e '/^#/d' -e '/^msgstr/d' -e '/^$$/d' diff.pot; \ |
| 87 | fi |
| 88 | |
| 89 | |
| 90 | refresh-po: $(POTFILE) require-gettext |
| 91 | @echo "* Refreshing .po files" |
| 92 | for oldpo in $(POFILES); do \ |
| 93 | lang=`basename $$oldpo .po`; \ |
| 94 | echo $$lang; \ |
| 95 | msgmerge --no-fuzzy-matching -v $${lang}.po $(POTFILE) > $${lang}.pot; \ |
| 96 | mv $$lang.pot $$lang.po; \ |
| 97 | done |
| 98 | |
| 99 | spelling: $(POTFILE) require-gettext |
| 100 | @echo "* Checking spelling" |
| 101 | @echo |
| 102 | @echo Word count: `msggrep -Kie . --no-wrap $(POTFILE) | grep ^msgid | cut -c 8- | wc -w` |
| 103 | @echo |
| 104 | @command -v aspell >/dev/null 2>&1 || { echo "WARNING: Missing 'aspell'. apt users, try: sudo apt install aspell"; exit 0; } |
| 105 | msggrep -Kie . --no-wrap $(POTFILE) | grep ^msgid | cut -c 8- | aspell --personal=./aspell.pws list | sort -u |
| 106 | |
| 107 | %.mo: %.po require-gettext |
| 108 | @echo "* Generating $@" |
| 109 | msgfmt --statistics -o $@ $< |
| 110 | |
| 111 | local: $(MOFILES) |
| 112 | @echo "* Copy locally for running without system installation" |
| 113 | for mofile in $(MOFILES); do \ |
| 114 | lang=`basename $$mofile .mo`; \ |
| 115 | mkdir -p ../locale/$$lang/LC_MESSAGES/; \ |
| 116 | cp -lf $$mofile ../locale/$$lang/LC_MESSAGES/bleachbit.mo; \ |
| 117 | done |
| 118 | @echo "To launch the application, run this in the project root directory:" |
| 119 | @echo "$(PYTHON) bleachbit.py" |
| 120 | |
| 121 | install: $(MOFILES) |
| 122 | echo "* Installing in $(DESTDIR)/usr/share/locale" |
| 123 | for MO in $(MOFILES); do \ |
| 124 | lang=`basename $$MO .mo`; \ |
| 125 | DST=$(DESTDIR)/usr/share/locale/$$lang/LC_MESSAGES/; \ |
| 126 | mkdir -p $$DST; \ |
| 127 | cp $$MO $$DST/bleachbit.mo; \ |
| 128 | done |
| 129 | |
| 130 | clean: |
| 131 | echo "* Cleaning" |
| 132 | @rm -fv -- *.mo |
| 133 | # Keep $(POTFILE) because it is stored in Git for Weblate. |
| 134 | @rm -fv $(POTFILE).old cleanerml.pot desktop.pot metainfo.pot nsis.pot diff.pot |
| 135 | @rm -rfv ../locale |
| 136 | |
| 137 | all: $(POTFILE) $(MOFILES) |