2014-11-30 14:51:57 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
# Helps find duplicate translation keys in language files
|
|
|
|
|
#
|
2024-02-10 17:26:34 +01:00
|
|
|
# Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
|
|
|
|
# Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
2014-11-30 14:51:57 +01:00
|
|
|
|
2024-02-10 17:26:34 +01:00
|
|
|
exit_code=0
|
2014-11-30 14:51:57 +01:00
|
|
|
# Syntax
|
2024-02-10 17:26:34 +01:00
|
|
|
if [ "$1" != "list" ] && [ "$1" != "fix" ]
|
2014-11-30 14:51:57 +01:00
|
|
|
then
|
2024-01-10 19:47:29 +01:00
|
|
|
echo "Detect duplicate translation keys inside a file (there is no cross file check)."
|
2014-11-30 14:51:57 +01:00
|
|
|
echo "Usage: detectduplicatelangkey.sh (list|fix)"
|
2024-02-10 17:26:34 +01:00
|
|
|
exit_code=1
|
2014-11-30 14:51:57 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2024-02-10 17:26:34 +01:00
|
|
|
ACTION=$1
|
|
|
|
|
|
|
|
|
|
if [ "${ACTION}" = "list" ]
|
2014-11-30 14:51:57 +01:00
|
|
|
then
|
2016-10-11 10:24:02 +02:00
|
|
|
echo "Search duplicate keys into en_US lang files (there is no cross file check)"
|
2024-02-10 17:26:34 +01:00
|
|
|
for file in htdocs/langs/en_US/*.lang
|
2014-11-30 14:51:57 +01:00
|
|
|
do
|
2024-01-10 19:47:29 +01:00
|
|
|
dupes=$(
|
|
|
|
|
sed "s/^\s*//" "$file" | # Remove any leading whitespace
|
|
|
|
|
sed "s/\s*\=/=/" | # Remove any whitespace before =
|
2024-02-10 17:26:34 +01:00
|
|
|
grep -Po "(^.*?)(?==)" | # Non greedy match everything before =
|
|
|
|
|
sort | uniq -d | # Find duplicates
|
|
|
|
|
while IFS= read -r key ; do
|
|
|
|
|
grep -n "^$key" "$file" |
|
|
|
|
|
# Format line to be recognised for code annotation by logToCs.py
|
|
|
|
|
echo "$file:$(cut -d ':' -f 1 | tail -n 1):error:Duplicate '$key'"
|
|
|
|
|
done
|
|
|
|
|
# awk '$0="'"$file"':"$0' # Prefix with filename (for ci)
|
2024-01-10 19:47:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if [ -n "$dupes" ]
|
|
|
|
|
then
|
2024-02-10 17:26:34 +01:00
|
|
|
exit_code=1
|
2024-01-10 19:47:29 +01:00
|
|
|
echo "$dupes"
|
|
|
|
|
fi
|
2014-11-30 14:51:57 +01:00
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# To convert
|
2024-02-10 17:26:34 +01:00
|
|
|
if [ "${ACTION}" = "fix" ]
|
2014-11-30 14:51:57 +01:00
|
|
|
then
|
|
|
|
|
echo Feature not implemented. Please fix files manually.
|
2024-02-10 17:26:34 +01:00
|
|
|
exit_code=1
|
2014-11-30 14:51:57 +01:00
|
|
|
fi
|
2024-02-10 17:26:34 +01:00
|
|
|
|
|
|
|
|
exit $exit_code
|