Skip to content

Commit

Permalink
Update translation scripts to avoid committing messages.pot
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthayhurst committed Aug 12, 2023
1 parent 4590633 commit becf2bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ release:
$(MAKE) build
$(MAKE) check
translations:
@./scripts/update-po.sh -a
@BUILD_DIR=$(BUILD_DIR) ./scripts/update-po.sh -a
gtk4:
@$(MAKE) $(UI_FILES)
$(UI_FILES):
Expand Down
117 changes: 0 additions & 117 deletions extension/po/messages.pot

This file was deleted.

17 changes: 12 additions & 5 deletions scripts/update-po.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#This script generates the latest '.po' file(s) from the source
#Usage: 'update-po.sh -l <LANG-CODE>', use '-a' to update all '.po' files

#Create a new translation from 'po/messages.pot'
#Create a new translation from 'build/messages.pot'
promptNewTranslation() {
if [[ -n "$1" ]]; then
echo -n "The translation for '$1' does not exist, do you want to create it? [Y/n] "
read -r reply

if [[ "$reply" = "Y" ]] || [[ "$reply" = "y" ]]; then
msginit --input=po/messages.pot --locale="$1" --output-file="po/$1.po"
msginit --input="../$BUILD_DIR/messages.pot" --locale="$1" --output-file="po/$1.po"
#Add copyright info
sed -i "2s/.*/# Copyright (C) $(date +%Y) Stuart Hayhurst/" "po/$1.po"
fi
Expand All @@ -19,16 +19,23 @@ promptNewTranslation() {
#Update translation file $1
updateTranslation() {
echo -n "Updating '$1': "
msgmerge --previous -U --quiet "$1" po/messages.pot
msgmerge --previous -U --quiet "$1" "../$BUILD_DIR/messages.pot"
msgfmt --check --verbose --output-file=/dev/null "$1"
}

#Change to repository root and exit on failure
set -e
cd "$( cd "$( dirname "$0" )" && pwd )/.." || exit 1
cd "extension" || exit 1

../scripts/update-pot.sh
#Set build directory if missing, and create it
if [[ "$BUILD_DIR" == "" ]]; then
BUILD_DIR="build"
fi
mkdir -p "$BUILD_DIR"

#Generate pot file and swap to extension source dir
./scripts/update-pot.sh
cd "extension" || exit 1

if [[ "$1" == "-l" ]]; then #Update / create one specific '.po' file
#Check if a valid language code was given
Expand Down
19 changes: 12 additions & 7 deletions scripts/update-pot.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#!/bin/bash
#This script scans the source code for any translatable strings and updates the po/messages.pot file accordingly
#This script scans the source code for any translatable strings and create the build/messages.pot

#Change to repository root and exit on failure
set -e
cd "$( cd "$( dirname "$0" )" && pwd )/.." || exit 1
cd "extension" || exit 1

#Set build directory if missing, and create it
if [[ "$BUILD_DIR" == "" ]]; then
BUILD_DIR="build"
fi
mkdir -p "$BUILD_DIR"

#Update the template file with the strings from the source files
xgettext --from-code=UTF-8 \
--add-comments=Translators \
--copyright-holder="Stuart Hayhurst" \
--package-name="privacy-menu-extension" \
--output=po/messages.pot \
-- *.js ui/*/*.ui
--output="$BUILD_DIR/messages.pot" \
-- extension/*.js extension/ui/*/*.ui

#Replace some lines of the header with our own
sed -i '1s/.*/# <LANGUAGE> translation for the Privacy Quick Settings GNOME Shell Extension./' po/messages.pot
sed -i "2s/.*/# Copyright (C) $(date +%Y) Stuart Hayhurst/" po/messages.pot
sed -i '17s/CHARSET/UTF-8/' po/messages.pot
sed -i '1s/.*/# <LANGUAGE> translation for the Privacy Quick Settings GNOME Shell Extension./' "$BUILD_DIR/messages.pot"
sed -i "2s/.*/# Copyright (C) $(date +%Y) Stuart Hayhurst/" "$BUILD_DIR/messages.pot"
sed -i '17s/CHARSET/UTF-8/' "$BUILD_DIR/messages.pot"

echo "Generated translation list"

0 comments on commit becf2bc

Please sign in to comment.