Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve download translation script #151

Merged
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 50 additions & 21 deletions download-translations
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,50 @@
# We need to check all languages, not only po/LINGUAS, since there might be
# new translations
LANGUAGES=\
"af am ar az be bg pt_BR bs ca zh_CN cs cy da de el eo es et eu fa fi fr "\
"ga en_GB gl gu he hi zh_HK hr hu id is it ja ko ku ky lg lt lv mk mn ms "\
"mt nb ne nl nn or pa pl pt rm ro ru rw sk sl sq sr sv ta tq th tk "\
"tr zh_TW uk ven vi wa xh zu"
"ab af an ar ast be bg bn bn_IN ca ckb crh cs da de el en_GB eo es et eu "\
"fa fi fr fur ga gd gl gu he hi hr hu hy id is it ja ka kk kn ko ku ky lg "\
"lt lv mk ml mn mr ms mt nb ne nl nn or pa pl pt pt_BR ro ru rw sk sl sq "\
"sr sv sw ta te tg th tr uk ur vi wa wo zh_CN zh_HK zh_TW"

# for testing/debugging:
#LANGUAGES="es fr hu sv pl xx"

# print error message and exit; prefix problem matcher when in GitHub Actions
err_msg() {
local prefix
[ -n "$CI" ] && prefix="::error::"
echo $prefix"$*" >&2
exit 1
}

# print warning message; prefix problem matcher when in GitHub Actions
warn_msg() {
local prefix
[ -n "$CI" ] && prefix="::warning::"
echo $prefix"$*" >&2
}

# check for 'diff' program
diff --version 2>/dev/null >/dev/null
if [ ! $? ]; then
echo "==== You must have the 'diff' program installed for this script ===="
exit 1
if [ $? -ne 0 ]; then
err_msg "==== You must have the 'diff' program installed for this script ===="
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this you can actually write:
diff --version 2>/dev/null >/dev/null | err_msg "==== You must have the 'diff' program installed for this script ===="

(also below)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, we can also omit the "===="

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, reduced some lines.

fi

# check for 'wget' program
wget --version 2>/dev/null >/dev/null
if [ ! $? ]; then
echo "==== You must have the 'wget' program installed for this script ===="
exit 1
if [ $? -ne 0 ]; then
err_msg "==== You must have the 'wget' program installed for this script ===="
fi

# check for 'msguniq' program
msguniq --version 2>/dev/null >/dev/null
if [ $? -ne 0 ]; then
err_msg "==== You must have the 'gettext' package installed for this script ===="
fi

# make sure we're in the top-level directory
if [ ! -d ./po ]; then
echo "==== No ./po directory in the current working directory ===="
exit 1
err_msg "==== No ./po directory in the current working directory ===="
fi

DOMAIN="buzztrax"
Expand All @@ -57,7 +75,7 @@ do
--to-code=UTF-8; then
mv $PO_FILENAME.utf8 $PO_FILENAME
else
echo "**** $l: conversion from $CHARSET to UTF-8 failed ****"
warn_msg "**** $l: conversion from $CHARSET to UTF-8 failed ****"
fi
fi
if [ -f "po/$l.po" ]; then
Expand All @@ -84,37 +102,48 @@ do
# website, so it's probably a new translation
echo "$l.po: new language"
mv $PO_FILENAME "po/$l.po"
LANGUAGES_UPDATED="$LANGUAGES_UPDATED $l"
LANGUAGES_TO_ADD="$LANGUAGES_TO_ADD $l"
fi
else
rm -f $PO_FILENAME
echo "$l.po: failure (does probably not exist)"
echo "$l.po: failure (probably does not exist yet)"
fi
done

if [ -n "LANGUAGES_UPDATED" ]; then
if [ -n "$LANGUAGES_UPDATED" ] || [ -n "$LANGUAGES_TO_ADD" ]; then
echo "===================================================================="
echo
echo "Language codes updated :$LANGUAGES_UPDATED"
echo "Language codes to git add :$LANGUAGES_TO_ADD"
echo
echo "Source: http://translationproject.org/latest/$DOMAIN/"
echo
if [ -n "$LANGUAGES_TO_ADD" ]; then
if [ -n "$LANGUAGES_UPDATED" ]; then
CMD_STRING="git add"
for d in $LANGUAGES_TO_ADD; do
for l in $LANGUAGES_UPDATED; do
CMD_STRING="$CMD_STRING po/$l.po"
done
CMD_STRING="$CMD_STRING; git commit -m \"add new translations\""
echo "Please run"
CMD_STRING="$CMD_STRING; git commit -m 'po: update translations'"
echo "To commit the updated translations, please run:"
echo
echo " $CMD_STRING"
echo
echo "now and add the following language codes to the po/LINGUAS file:"
echo
fi
if [ -n "$LANGUAGES_TO_ADD" ]; then
echo "Edit 'po/LINGUAS' adding the following new language codes:"
echo
echo " $LANGUAGES_TO_ADD"
echo
CMD_STRING="git add"
for l in $LANGUAGES_TO_ADD; do
CMD_STRING="$CMD_STRING po/$l.po"
done
CMD_STRING="$CMD_STRING po/LINGUAS; git commit -m 'po: add new translations'"
echo "and now add the new translations, please run:"
echo
echo " $CMD_STRING"
echo
echo
fi
echo "===================================================================="
Expand Down
Loading