matrix-docker-ansible-deploy/i18n/bin/extract-translation-templates.sh
Suguru Hirahara 1636c49134
Start adopting REUSE on files for a brand new subproject (translation)
REUSE is an initiative by FSFE, which intends to make licensing easier with best practices to display legal information through comment headers on source files that can be easily human and machine readable.

Because these files are new and translation shall involve a lot of people as copyright holders, now is the best time to adopt REUSE. As a first implementation, this commit intentionally limits the scope to i18n directory.

Cherry-picked from c737ed0612 and a2445af6d0

Signed-off-by: Suguru Hirahara <acioustick@noreply.codeberg.org>
2024-12-20 19:08:12 +09:00

37 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# SPDX-FileCopyrightText: 2024 Slavi Pantaleev <slavi@devture.com>
# This script extracts translation templates (original English strings) into the `translation-templates/` directory.
# These templates are later used to generate locale files for each language in the `locales/` directory.
#
# By default `sphinx-build` extracts the templates into a `build/gettext` directory, while we'd like to have them in the `translation-templates/` directory.
# To avoid the `POT-Creation-Date` information in templates being updated every time we extract them,
# we restore the `translation-templates/` directory to the `build/gettext` directory before running the script.
set -euxo pipefail
base_path="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# Restore the `translation-templates/` directory to the `build/gettext` directory
if [ -d ${base_path}/i18n/build ]; then
rm -rf ${base_path}/i18n/build
fi
mkdir -p ${base_path}/i18n/build
cp -r ${base_path}/i18n/translation-templates ${base_path}/i18n/build/gettext
# Extract translation templates from the documentation into the `build/gettext` directory
sphinx-build -M gettext ${base_path} ${base_path}/i18n/build
# Clean up the build directory
rm -rf ${base_path}/i18n/build/gettext/.doctrees
# Update the `translation-templates/` directory with the new templates
if [ -d ${base_path}/i18n/translation-templates ]; then
rm -rf ${base_path}/i18n/translation-templates
fi
mv ${base_path}/i18n/build/gettext ${base_path}/i18n/translation-templates
# Get rid of the `build` directory
rmdir ${base_path}/i18n/build