Skip to content
Snippets Groups Projects
Commit ccd05c6d authored by Robert Lange's avatar Robert Lange
Browse files

refs #18047 [finc] optimize i18n merging script

* add help and additional consistency checks
* ignore empty lines
parent 8058567d
No related merge requests found
......@@ -20,14 +20,34 @@
# this script merges token files and removes unused / duplicate tokens with parent and target translation file *.ini
# assumes You are in projects base dir
# if new translations are on alpha, first copy files via:
# scp -r [user]@139.18.19.237:/usr/local/vufind/[instance]/[issue_number]/data/i18n/languages /[path_to_instance_directory]/data/i18n/languages
Help()
{
# Display Help
echo "Usage: $0 path/to/language/with/new/tokens path/to/language/file/of/instance [path/to/parent/file/of/instance]"
echo "example command 1: \"devops/i18n-merge.sh data/i18n/languages/de.ini de_zi4/languages/de.ini local/languages/de.ini\"";
echo "if new translations are on alpha, first copy files via: scp -r [user]@139.18.19.237:/usr/local/vufind/[instance]/[issue_number]/data/i18n/languages /[path_to_instance_directory]/data/i18n/languages"
}
while getopts ":h" option; do
case $option in
h) # display Help
Help
exit;;
\?) # incorrect option
echo "Error: Invalid option"
exit 1;
esac
done
CACHE_FILE=$1; INSTANCE_FILE=$2; PARENT_FILE=$3;
HAS_ERROR=0;
if [ -z "$CACHE_FILE" ] || [ -z "$INSTANCE_FILE" ]; then
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
HAS_ERROR=1
echo "Usage: $0 path/to/language/with/new/tokens path/to/language/file/of/instance [path/to/parent/file/of/instance]"
echo "example command 1: \"devops/i18n-merge.sh data/i18n/languages/de.ini de_zi4/languages/de.ini local/languages/de.ini\"";
Help
exit 1;
else
if [ ! -f "$CACHE_FILE" ]
then
......@@ -38,6 +58,12 @@ else
then
echo "Language File "$INSTANCE_FILE" does not exist on your filesystem."; HAS_ERROR=1;
fi
if [ ${CACHE_FILE##*/} != ${INSTANCE_FILE##*/} ]
then
echo "Cache file "$CACHE_FILE" and language file "$INSTANCE_FILE" must have same file name.";
HAS_ERROR=1;
fi
fi
if [ -z "$CACHE_FILE" ]; then
......@@ -45,11 +71,21 @@ if [ -z "$CACHE_FILE" ]; then
echo "Parent Language File "$PARENT_FILE" does not exist on your filesystem.";
HAS_ERROR=1;
fi
if [ ${CACHE_FILE##*/} != ${PARENT_FILE##*/} ]; then
echo "Cache file "$CACHE_FILE" and parent file "$PARENT_FILE" must have same file name.";
HAS_ERROR=1;
fi
fi
if [ ! -z "$PARENT_FILE" ]; then
if [ ${INSTANCE_FILE##*/} != ${PARENT_FILE##*/} ]; then
echo "Instance file "$INSTANCE_FILE" and parent file "$PARENT_FILE" must have same file name.";
HAS_ERROR=1;
fi
fi
if [ $HAS_ERROR = 1 ]
then
#echo "exit 1: aborting"
exit 1;
fi
......@@ -58,10 +94,12 @@ declare -A newTokens
declare -a newTokensOrder
while IFS= read -r line || [ -n "$line" ] # handle possible missing newline in last line
do
key=$(echo "$line" | awk -F: '{ st = index($0,"=");print substr($0,0,st-1)}')
value=$(echo "$line" | awk -F: '{ st = index($0,"=");print substr($0,st+1)}')
newTokens["$key"]="$value"
newTokensOrder+=("$key");
if [ ! -z "$line" ]; then # ignore empty lines
key=$(echo "$line" | awk -F: '{ st = index($0,"=");print substr($0,0,st-1)}')
value=$(echo "$line" | awk -F: '{ st = index($0,"=");print substr($0,st+1)}')
newTokens["$key"]="$value"
newTokensOrder+=("$key");
fi
done < $CACHE_FILE
echo "Reading and minify existing tokens from $INSTANCE_FILE"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment