如何自动在 localizable.strings 文件中查找重复键? [英] How to find duplicate keys in localizable.strings files automatically?
问题描述
当在 XCode 项目中使用包含多个条目的 localizable.strings 时,您迟早可能会多次使用一个键.是否可以让 XCode 找到该案例并发出警告?
When using localizable.strings with many entries in your XCode project you sooner or later may use a key more than once. Is it possible to let XCode find that case and issue a warning about it?
Apple 的 资源编程 提到genstrings 工具,但通常您自己不会在 XCode 中使用它.那么,如何让 XCode 在不手动运行 genstrings 的情况下检测此类文件中的重复键?
Apple's Resource Programming mentions the genstrings tool, but usually you don't use that yourself in XCode. So, how can I let XCode detect duplicate keys in such files without manually running genstrings?
赏金说明:要获得赏金,解决方案必须与 XCode 完全集成,如果它使用脚本等外部资源,即必须使用 XCode 中提供的输入文件,将构建标记为失败在重复的情况下,不得触发空行或注释等误报.
Bounty note: to earn the bounty a solution must fully integrate with XCode if it uses external resources like scripts, that is, it must work with input files given in XCode, mark a build as fail in case of duplicates and must not trigger for false positives like empty lines or comments.
推荐答案
cut -d' ' -f1 Localizable.strings |排序 |uniq -c
在终端中输入这个命令,你会得到一个列表,说明每个键的使用频率.
type this command in the terminal and you get a list saying how often each key is used.
使用 -d 而不是 -c 只会得到重复项
#!/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
这篇关于如何自动在 localizable.strings 文件中查找重复键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!