Now, my instance downloads translation data from Transifex weekly. I’d share my recipe here. I hope it will help you. Please do not hesitate to ask if anything is not clear.
My instance runs on Ubuntu 16.04 LTS on Oracle VirtualBox VM, for reference.
Preparation
First of all, please define your favorite language as an environment variable. In this instructions, I choose Japanese (ja_JP
) for instance.
INDICO_TARGET_LANGUAGE=ja_JP
export INDICO_TARGET_LANGUAGE
Timer settings
cat > /etc/systemd/system/update-indico-translation.service <<'EOF'
[Unit]
Description=Indico translation update script
RefuseManualStart=no
RefuseManualStop=yes
[Service]
Type=oneshot
ExecStart=/opt/indico/etc/update-indico-translation 2.7 ${INDICO_TARGET_LANGUAGE}
User=indico
Group=nginx
EOF
cat > /etc/systemd/system/update-indico-translation.timer <<'EOF'
[Unit]
Description=Update Indico translation data weekly
[Timer]
OnCalendar=weekly
Persistent=true
Unit=update-indico-translation.service
[Install]
WantedBy=timers.target
EOF
Then, let’s enable the timer.
systemctl start update-indico-translation.timer
systemcrl enable update-indico-translation.timer
Please check if your timer is activated.
systemctl list-timers
Then, please continue with indico
user previlege.
su - indico
Obtain your Transifex API token
Please log in to Transifex, open user settings, and get your API token.
Then, please save the token as /opt/indico/.tx-api-token
.
# You definitely want to change the access permissions of it, don't you?
chmod 600 /opt/indico/.tx-api-token
The script
Do not use cat
here, since variables are expanded on the fly if you do so. Please use your favorite editor.
#!/bin/sh
python_version="$1"
lang="$2"
api_token="$(cat /opt/indico/.tx-api-token)"
work_dir="${TMPDIR}/$(mktemp -d)"
cd "${work_dir}"
echo "Updating Indico (Python ${python_version}) translation resources for ${lang}..."
fetch_language_resource() {
package="$1"
component="$2"
package_dir="/opt/indico/.venv/lib/python${python_version}/site-packages/${package}/"
if [ -d "${package_dir}" ]; then
echo "The ${package} package is found. Downloading translation resources for ${lang}..."
locale_dir="${package_dir}/translations/${lang}/LC_MESSAGES/"
mkdir -p "${locale_dir}"
echo "Downloading messages.po..."
py_resource_url="https://www.transifex.com/api/2/project/indico/resource/${component}-messages/translation/${lang}/?file"
py_status_code=$(curl -s -L --user "api:${api_token}" -X GET "${py_resource_url}" -o "messages.po" -w "%{http_code}")
if [ $? = 0 ] && [ "${py_status_code}" = "200" ]; then
msgfmt messages.po
mv messages.po messages.mo "${locale_dir}"
else
echo "Failed to download ${lang} messages.po for ${package}."
if [ -f messages.po ]; then
rm -f messages.po
fi
fi
echo "Downloading messages-js.po..."
js_resource_url="https://www.transifex.com/api/2/project/indico/resource/${component}-messages-js/translation/${lang}/?file"
js_status_code=$(curl -s -L --user "api:${api_token}" -X GET "${js_resource_url}" -o "messages-js.po" -w "%{http_code}")
if [ $? = 0 ] && [ "${js_status_code}" = "200" ]; then
mv messages-js.po "${locale_dir}"
else
echo "Failed to download ${lang} messages-js.po for ${package}."
if [ -f messages-js.po ]; then
rm -f messages-js.po
fi
fi
fi
}
fetch_language_resource indico core
fetch_language_resource indico_chat chat
fetch_language_resource indico_importer importer
fetch_language_resource indico_importer_invenio importer-invenio
fetch_language_resource indico_livesync livesync
fetch_language_resource indico_livesync_invenio livesync-invenio
fetch_language_resource indico_payment_manual payment-manual
fetch_language_resource indico_payment_paypal payment-paypal
fetch_language_resource indico_piwik piwik
fetch_language_resource indico_search search
fetch_language_resource indico_vc_vidyo vc-vidyo
echo "Reloading Indico..."
touch /opt/indico/web/indico.wsgi
cd
rm -rf "${work_dir}"
echo "Finished updating Indico translation resources."
I assume that you saved it at /opt/indico/etc/update-indico-translation
in the description below. Please do not forget to add an executable bit to the script.
chmod +x /opt/indico/etc/update-indico-translation
Done!
Let’s update translations on Transifex and reload the page next week!