2
0
forked from Wavyzz/dolibarr
Files
dolibarr-fork/dev/tools/fixaltlanguages.sh
MDW c885c6917e Qual: Ignore most shellcheck annotations, fix some (#27452)
# Qual: Ignore most shellcheck annotations, fix some

Most shellcheck annotations are ignored - this is to make sure that ci
can work for existing scripts.

Some fixes were applied.

pre-commit script was beautyfied by temporarily suppressing the IFS= expression on 2 lines.
2024-01-12 21:03:08 +01:00

92 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
# Recursively deduplicate file lines on a per file basis
# Useful to deduplicate language files
#
# Needs awk 4.0 for the inplace fixing command
#
# Raphaël Doursenaud - rdoursenaud@gpcsolutions.fr
# shellcheck disable=2006,2027,2044,2045,2046,2086,2155,2166,2268
# Syntax
if [ "x$1" != "xlist" -a "x$1" != "xfix" ]
then
echo "Scan alternate language files and remove entries found into parent file"
echo "Usage: fixaltlanguages.sh (list|fix) (all|file.lang) [xx_XX]"
exit
fi
if [ "x$2" = "x" ]
then
echo "Scan alternate language files and remove entries found into parent file"
echo "Usage: fixaltlanguages.sh (list|fix) (all|file.lang) [xx_XX]"
exit
fi
# To detect
if [ "x$1" = "xlist" ]
then
echo Feature not available
fi
# To fix
if [ "x$1" = "xfix" ]
then
for dir in `find htdocs/langs/$3* -type d`
do
dirshort=`basename $dir`
#echo $dirshort
export aa=`echo $dirshort | nawk -F"_" '{ print $1 }'`
export bb=`echo $dirshort | nawk -F"_" '{ print $2 }'`
aaupper=`echo $dirshort | nawk -F"_" '{ print toupper($1) }'`
if [ $aaupper = "EN" ]
then
aaupper="US"
fi
if [ $aaupper = "EL" ]
then
aaupper="GR"
fi
if [ $bb = "EG" ]
then
aaupper="SA"
fi
if [ $bb = "IQ" ]
then
aaupper="SA"
fi
bblower=`echo $dirshort | nawk -F"_" '{ print tolower($2) }'`
echo "***** Process language "$aa"_"$bb
if [ "$aa" != "$bblower" -a "$dirshort" != "en_US" ]
then
reflang="htdocs/langs/"$aa"_"$aaupper
echo $reflang" "$aa"_"$bb != $aa"_"$aaupper
# If $reflang is a main language to use to sanitize the alternative file
if [ -d $reflang ]
then
if [ $aa"_"$bb != $aa"_"$aaupper ]
then
echo "***** Search original into "$reflang
echo $dirshort is an alternative language of $reflang
echo ./dev/translation/strip_language_file.php $aa"_"$aaupper $aa"_"$bb $2
./dev/translation/strip_language_file.php $aa"_"$aaupper $aa"_"$bb $2
for fic in `ls htdocs/langs/${aa}_${bb}/*.delta`; do f=`echo $fic | sed -e 's/\.delta//'`; echo $f; mv $f.delta $f; done
for fic in `ls htdocs/langs/${aa}_${bb}/*.lang`;
do f=`cat $fic | wc -l`;
#echo $f lines into file $fic;
if [ $f = 1 ]
then
echo "Only one line remaining into file '$fic', we delete it";
rm $fic
fi;
done
fi
fi
fi
done;
fi