Skip to content

Commit

Permalink
Add babel translation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nurupo committed Apr 28, 2018
1 parent 3c5513a commit 8b6303b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ public
*.pyc
pelican.pid
srv.pid
themes/i18n/translations/*/LC_MESSAGES/*.mo

# This is a generic Python gitignore
# https://github.com/github/gitignore/blob/2eba0d635f6f5f1b22a4ad99dcc9da0c11da2208/Python.gitignore
Expand Down
5 changes: 5 additions & 0 deletions i18n-compile-po.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

export TZ=UTC

pybabel compile -d themes/i18n/translations
27 changes: 27 additions & 0 deletions i18n-extract-messages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

export TZ=UTC

if [ -e themes/i18n/messages.pot ]; then
mv themes/i18n/messages.pot themes/i18n/messages.pot.old
fi

pybabel extract --msgid-bugs-address="https://github.com/Tox/tox.chat/issues" \
--copyright-holder="Project Tox Website Contributors" \
--project="Tox Website" \
--version="(https://tox.chat)" \
--sort-by-file \
-F themes/i18n/babel.cfg \
-o themes/i18n/messages.pot \
.

if [ -e themes/i18n/messages.pot.old ]; then
if diff -u <(sed '/POT-Creation-Date/d' themes/i18n/messages.pot) <(sed '/POT-Creation-Date/d' themes/i18n/messages.pot.old); then
echo "No translation strings changed, keeping the old POT"
mv themes/i18n/messages.pot.old themes/i18n/messages.pot
else
echo "Translation strings changed, using the new POT"
rm themes/i18n/messages.pot.old
fi
fi

10 changes: 10 additions & 0 deletions i18n-update-po.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

export TZ=UTC

pybabel update -i themes/i18n/messages.pot -d themes/i18n/translations

for file in themes/i18n/translations/*/LC_MESSAGES/*.po; do
sed -i '/^#~/,+2d' $file
done

3 changes: 3 additions & 0 deletions themes/i18n/babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[jinja2: themes/global/templates/**.html]
[jinja2: themes/website/templates/**.html]
[jinja2: themes/blog/templates/**.html]

0 comments on commit 8b6303b

Please sign in to comment.