[TASK] Script to recover lost translations from system extensions 62/41962/3
authorXavier Perseguers <xavier@typo3.org>
Sun, 26 Jul 2015 06:10:02 +0000 (08:10 +0200)
committerXavier Perseguers <xavier@typo3.org>
Sun, 26 Jul 2015 06:13:48 +0000 (08:13 +0200)
Change-Id: I716db5ce51f71fc42cb665b02926ac8196642c0e
Reviewed-on: http://review.typo3.org/41962
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/files/scripts/bin/migration/3-recover-missing-translations [new file with mode: 0755]

diff --git a/typo3/files/scripts/bin/migration/3-recover-missing-translations b/typo3/files/scripts/bin/migration/3-recover-missing-translations
new file mode 100755 (executable)
index 0000000..e7ba71e
--- /dev/null
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+
+. /home/pootle/scripts/etc/pootle.conf
+. /home/pootle/scripts/etc/functions
+
+ORIGIN="pootle@178.79.185.68:/var/www/vhosts/pootle.typo3.org/pootle/po/TYPO3."
+
+# Allow to abort whole script on Ctrl+C
+trap "exit" INT
+
+pushd ${POOTLE_PO} >/dev/null
+
+PROJECTS=$(find . -maxdepth 1 -name TYPO3.core.\* -type d | cut -b3- | sort)
+
+for PROJECT in ${PROJECTS}; do
+       pushd ${PROJECT} >/dev/null
+       echo "[INFO]    Fixing ${PROJECT}"
+       echo "[INFO]    ==================================="
+
+       MAPPING=${POOTLE_PO}/${PROJECT}/.typo3/TYPO3v6.filemapping
+       if [ ! -f "${MAPPING}" ]; then
+               echo "[WARNING] - Mapping not found"
+               continue
+       fi
+
+       LANGUAGES=$(find . -maxdepth 1 -type d | cut -b3- | grep -v templates | grep -v .typo3 | sort)
+       for LANGUAGE in ${LANGUAGES}; do
+               pushd ${LANGUAGE} >/dev/null
+               echo "[INFO]    ${PROJECT} - ${LANGUAGE}"
+
+               FILES=$(find . -maxdepth 1 -name locallang.\*.xlf | cut -b3- | sort)
+               FILES=$(find . -name \*.xlf | cut -b3- | sort)
+               for FILE in ${FILES}; do
+                       echo ${FILE} | egrep -q "^locallang\.[0-9]+\.xlf$"
+                       LEGACY=$?
+
+                       TARGETS=$(cat ${FILE} | grep "<target" | grep -v "<target/>")
+                       if [ -z "${TARGETS}" ]; then
+                               if [ ${LEGACY} -eq 0 ]; then
+                                       TARGET_FILE=$(grep ${FILE} ${MAPPING} | cut -d' ' -f2)
+                                       if [ -z "${TARGET_FILE}" ]; then
+                                               # File does not exist for current TYPO3 version
+                                               continue
+                                       fi
+                               else
+                                       TARGET_FILE=${FILE}
+                               fi
+
+                               echo "[WARNING] - Missing translations for ${FILE}"
+
+                               TMP_NAME="/tmp/$(basename ${TARGET_FILE})"
+                               rm -f ${TMP_NAME}
+
+                               scp -q ${ORIGIN}${PROJECT}/${LANGUAGE}/${TARGET_FILE} ${TMP_NAME} >/dev/null 2>&1
+                               if [ $? -eq 0 ]; then
+                                       grep -q "<target" ${TMP_NAME}
+                                       if [ $? -ne 0 ]; then
+                                               echo "[WARNING] - Old server has no translations either (${TARGET_FILE})"
+                                               rm -f ${TMP_NAME}
+                                               continue
+                                       fi
+
+                                       mv ${TMP_NAME} ${FILE}
+                                       ${POOTLE_MANAGE} update_stores --force --project=${PROJECT} --language=${LANGUAGE} >/dev/null 2>&1
+                               fi
+                       fi
+               done
+
+               popd >/dev/null
+       done
+
+       popd >/dev/null
+done
+
+popd >/dev/null