2
0
forked from Wavyzz/dolibarr
Files
dolibarr-fork/dev/tools/fixduplicatelanglines.sh
MDW 16f723f0ba Qual Language scripts fixed/updated (#28101)
* Qual: Fix/extend language scripts, integrate in pre-commit

Updated scripts to comply with shellscript.
Integrated one in pre-commit that seems useful.

* Qual: Find duplicate lang keys

* Add line numbers (to allow annotation)

* Fix fixaltlanguages.sh and add to pre-commit

* Make historical language checks 'manual' in 'pre-commit'
2024-02-10 17:26:34 +01:00

48 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Recursively deduplicate file lines on a per file basis
# Useful to deduplicate language files
#
# Needs awk 4.0 for the inplace fixing command
#
# Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
# Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
exit_code=0
# Check arguments
if [ "$1" != "list" ] && [ "$1" != "fix" ]
then
echo "Find exact duplicated lines into file (not cross file checking)"
echo "Usage: $(basename "$0") [list|fix]"
exit_code=1
fi
ACTION=$1
# To detect
if [ "${ACTION}" = "list" ] || [ "${ACTION}" = "fix" ]
then
echo "Search duplicate lines for lang en_US"
echo ""
for file in htdocs/langs/en_US/*.lang
do
if [ "$(sort "$file" | grep -v -P '^#?$' | uniq -d | wc -l)" -gt 0 ]
then
sort "$file" | grep -v -P '^#?$' | uniq -d | awk '$0="'"$file"':"$0'
exit_code=1
fi
done
fi
# To fix
if [ "${ACTION}" = "fix" ]
then
echo "Fix duplicate line for lang en_US"
# shellcheck disable=2016
for file in htdocs/langs/en_US/*.lang ; do
awk -i inplace ' !x[$0]++' "$file"
done
fi
exit $exit_code