#!/bin/bash
#用途:自動(dòng)生成本地化方法聲明和實(shí)現(xiàn)
#文件名:localize.sh
#參數(shù):本地化數(shù)據(jù)文件(txt文件每行三列以Tab分隔分別為methodName,key和comment)
#使用方法:./localize.sh test.txt
if [ $# -ne 1 ];
then
echo "Usage: $0 filename";
exit -1
fi
cat > MethodStatement.txt <<_EOF_
/*!
@brief comment
*/
+ (NSString *)method;
_EOF_
cat > MethodImplementation.txt <<_EOF_
+ (NSString *)method {
return NSLocalizedString(@"key", @"comment");
}
_EOF_
filename=$1
#如果stat.txt文件存在就刪除它
if [[ -f "stat.txt" ]]; then
rm stat.txt
fi
#如果impl.txt文件存在就刪除它
if [[ -f "impl.txt" ]]; then
rm impl.txt
fi
cat $filename | while read line
do
method=`echo $line | awk '{print $1 }'`
key=`echo $line | awk '{print $2 }'`
comment=`echo $line | awk '{print $3 }'`
echo $method
echo $key
echo $comment
#生成.h中的方法聲明
sed "s/comment/$comment/" MethodStatement.txt > stat_temp.txt
sed "s/method/$method/" stat_temp.txt >> stat.txt
rm stat_temp.txt
#生成.m中的方法實(shí)現(xiàn)
sed "s/method/$method/" MethodImplementation.txt > impl_temp.txt
sed "s/key/$key/" impl_temp.txt >> impl_temp_2.txt
sed "s/comment/$comment/" impl_temp_2.txt >> impl.txt
rm impl_temp.txt
rm impl_temp_2.txt
done