例如.一个键中没有拼写错误,以至于NSLocalizedString找不到它正在寻找的键?
解决方法@H_301_13@ 好的,我写了一个bash脚本来完成上述 *** 作.这里是.这花了我几个小时所以如果你愿意,不要忘记向我投票.随意做出改进等.我添加了一些评论,暗示了潜在的改进.#!/bin/sh# VerNSLocalizedStringswhile getopts "vsl:" arg; do case $arg in v) verbose="yes" ;; s) stopOnMissing="yes" ;; l) lang=$OPTARG ;; esacdoneif [[ -z $lang ]] then lang="en"fisearchDir=$lang.lprojfileFound=`ls . | grep $searchDir`if [[ -z $fileFound ]]then echo "dir "$searchDir" not found." exitfifileFound=`ls $searchDir/ | grep strings`if [[ -z $fileFound ]]then echo "No .strings files found in dir "$searchDir"." exitfiecho "Verifying NSLocalizationStrings in "$searchDir # Get all the NSLocalizedString Commandsoutput=$(grep -R NSLocalizedString . --include="*.m")# Go thru the NSLocalizedString commands line for linecount=$(( 0 ))missing=$(( 0 ))unusable=$(( 0 ))OIFS="${IFS}"NIFS=$'\n'IFS="${NIFS}"for liNE in ${output} ; do IFS="${OIFS}" # Now extract the key from it # admittedly this only works if there are no line breaks between # NSLocalizedStrings and the entire key,# but it accounts for the keys it Couldn't IDentify. quotes=`echo $liNE | awk -F\" '{ for(i=2; i<=NF; i=i+2){ a = a"\""$i"\"""^";} {print a; a="";}}'` key=`echo $quotes | cut -f1 -d"^"` # If we Couldn't find the key then flag problem if [[ -z $key ]] then (( unusable += 1 )) echo "Couldn't extract key: " $liNE if [ -n "$stopOnMissing" ] then break else continue fi fi # I don't kNow how grep works regarding length of string,only that # if the string is too long then it doesn't find it in the file keyLength=$(echo ${#key}) if [ $keyLength -gt 79 ] then (( unusable += 1 )) echo "Key too long ("$keyLength"): " $key if [ -n "$stopOnMissing" ] then break else continue fi fi # It would be nice if this were a regular Expression that allowed as many # spaces as you want,even a line break then forced the quotes on the # other sIDe of the equal sign. keyString=$key" =" # Search for the key found=$(iconv -sc -f utf-16 -t utf8 $searchDir/*.strings | grep "$keyString") # damned if I kNow why some strings files are utf-16 and others are utf8 if [[ -z $found ]] then found=$(grep -r "$keyString" $searchDir/ --include=*.strings) fi # analyze the result if [[ -z $found ]] then (( missing += 1 )) echo "Missing: " $key "\n from: " $liNE if [ -n "$stopOnMissing" ] then break fi else if [ -n "$verbose" ] then echo "found: " $key fi fi (( count += 1 )) IFS="${NIFS}" doneIFS="${OIFS}"# It would also be nice if it went the other way and IDentifIEd # extraneous unused items in the strings files. But# I've spent enough time on this for Nowecho $count " keys analyzed"echo $unusable " keys Could not be determined"echo $missing " keys missing"总结
以上是内存溢出为你收集整理的在xcode中是否有办法验证所有NSLocalizedStrings的密钥?全部内容,希望文章能够帮你解决在xcode中是否有办法验证所有NSLocalizedStrings的密钥?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)