forked from Blackjacx/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-translation-consistency.sh
executable file
·45 lines (35 loc) · 1.17 KB
/
check-translation-consistency.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Import Global Functionality
. "$(dirname "$0")"/imports.sh --source-only
# Treats spaces correctly in filenames
IFS=$'\n'
# Find files that contain localization keys
ITEMS=( $( find . -name "*.strings" -type f ) )
UNUSED=()
KEYS=()
# Iterate over all localization files
for ITEM in "${ITEMS[@]}"; do
LINES=( $(grep '^\".*\"' "$ITEM") )
# LINES=( $(cat $ITEM | grep '^\".*\"') )
echo "$red$ITEM $blue(${#LINES[@]} Keys)$white"
# iterate over lines of the translation file and collect all keys
for LINE in "${LINES[@]}"; do
KEY=$(echo $LINE|cut -d'"' -f2|cut -d'"' -f1)
KEYS+=("$KEY")
done
done
# sort and uniqueing all keys
KEYS=( $(printf "%s\n" "${KEYS[@]}" | sort -u) )
echo -e "Found $red${#KEYS[@]}$white keys in $red${#ITEMS[@]}$white files!\n"
# Iterate over all keys
for KEY in "${KEYS[@]}"; do
# Find usages of localization keys - ignore paths from .strings files
CMD_FIND="find $(pwd) -name \"*.swift\" -type f ! -path \"*.strings*\" -exec grep -n --quiet \"$KEY\" {} +"
if ! eval "$CMD_FIND"; then
UNUSED+=("$KEY")
fi
done
# Status Reporting
echo -e "The following translation keys are unused:\n"
printf '\t%s\n' "${UNUSED[@]}"
echo