new: setup translations

This commit is contained in:
2026-10-09 17:52:48 -04:00
parent 23a44aa210
commit ffe0a54cbd
13 changed files with 507 additions and 96 deletions
+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
# janky aaah
domain=$(sed -n '/^\[package\]/,/^\[/s/^name = "\(.*\)"$/\1/p' Cargo.toml)
version=$(sed -n '/^\[package\]/,/^\[/s/^version = "\(.*\)"$/\1/p' Cargo.toml)
[ -n "$domain" ] || { echo "error: could not find the package name in Cargo.toml" >&2; exit 1; }
dir=assets/translations
pot=$dir/$domain.pot
for tool in slint-tr-extractor msginit msgmerge msgcat; do
command -v "$tool" > /dev/null || { echo "error: '$tool' is not installed, see docs/TRANSLATIONS.md" >&2; exit 1; }
done
fresh=$(mktemp)
trap 'rm -f "$fresh"' EXIT
find ui -name '*.slint' | LC_ALL=C sort | xargs slint-tr-extractor --package-name "$domain" --package-version "$version" -o "$fresh"
msgcat --no-wrap "$fresh" > /dev/null || { echo "error: the extracted template is not valid, is a translator comment longer than 76 characters?" >&2; exit 1; }
if [ -f "$pot" ] && diff -q <(grep -v '^"POT-Creation-Date:' "$pot") <(grep -v '^"POT-Creation-Date:' "$fresh") > /dev/null; then
echo "$pot is up to date"
else
cp "$fresh" "$pot"
echo "updated $pot"
fi
for lang in "$@"; do
po=$dir/$lang/LC_MESSAGES/$domain.po
if [ -e "$po" ]; then
echo "$po already exists" >&2
else
mkdir -p "$(dirname "$po")"
msginit --no-translator --locale="$lang" --input="$pot" --output-file="$po"
fi
done
for po in "$dir"/*/LC_MESSAGES/"$domain".po; do
[ -e "$po" ] || continue
msgmerge --update --backup=none --quiet "$po" "$pot"
echo "merged into $po"
done