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