How to find duplicate keys in localizable.strings files automatically?

When using localizable.strings with many entries in an Xcode project, sooner or later you can use the key more than once. Can Xcode find this case and issue a warning about it?

Apple Resource Programming mentions the genstrings tool, but usually you don't use it yourself in Xcode. So, how can I let Xcode detect duplicate keys in such files without manually starting genstrings?

Note: thanks: in order to earn bonuses, the solution must be fully integrated with Xcode if it uses external resources, such as scripts, that is, it must work with the input files specified in Xcode in the case of duplicates and should not cause false positives, such like empty lines or comments.

+6
source share
3 answers

cut -d' ' -f1 Localizable.strings | sort | uniq -c

enter this command into the terminal and you will get a list that says how often each key is used.

use -d instead of -c and you only get duplicates

script:

 #!/bin/bash c=`expr $SCRIPT_INPUT_FILE_COUNT - 1` for i in $(seq 0 $c) do var="SCRIPT_INPUT_FILE_$i" FILENAME=${!var} DUPES=`cut -d' ' -f1 "$FILENAME" | sort | uniq -d` while read -r line; do if [[ $line == "\""* ]] ; then echo "warning: $line used multiple times -" fi done <<< "$DUPES" done 

screenshot

+13
source

cut -d '=' -f1 Localizable.strings | sort | uniq -d

You are looking for phrases separated by an equal sign, not the first word on each line.

0
source
 more Filename.strings | tr -d ' ' | sort | uniq -d | grep -v '^$' 
-1
source

Source: https://habr.com/ru/post/970578/


All Articles