Contents of /tags/installer-simple-0_4_90_20140108_1/generate-po.sh
Parent Directory | Revision Log
Revision 2494 -
(show annotations)
(download)
(as text)
Wed Jan 8 12:45:45 2014 UTC (10 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2482 byte(s)
Wed Jan 8 12:45:45 2014 UTC (10 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2482 byte(s)
tagged 'installer-simple-0_4_90_20140108_1'
1 | #!/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 | echo " --unique-pot - remove duplicates from pot file" |
16 | 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 | 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 | msguniq --unique --no-wrap --sort-by-file --output-file="${pot}.fixed" "${pot}" |
57 | if [[ $? = 0 ]] |
58 | then |
59 | rm "${pot}" |
60 | mv "${pot}.fixed" "${pot}" |
61 | else |
62 | echo "Error: msguniq failed" |
63 | exit 1 |
64 | fi |
65 | } |
66 | |
67 | 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 | exit 1 |
78 | 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 | msgmerge --quiet --no-fuzzy-matching --no-wrap --sort-by-file --update "${po}" "${pot}" |
87 | else |
88 | echo "Processing lang '${lang}'" |
89 | install -d locale/"${lang}" |
90 | msginit --no-wrap --no-translator --locale="${lang}" --input="${pot}" --output-file="${po}" |
91 | 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 | --unique-pot) unique_pot ;; |
132 | --generate) generate_po ;; |
133 | --compile) generate_mo ;; |
134 | *) usage ;; |
135 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |