Tizen 2.0 Release
[apps/home/ug-memo-efl.git] / scripts / string.sh
1 SYS_MO="$HOME/sbs/target-armel/usr/share/locale/en/LC_MESSAGES/sys_string.mo"
2 APP_MO="$HOME/sbs/target-armel/opt/apps/com.samsung.memo/res/locale/en/LC_MESSAGES/memo.mo"
3 TEMP_STR="./temp"
4 IN="str.in"
5 APP_NAME="memo"
6
7 declare -a SYS_ID
8 declare -a APP_ID
9 declare -a CUSTOM_ID
10
11 out=../include/"$APP_NAME""_string.h"
12 rm -fr $out
13
14 sbs -et apt-get install sys-string-0 -y --force-yes
15
16 function get_str_id () {
17     local str=$1
18     local mo=$2
19     local result=""
20     if [[ -e $mo ]] ; then
21         result=`msgunfmt $mo | grep "\"$str\"" -B 1 | head -n 1 | awk '{print $2}'`
22     fi
23     echo $result
24 }
25
26 function get_tmp_id () {
27     local str=$1
28     local result=""
29     if [[ -e $TEMP_STR ]] ; then
30         result=`cat $TEMP_STR | grep "$str" -A 1 | tail -n 1 | awk '{print $1}'`
31     fi
32     echo $result
33 }
34
35 function gen_id () {
36     local prefix=$1
37     local str=$2
38     local id=$prefix`echo $str | tr a-z A-Z | sed "s/ /_/g" | sed "s/?//g" | sed "s/%//g"`
39     echo $id
40 }
41
42 function dump () {
43     local dest=$1
44     local str=$2
45     printf "$str\n" >> $dest
46 }
47
48 #copy right
49 cat ./copyright > $out
50 dump $out ""
51 dump $out "#ifndef __MEMO_STRING_H__"
52 dump $out "#define __MEMO_STRING_H__"
53
54 LINES=`cat $IN |wc -l`
55 for (( i=1; i<=$LINES; i++ )) ; do
56     string=`cat $IN | sed -n "$i p"`
57     sys_id=$(get_str_id "$string" "$SYS_MO")
58     app_id=$(get_str_id "$string" "$APP_MO")
59     tmp_id=$(get_tmp_id "$string")
60     if [ "$sys_id" != "" ] ; then
61         SYS_ID[${#SYS_ID[@]}]=$(gen_id "MEMO_I18N_" "$string") #append id to array
62         SYS_ID[${#SYS_ID[@]}]="dgettext(\"sys_string\", $sys_id) /* $string */" #append def to array
63     elif [ "$app_id" != "" ] ; then
64         APP_ID[${#APP_ID[@]}]=$(gen_id "MEMO_I18N_" "$string")
65         APP_ID[${#APP_ID[@]}]="dgettext(\"memo\", $app_id) /* $string */"
66     elif [ "$tmp_id" != "" ] ; then
67         CUSTOM_ID[${#CUSTOM_ID[@]}]=$(gen_id "MEMO_I18N_" "$string")
68         CUSTOM_ID[${#CUSTOM_ID[@]}]="dgettext(\"memo\", \"$tmp_id\") /* $string */"
69     else
70         CUSTOM_ID[${#CUSTOM_ID[@]}]=$(gen_id "MEMO_I18N_" "$string")
71         CUSTOM_ID[${#CUSTOM_ID[@]}]="_(\"$string\") /* $string */"
72     fi
73 done
74
75 #dump results
76 dump $out ""
77 dump $out "/* system string */"
78 for (( i=0; i<${#SYS_ID[@]} ; i+=2 )) ; do
79     printf "#define %-36s %s\n" ${SYS_ID[$i]} "${SYS_ID[$i+1]}">> $out
80 done
81 dump $out ""
82 dump $out "/* app string */"
83 for (( i=0; i<${#APP_ID[@]} ; i+=2 )) ; do
84     printf "#define %-36s %s\n" ${APP_ID[$i]} "${APP_ID[$i+1]}">> $out
85 done
86 dump $out ""
87 dump $out "/* custom string */"
88 for (( i=0; i<${#CUSTOM_ID[@]} ; i+=2 )) ; do
89     printf "#define %-36s %s\n" "${CUSTOM_ID[$i]}" "${CUSTOM_ID[$i+1]}" >> $out
90 done
91
92 dump $out ""
93 dump $out "#endif                /* __MEMO_STRING_H__ */"