#!/bin/bash
#用途:自动生成本地化方法声明和实现
#文件名:localize.sh
#参数:本地化数据文件(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中的方法实现
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