update virtualenv_translate to do additional po file header cleanup as well as detecting upstream tranlation updates from translatewiki.
@@ -8,6 +8,20 @@ fi
source ${TWLIGHT_HOME}/bin/virtualenv_activate.sh
+makemessages() {
+ echo "makemessages"
+ langs=($(python manage.py diffsettings | grep '^LANGUAGES =' | grep -o "(u'[^']*'" | grep -o "'[^']*'" | xargs))
+ langs+=('qqq')
+ for locale in "${langs[@]}"; do
+ python manage.py makemessages --locale=${locale} || exit 1
+ # Search and replace meaningless boilerplate information from headers.
+ sed -i "s/# SOME DESCRIPTIVE TITLE./# TWLlight ${locale} translation./" ${TWLIGHT_HOME}/locale/${locale}/LC_MESSAGES/django.po
+ # @TODO do this with Python instead of Perl to avoid extra dependencies.
+ # multiline text munging is just so handy in Perl.
+ perl -i -0pe 's/# FIRST AUTHOR \<EMAIL\@ADDRESS\>, YEAR.\n#\n#, fuzzy/#/' ${TWLIGHT_HOME}/locale/${locale}/LC_MESSAGES/django.po
+ done
+}
+
# Count the number of files searched by makemessages
# that have unstaged changes.
# https://docs.djangoproject.com/en/1.11/ref/django-admin/
@@ -15,20 +29,21 @@ message_files_changed=$(git diff-files --name-only -- '*.html' '*.txt' '*.py' --
# Count the number of translation files changed.
translation_files_changed=$(git diff-files --name-only -- '*.po' --porcelain | wc -l)
-# If any relevant files changed but no translation files changed,
-# update translations.
+# If message files changed but no translations changed, make messages.
if [ "${message_files_changed}" -gt 0 ] && [ "${translation_files_changed}" -eq 0 ]
then
+ makemessages
+ # Recount the number of translation files changed.
+ translation_files_changed=$(git diff-files --name-only -- '*.po' --porcelain | wc -l)
+else
+ echo "No translatable source files changed."
+fi
- echo "makemessages"
- langs=($(python manage.py diffsettings | grep '^LANGUAGES =' | grep -o "(u'[^']*'" | grep -o "'[^']*'" | xargs))
- for locale in "${langs[@]}"; do
- python manage.py makemessages --locale=${locale} || exit 1
- done
- python manage.py makemessages --locale=qqq || exit 1
-
+# If translations changed, recompile messages.
+if [ "${translation_files_changed}" -gt 0 ]
+then
echo "compilemessages"
python manage.py compilemessages || exit 1
else
- echo "No translatable source files changed."
+ echo "No translations changed."
fi
