From eea4423a8f8763cc945fbfbf19f2f02f0a55da08 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 6 Aug 2024 12:28:29 +0200 Subject: [PATCH] small improvement: only change POT file if there are real changes --- install/po_gen_installer.sh | 28 ++++++++++++++++++++-------- po_gen.sh | 30 ++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/install/po_gen_installer.sh b/install/po_gen_installer.sh index 5d32206ba..a4f5f2b65 100644 --- a/install/po_gen_installer.sh +++ b/install/po_gen_installer.sh @@ -43,9 +43,12 @@ echo " " # Find all PHP files and create a list in a temporary file find $FOLDERS -name "*.php" > PHPFILESLIST +# Generate a new POT file to a temporary file +TEMP_POT_FILE=$(mktemp) + # Run the xgettext command with various options. Do not change these options to keep the POT/PO files consistent in Wavelog xgettext -F \ - -o $POT_FILE \ + -o $TEMP_POT_FILE \ --from-code=UTF-8 \ --keyword=__ \ --keyword=_ngettext:1,2 \ @@ -57,19 +60,28 @@ xgettext -F \ # After the xgettext command, we don't need the temporary file anymore rm PHPFILESLIST -# Let's edit the header of the POT file -sed -i "1s/.*/# $POT_TITLE_TEXT/" "$POT_FILE" -sed -i "2s/.*/# $POT_COPYRIGHT_TEXT/" $POT_FILE -sed -i "3s/.*/# $POT_LICENCE_TEXT/" $POT_FILE -sed -i '4d' $POT_FILE -sed -i '8d' $POT_FILE +# Let's edit the header of the TEMP_POT_FILE +sed -i "1s/.*/# $POT_TITLE_TEXT/" "$TEMP_POT_FILE" +sed -i "2s/.*/# $POT_COPYRIGHT_TEXT/" "$TEMP_POT_FILE" +sed -i "3s/.*/# $POT_LICENCE_TEXT/" "$TEMP_POT_FILE" +sed -i '4d' "$TEMP_POT_FILE" +sed -i '8d' "$TEMP_POT_FILE" + +# Compare the new POT file with the existing one (excluding the POT Creation Date) +if ! diff -I 'POT-Creation-Date' "$TEMP_POT_FILE" "$POT_FILE" >/dev/null; then + echo "Updating POT file with new translations." + mv "$TEMP_POT_FILE" "$POT_FILE" +else + echo "No changes detected in translations. POT file remains unchanged." + rm "$TEMP_POT_FILE" +fi # Extract the first three lines of the POT file to a temporary file head -n 3 "$POT_FILE" > POT_HEADER # Now we can merge the POT file (PO template) into each found PO file for po in $(find $FOLDERS -name "*.po"); do - msgmerge --update -vv --backup=none --no-fuzzy-matching "$po" $POT_FILE; + msgmerge --update -vv --backup=none --no-fuzzy-matching "$po" "$POT_FILE"; # Replace the first three lines of the PO file with the POT file header sed -i '1,3d' "$po" cat POT_HEADER "$po" > temp.po && mv temp.po "$po" diff --git a/po_gen.sh b/po_gen.sh index af4b758d1..d540390c4 100644 --- a/po_gen.sh +++ b/po_gen.sh @@ -43,9 +43,12 @@ echo " " # Find all PHP files and create a list in a temporary file find $FOLDERS -name "*.php" > PHPFILESLIST +# Generate a new POT file to a temporary file +TEMP_POT_FILE=$(mktemp) + # Run the xgettext command with various options. Do not change these options to keep the POT/PO files consistent in Wavelog xgettext -F \ - -o $POT_FILE \ + -o $TEMP_POT_FILE \ --from-code=UTF-8 \ --keyword=__ \ --keyword=_ngettext:1,2 \ @@ -57,19 +60,30 @@ xgettext -F \ # After the xgettext command, we don't need the temporary file anymore rm PHPFILESLIST -# Let's edit the header of the POT file -sed -i "1s/.*/# $POT_TITLE_TEXT/" "$POT_FILE" -sed -i "2s/.*/# $POT_COPYRIGHT_TEXT/" $POT_FILE -sed -i "3s/.*/# $POT_LICENCE_TEXT/" $POT_FILE -sed -i '4d' $POT_FILE -sed -i '8d' $POT_FILE +# Let's edit the header of the TEMP_POT_FILE file +sed -i "1s/.*/# $POT_TITLE_TEXT/" "$TEMP_POT_FILE" +sed -i "2s/.*/# $POT_COPYRIGHT_TEXT/" "$TEMP_POT_FILE" +sed -i "3s/.*/# $POT_LICENCE_TEXT/" "$TEMP_POT_FILE" +sed -i '4d' "$TEMP_POT_FILE" +sed -i '8d' "$TEMP_POT_FILE" + +# Compare the new POT file with the existing one (excluding the POT Creation Date) +if ! diff -I 'POT-Creation-Date' "$TEMP_POT_FILE" "$POT_FILE" >/dev/null; then + echo "Updating POT file with new translations." + echo " " + mv "$TEMP_POT_FILE" "$POT_FILE" +else + echo "No changes detected in translations. POT file remains unchanged." + echo " " + rm "$TEMP_POT_FILE" +fi # Extract the first three lines of the POT file to a temporary file head -n 3 "$POT_FILE" > POT_HEADER # Now we can merge the POT file (PO template) into each found PO file for po in $(find $FOLDERS -name "*.po"); do - msgmerge --update -vv --backup=none --no-fuzzy-matching "$po" $POT_FILE; + msgmerge --update -vv --backup=none --no-fuzzy-matching "$po" "$POT_FILE"; # Replace the first three lines of the PO file with the POT file header sed -i '1,3d' "$po" cat POT_HEADER "$po" > temp.po && mv temp.po "$po"