Magellan Linux

Annotation of /tags/installer-simple-0_4_91_20160616_1/generate-po.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2953 - (hide annotations) (download) (as text)
Thu Jun 16 08:46:14 2016 UTC (7 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 2487 byte(s)
tagged 'installer-simple-0_4_91_20160616_1'
1 niro 2350 #!/bin/bash
2    
3     method="$1"
4     script="$2"
5     domain="$3"
6     languages="de"
7     localedir="/usr/share/locale"
8    
9     usage()
10     {
11     echo "Usage: $0 [method] [shell script] {domain}"
12     echo "Known methods:"
13     echo " --create-pot - creates pot file from script"
14     echo " --append-pot - appends current pot file with script"
15 niro 2357 echo " --unique-pot - remove duplicates from pot file"
16 niro 2350 echo " --generate - generates pot and po files"
17     echo " --compile - compiles mo files"
18     echo
19     echo "Examples:"
20     echo " $0 --generate example.sh"
21     echo " $0 --compile example.sh"
22     echo
23     }
24    
25     create_pot()
26     {
27     local pot
28    
29     install -d locale
30     pot="locale/${domain}.pot"
31     bash --dump-po-strings "${script}" > "${pot}"
32     }
33    
34     append_pot()
35     {
36     local pot
37    
38     install -d locale
39     pot="locale/${domain}.pot"
40     bash --dump-po-strings "${script}" >> "${pot}"
41     }
42    
43 niro 2357 unique_pot()
44     {
45     local pot
46    
47     install -d locale
48     pot="locale/${domain}.pot"
49     if [ ! -f "${pot}" ]
50     then
51     echo "Error: ${pot} missing - run --create-pot or --append-pot"
52     exit 1
53     fi
54    
55     # remove duplicate messages
56 niro 2496 msguniq --no-wrap --sort-by-file --output-file="${pot}.fixed" "${pot}"
57 niro 2357 if [[ $? = 0 ]]
58     then
59 niro 2495 mv "${pot}" "${pot}.dump"
60     cp "${pot}.fixed" "${pot}"
61 niro 2357 else
62     echo "Error: msguniq failed"
63     exit 1
64     fi
65     }
66    
67 niro 2350 generate_po()
68     {
69     local lang
70     local po
71     local pot
72    
73     pot="locale/${domain}.pot"
74     if [ ! -f "${pot}" ]
75     then
76     echo "Error: ${pot} missing - run --create-pot or --append-pot"
77 niro 2354 exit 1
78 niro 2350 fi
79    
80     for lang in ${languages}
81     do
82     po="locale/${lang}/${domain}.po"
83     if [ -f "${po}" ]
84     then
85     echo "Updating lang '${lang}'"
86 niro 2356 msgmerge --quiet --no-fuzzy-matching --no-wrap --sort-by-file --update "${po}" "${pot}"
87 niro 2350 else
88     echo "Processing lang '${lang}'"
89     install -d locale/"${lang}"
90 niro 2355 msginit --no-wrap --no-translator --locale="${lang}" --input="${pot}" --output-file="${po}"
91 niro 2350 fi
92     done
93     }
94    
95     generate_mo()
96     {
97     local lang
98     local dir
99     local po
100    
101     for lang in ${languages}
102     do
103     echo "Compiling lang '${lang}'"
104     po="locale/${lang}/${domain}.po"
105     if [ ! -f "${po}" ]
106     then
107     echo "Error: ${po} missing - run --generate first"
108     exit 1
109     fi
110     dir="${DESTDIR}/${localedir}/${lang}/LC_MESSAGES"
111     install -d "${dir}"
112     msgfmt -o "${dir}"/"${domain}".mo "${po}"
113     done
114     }
115    
116     if [[ -z ${script} ]]
117     then
118     usage
119     echo "Error: Script missing"
120     exit 1
121     fi
122    
123     if [[ -z ${domain} ]]
124     then
125     domain="${script}"
126     fi
127    
128     case ${method} in
129     --create-pot) create_pot ;;
130     --append-pot) append_pot ;;
131 niro 2357 --unique-pot) unique_pot ;;
132 niro 2350 --generate) generate_po ;;
133     --compile) generate_mo ;;
134     *) usage ;;
135     esac

Properties

Name Value
svn:executable *