2020-04-23 14:29:40 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-04-24 10:16:54 +02:00
|
|
|
set -xe
|
2020-04-23 14:29:40 +02:00
|
|
|
|
|
|
|
SOURCE_REPOSITORIES=(
|
2021-06-09 11:21:55 +02:00
|
|
|
ipl-web
|
|
|
|
ipl-validator
|
2020-04-23 14:29:40 +02:00
|
|
|
icingaweb2
|
|
|
|
icingaweb2-module-director
|
|
|
|
icingaweb2-module-vspheredb
|
|
|
|
icingadb-web
|
|
|
|
icingaweb2-module-reporting
|
|
|
|
icingaweb2-module-graphite
|
|
|
|
icingaweb2-module-cube
|
2020-04-30 11:36:07 +02:00
|
|
|
#icingaweb2-module-idoreports
|
2020-04-23 14:29:40 +02:00
|
|
|
icingaweb2-module-aws
|
|
|
|
icingaweb2-module-businessprocess
|
|
|
|
#icingaweb2-module-doc
|
|
|
|
#icingaweb2-module-fileshipper
|
|
|
|
#icingaweb2-module-jira
|
|
|
|
#icingaweb2-module-nagvis
|
|
|
|
icingaweb2-module-pdfexport
|
|
|
|
#icingaweb2-module-pnp
|
|
|
|
#icingaweb2-module-puppetdb
|
|
|
|
#icingaweb2-module-test
|
|
|
|
#icingaweb2-module-vsphere
|
|
|
|
icingaweb2-module-x509
|
|
|
|
#icingaweb2-module-toplevelview
|
|
|
|
icingaweb2-module-audit
|
|
|
|
icingaweb2-module-elasticsearch
|
|
|
|
#icingaweb2-module-eventdb
|
|
|
|
#icingaweb2-module-generictts
|
|
|
|
#icingaweb2-module-lynxtechnik
|
|
|
|
)
|
|
|
|
|
|
|
|
# Fetch repositories which do not exist yet in the directory
|
|
|
|
FETCHED_REPOS=();
|
|
|
|
for repo_name in "${SOURCE_REPOSITORIES[@]}"; do
|
2020-04-27 16:08:35 +02:00
|
|
|
if [ ! -d "sources.d/$repo_name" ]; then
|
2020-04-23 14:29:40 +02:00
|
|
|
FETCHED_REPOS+=( $repo_name );
|
|
|
|
wget -q -O - https://github.com/Icinga/$repo_name/archive/master.tar.gz | tar xz
|
2020-04-27 16:08:35 +02:00
|
|
|
mv $repo_name-master/ sources.d/$repo_name
|
2020-04-23 14:29:40 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Create a list of files xgettext should scan
|
2020-04-27 16:08:35 +02:00
|
|
|
find -L sources.d -regex ".*\.\(php\|phtml\)" ! -path "*/vendor/*" ! -path "*/test/*" > catalog.txt
|
2020-04-23 14:29:40 +02:00
|
|
|
|
|
|
|
xgettext --language=PHP \
|
|
|
|
--keyword=translate \
|
|
|
|
--keyword=translate:1,2c \
|
|
|
|
--keyword=translatePlural:1,2 \
|
|
|
|
--keyword=translatePlural:1,2,4c \
|
|
|
|
--keyword=mt:2 \
|
|
|
|
--keyword=mt:2,3c \
|
|
|
|
--keyword=mtp:2,3 \
|
|
|
|
--keyword=mtp:2,3,5c \
|
|
|
|
--keyword=t \
|
|
|
|
--keyword=t:1,2c \
|
|
|
|
--keyword=tp:1,2 \
|
|
|
|
--keyword=tp:1,2,4c \
|
|
|
|
--keyword=N_ \
|
|
|
|
--from-code=utf-8 \
|
|
|
|
--files-from=catalog.txt \
|
2020-04-24 12:26:16 +02:00
|
|
|
--sort-by-file \
|
2020-05-12 15:26:49 +02:00
|
|
|
--copyright-holder="Icinga GmbH" \
|
2020-05-11 14:32:09 +02:00
|
|
|
--package-name="Icinga L10n" \
|
2020-04-23 14:29:40 +02:00
|
|
|
--package-version=$(git describe --always) \
|
2020-05-11 14:32:09 +02:00
|
|
|
--msgid-bugs-address=https://github.com/Icinga/L10n/issues \
|
2020-04-23 14:29:40 +02:00
|
|
|
--default-domain=icinga \
|
|
|
|
--output=icinga.pot
|
|
|
|
|
2020-04-28 09:42:29 +02:00
|
|
|
# Re-add the PoEdit header extensions
|
|
|
|
REPLACE_CODE=$(cat << PYTHON
|
|
|
|
import sys, re
|
|
|
|
result = re.sub(
|
|
|
|
r'msgid \"\"\nmsgstr \"\"(\n\".*\")+',
|
|
|
|
'\g<0>\n'
|
|
|
|
+ '\"X-Poedit-Basepath: ../../../src\\\\\\\\n\"\n'
|
|
|
|
+ '\"X-Poedit-SearchPath-0: sources.d\\\\\\\\n\"',
|
|
|
|
sys.stdin.read()
|
|
|
|
)
|
2020-05-12 15:26:49 +02:00
|
|
|
from datetime import date
|
|
|
|
result = result.replace(
|
|
|
|
'# Copyright (C) YEAR Icinga GmbH',
|
|
|
|
'# Copyright (C) {0} Icinga GmbH'.format(date.today().year),
|
|
|
|
1
|
|
|
|
)
|
2020-04-28 09:42:29 +02:00
|
|
|
sys.stdout.write(result)
|
|
|
|
PYTHON
|
|
|
|
)
|
|
|
|
cat icinga.pot | python -c "$REPLACE_CODE" > temp; mv temp icinga.pot
|
|
|
|
|
2020-04-23 14:29:40 +02:00
|
|
|
# Cleanup created files and directories
|
|
|
|
rm catalog.txt
|
|
|
|
for repo_name in "${FETCHED_REPOS[@]}"; do
|
2020-04-27 16:08:35 +02:00
|
|
|
rm -rf sources.d/$repo_name
|
2020-04-23 14:29:40 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# Check for changes (new messages) that need to be committed
|
2020-04-28 11:21:36 +02:00
|
|
|
CHANGES=1
|
|
|
|
git diff -U0 \
|
2020-05-04 14:31:43 +02:00
|
|
|
| grep -Pe '^[+-]{1}(?!#:)[^+-]+' \
|
2020-04-28 11:21:36 +02:00
|
|
|
| grep -qv -e '."Project-Id-Version:' -e '."POT-Creation-Date:' \
|
|
|
|
|| CHANGES=0
|
|
|
|
|
2020-04-29 16:37:25 +02:00
|
|
|
if [ $CHANGES -eq 0 ]; then
|
2020-04-23 14:29:40 +02:00
|
|
|
echo "No new messages found.";
|
|
|
|
git checkout icinga.pot;
|
|
|
|
else
|
2020-04-30 14:06:59 +02:00
|
|
|
STATS=""
|
|
|
|
|
2020-04-28 10:58:59 +02:00
|
|
|
# Update intermediate (in-progress) catalogs
|
|
|
|
LOCALES=$(find . -mindepth 1 -maxdepth 1 -type d -regextype grep -regex '\./[a-z]\{2\}_[A-Z]\{2\}' -printf "%P ")
|
|
|
|
for locale_name in $LOCALES; do
|
|
|
|
msgmerge --update --backup=none --lang=$locale_name --sort-by-file $locale_name/LC_MESSAGES/icinga.po icinga.pot
|
2020-04-30 14:06:59 +02:00
|
|
|
|
|
|
|
STATS_OUT=$(LC_ALL=C msgfmt --statistics $locale_name/LC_MESSAGES/icinga.po 2>&1 >/dev/null)
|
|
|
|
if [ -f "messages.mo" ]; then
|
|
|
|
rm "messages.mo"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# TODO: Make this a function? (is also used in bin/validate)
|
|
|
|
TRANSLATED=0
|
|
|
|
UNTRANSLATED=0
|
|
|
|
FUZZY=0
|
|
|
|
|
|
|
|
RE="[0-9]+"
|
|
|
|
LAST_LINE=$(echo "$STATS_OUT" | tail -1)
|
|
|
|
for chars in $LAST_LINE; do
|
|
|
|
if [[ "$chars" =~ $RE ]] && [[ ${BASH_REMATCH[0]} ]]; then
|
|
|
|
LAST_CNT="${BASH_REMATCH[0]}"
|
|
|
|
else
|
|
|
|
case $chars in
|
|
|
|
"translated")
|
|
|
|
TRANSLATED=$LAST_CNT
|
|
|
|
;;
|
|
|
|
"fuzzy")
|
|
|
|
FUZZY=$LAST_CNT
|
|
|
|
;;
|
|
|
|
"untranslated")
|
|
|
|
UNTRANSLATED=$LAST_CNT
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
PROGRESS=$(python -c "print (int(round(($TRANSLATED.0 / ($TRANSLATED + $UNTRANSLATED + $FUZZY)) * 100)))")
|
|
|
|
STATS+=" $locale_name:$PROGRESS%"
|
2020-04-28 10:58:59 +02:00
|
|
|
done
|
|
|
|
|
2020-04-30 14:06:59 +02:00
|
|
|
# Update locale statistics
|
|
|
|
python -c "import json; \
|
|
|
|
print ( \
|
|
|
|
json.dumps({k: v for k, v in (kv for kv in (s.split(':') for s in '$STATS'.strip().split()))}) \
|
|
|
|
) \
|
|
|
|
" > ../.github/stats.json
|
|
|
|
|
2020-04-23 14:29:40 +02:00
|
|
|
echo "New messages found!";
|
|
|
|
# Working tree is left dirty as the following step creates a new pull request
|
|
|
|
fi
|