summaryrefslogtreecommitdiff
path: root/scripts/string.sh
blob: a7804cf191bc6e8eba2fd7a718067cd2252d5f7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
SYS_MO="$HOME/sbs/target-armel/usr/share/locale/en/LC_MESSAGES/sys_string.mo"
APP_MO="$HOME/sbs/target-armel/opt/apps/com.samsung.memo/res/locale/en/LC_MESSAGES/memo.mo"
TEMP_STR="./temp"
IN="str.in"
APP_NAME="memo"

declare -a SYS_ID
declare -a APP_ID
declare -a CUSTOM_ID

out=../include/"$APP_NAME""_string.h"
rm -fr $out

sbs -et apt-get install sys-string-0 -y --force-yes

function get_str_id () {
    local str=$1
    local mo=$2
    local result=""
    if [[ -e $mo ]] ; then
        result=`msgunfmt $mo | grep "\"$str\"" -B 1 | head -n 1 | awk '{print $2}'`
    fi
    echo $result
}

function get_tmp_id () {
    local str=$1
    local result=""
    if [[ -e $TEMP_STR ]] ; then
        result=`cat $TEMP_STR | grep "$str" -A 1 | tail -n 1 | awk '{print $1}'`
    fi
    echo $result
}

function gen_id () {
    local prefix=$1
    local str=$2
    local id=$prefix`echo $str | tr a-z A-Z | sed "s/ /_/g" | sed "s/?//g" | sed "s/%//g"`
    echo $id
}

function dump () {
    local dest=$1
    local str=$2
    printf "$str\n" >> $dest
}

#copy right
cat ./copyright > $out
dump $out ""
dump $out "#ifndef __MEMO_STRING_H__"
dump $out "#define __MEMO_STRING_H__"

LINES=`cat $IN |wc -l`
for (( i=1; i<=$LINES; i++ )) ; do
    string=`cat $IN | sed -n "$i p"`
    sys_id=$(get_str_id "$string" "$SYS_MO")
    app_id=$(get_str_id "$string" "$APP_MO")
    tmp_id=$(get_tmp_id "$string")
    if [ "$sys_id" != "" ] ; then
        SYS_ID[${#SYS_ID[@]}]=$(gen_id "MEMO_I18N_" "$string") #append id to array
        SYS_ID[${#SYS_ID[@]}]="dgettext(\"sys_string\", $sys_id) /* $string */" #append def to array
    elif [ "$app_id" != "" ] ; then
        APP_ID[${#APP_ID[@]}]=$(gen_id "MEMO_I18N_" "$string")
        APP_ID[${#APP_ID[@]}]="dgettext(\"memo\", $app_id) /* $string */"
    elif [ "$tmp_id" != "" ] ; then
        CUSTOM_ID[${#CUSTOM_ID[@]}]=$(gen_id "MEMO_I18N_" "$string")
        CUSTOM_ID[${#CUSTOM_ID[@]}]="dgettext(\"memo\", \"$tmp_id\") /* $string */"
    else
        CUSTOM_ID[${#CUSTOM_ID[@]}]=$(gen_id "MEMO_I18N_" "$string")
        CUSTOM_ID[${#CUSTOM_ID[@]}]="_(\"$string\") /* $string */"
    fi
done

#dump results
dump $out ""
dump $out "/* system string */"
for (( i=0; i<${#SYS_ID[@]} ; i+=2 )) ; do
    printf "#define %-36s %s\n" ${SYS_ID[$i]} "${SYS_ID[$i+1]}">> $out
done
dump $out ""
dump $out "/* app string */"
for (( i=0; i<${#APP_ID[@]} ; i+=2 )) ; do
    printf "#define %-36s %s\n" ${APP_ID[$i]} "${APP_ID[$i+1]}">> $out
done
dump $out ""
dump $out "/* custom string */"
for (( i=0; i<${#CUSTOM_ID[@]} ; i+=2 )) ; do
    printf "#define %-36s %s\n" "${CUSTOM_ID[$i]}" "${CUSTOM_ID[$i+1]}" >> $out
done

dump $out ""
dump $out "#endif                /* __MEMO_STRING_H__ */"