🔧(scalingo) compile translation files at deploy time

The .mo files are gitignored so they must be generated
during the Scalingo post-build step to ensure translations
are available in production.
This commit is contained in:
Nathan Vasse
2026-03-31 14:47:31 +02:00
parent bcae25191e
commit b84ef76892
2 changed files with 53 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ and this project adheres to
- 🐛(backend) fix hard delete of files created by other users
- 🐛(backend) handle race condition on concurrent LinkTrace creation
- 🐛(frontend) fix React SVG attributes in AddFolderButton
- 🔧(scalingo) compile translation files at deploy time
## [v0.15.0] - 2026-03-16

52
bin/post_compile Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
# Compile translation .mo files (gitignored, must be generated at build time)
#
# 1. We cannot put this task in the scalingo_postbackend script because it requires
# python environment, which is not available in the scalingo_postbackend script.
# This script is executed by the python buildpack, that's why the python environment
# is available.
#
# 2.According to this doc: https://doc.scalingo.com/languages/python/django/start
# See "Compile .mo Message Translation File" section, we should be able to
# run "python manage.py compilemessages" out of the box.
# But it does not work ... it requires the gettext package to be installed.
# And it appears that the documentation is outdated because the gettext package
# is not installed by default.
# So we install it manually using the same technique as the Scalingo apt-buildpack.
# This is why we have this script.
# The strange way of installing gettext is because the deploy user do not have
# root privileges.
set -o errexit # always exit on error
set -o pipefail # don't ignore exit codes when piping output
# Install gettext without root (same technique as Scalingo apt-buildpack)
APT_CACHE_DIR="$(mktemp -d)"
APT_STATE_DIR="$(mktemp -d)"
mkdir -p "${APT_CACHE_DIR}/archives/partial" "${APT_STATE_DIR}/lists/partial"
APT_OPTIONS=("-o" "debug::nolocking=true"
"-o" "dir::cache=${APT_CACHE_DIR}"
"-o" "dir::state=${APT_STATE_DIR}")
echo "Downloading gettext package"
apt-get "${APT_OPTIONS[@]}" update -qq
apt-get "${APT_OPTIONS[@]}" -y -qq -d install --reinstall gettext
mkdir -p .apt
for DEB in "${APT_CACHE_DIR}/archives/"*.deb; do
dpkg -x "$DEB" .apt/
done
APT_DIR="$(pwd)/.apt"
export PATH="${APT_DIR}/usr/bin:$PATH"
export LD_LIBRARY_PATH="${APT_DIR}/usr/lib:${APT_DIR}/usr/lib/x86_64-linux-gnu:${APT_DIR}/lib:${APT_DIR}/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}"
# Compile .mo translation files (gitignored, must be generated at build time)
echo "Compiling translation .mo files"
DJANGO_CONFIGURATION=Build python manage.py compilemessages --ignore=".venv/**/*"
# Clean up
rm -rf .apt "${APT_CACHE_DIR}" "${APT_STATE_DIR}"