Browse code

because functions are nice

Runa A. Sandvik authored on16/05/2010 12:35:06
Showing1 changed files
... ...
@@ -83,170 +83,112 @@ for file in $po ; do
83 83
 
84 84
 	# Time to write the translated wml file.
85 85
 	# The translated document is written if 80% or more of the po
86
-	# file has been translated.
87
-	# Example: Use '-k 21' to set this number down to 21%.
88
-	
89
-	# The nice thing with po4a-translate is that it will only write
90
-	# the translated document if 80% or more has been translated.
91
-	# But it will delete the wml if less than 80% has been
86
+	# file has been translated. Example: Use '-k 21' to set this
87
+	# number down to 21%. Also, po4a-translate will only write the
88
+	# translated document if 80% or more has been translated.
89
+	# However, it will delete the wml if less than 80% has been
92 90
 	# translated. To avoid having our current, translated wml files
93
-	# deleted, we first convert the po to a temp wml. If this file
94
-	# was written, we'll rename it.
91
+	# deleted, convert the po to a temp wml first. If this file was
92
+	# actually written, rename it to wml.
95 93
 
96
-	# If $onedirup is equal to $lang, that means we do not have a
97
-	# subdirectory. Also, we don't want to convert english po back
98
-	# to english wml.
99
-	if [ $onedirup == $lang ]
100
-	then
94
+	# Convert translations to directories such as website/nb/.
95
+	function nosubdir {
101 96
 		# The location of the english wml file
102 97
 		english="$wmldir/en/$wmlfile"
103 98
 
104
-		# If the current subdirectory is "zh_CN" use "zh-cn" instead
105
-		if [ $subdir = "zh_CN" ]
99
+		# Convert the files
100
+		po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
101
+
102
+		# Check to see if the file was written
103
+                if [ -e "$wmldir/$subdir/tmp-$wmlfile" ]
106 104
 		then
107
-			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/zh-cn/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
105
+			mv "$wmldir/$subdir/tmp-$wmlfile" "$wmldir/$subdir/$wmlfile"
106
+
107
+                        # Remove last three lines in file
108
+			sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$wmlfile"
109
+
110
+			# Include foot.wmi
111
+			echo "#include <foot.wmi>" >> "$wmldir/$subdir/$wmlfile"
112
+		fi
113
+	}	
108 114
 
109
-			# Check to see if the file was written
110
-			if [ -e "$wmldir/zh-cn/tmp-$wmlfile" ]
111
-			then
112
-				mv "$wmldir/zh-cn/tmp-$wmlfile" "$wmldir/zh-cn/$wmlfile"
115
+	# Convert translations to directories such as website/torbrowser/nb/.	
116
+	function subdir {
117
+		# The location of the english wml file
118
+                english="$wmldir/$subdir/en/$wmlfile"
113 119
 
114
-				# Remove last three lines in file
115
-				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/zh-cn/$wmlfile"
120
+		# Convert the files
121
+		po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/$lang/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
116 122
 
117
-				# Include foot.wmi
118
-				echo "#include <foot.wmi>" >> "$wmldir/zh-cn/$wmlfile"
119
-			fi
123
+		# Check to see if the file was written
124
+		if [ -e "$wmldir/$subdir/$lang/tmp-$wmlfile" ]
125
+		then
126
+			mv "$wmldir/$subdir/$lang/tmp-$wmlfile" "$wmldir/$subdir/$lang/$wmlfile"
127
+
128
+			# Remove last three lines in file
129
+			sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$lang/$wmlfile"
130
+
131
+			# Include foot.wmi
132
+			echo "#include <foot.wmi>" >> "$wmldir/$subdir/$lang/$wmlfile"
133
+		fi
134
+	}
135
+
136
+	# If $onedirup is equal to $lang, that means we do not have a
137
+	# subdirectory.
138
+	if [ $onedirup == $lang ]
139
+	then
140
+		# If the current subdirectory is "zh_CN" use "zh-cn" instead
141
+		if [ $subdir = "zh_CN" ]
142
+		then
143
+			subdir="zh-cn"
144
+			nosubdir
120 145
 		fi
121 146
 		
122 147
 		# If the current directory is "nb" use "no" instead
123 148
 		if [ $subdir = "nb" ]
124 149
 		then
125
-			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/no/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"	
126
-
127
-			# Check to see if the file was written
128
-			if [ -e "$wmldir/no/tmp-$wmlfile" ]
129
-			then
130
-				mv "$wmldir/no/tmp-$wmlfile" "$wmldir/no/$wmlfile"
131
-
132
-				# Remove last three lines in file
133
-				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/no/$wmlfile"
134
-
135
-				# Include foot.wmi
136
-				echo "#include <foot.wmi>" >> "$wmldir/no/$wmlfile"
137
-			fi
150
+			subdir="no"
151
+			nosubdir
138 152
 		fi
139 153
 
140 154
 		# If the current directory is "sv" use "se" instead
141 155
 		if [ $subdir = "sv" ]
142 156
 		then
143
-			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/se/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
144
-
145
-			# Check to see if the file was written
146
-			if [ -e "$wmldir/se/tmp-$wmlfile" ]
147
-			then
148
-				mv "$wmldir/se/tmp-$wmlfile" "$wmldir/se/$wmlfile"
149
-
150
-				# Remove last three lines in file
151
-				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/se/$wmlfile"
152
-
153
-				# Include foot.wmi
154
-				echo "#include <foot.wmi>" >> "$wmldir/se/$wmlfile"
155
-
156
-			fi
157
+			subdir="se"
158
+			nosubdir
157 159
 		fi
158 160
 
159 161
 		# Convert everything else
160 162
 		if [[ $subdir != "en" && $subdir != "zh_CN" && $subdir != "nb" && $subdir != "sv" ]]
161 163
 		then
162
-			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
163
-
164
-			# Check to see if the file was written
165
-			if [ -e "$wmldir/$subdir/tmp-$wmlfile" ]
166
-			then
167
-				mv "$wmldir/$subdir/tmp-$wmlfile" "$wmldir/$subdir/$wmlfile"
168
-
169
-				# Remove last three lines in file
170
-				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$wmlfile"
171
-
172
-				# Include foot.wmi
173
-				echo "#include <foot.wmi>" >> "$wmldir/$subdir/$wmlfile"
174
-			fi
164
+			nosubdir
175 165
 		fi
176 166
 	else
177
-		# The location of the english wml file
178
-		english="$wmldir/$subdir/en/$wmlfile"
179
-		
180 167
 		# If the current language is "zh_CN" use "zh-cn" instead
181 168
 		if [ $lang = "zh_CN" ]
182 169
 		then
183
-			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/zh-cn/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
184
-
185
-			# Check to see if the file was written
186
-			if [ -e "$wmldir/$subdir/zh-cn/tmp-$wmlfile" ]
187
-			then
188
-				mv "$wmldir/$subdir/zh-cn/tmp-$wmlfile" "$wmldir/$subdir/zh-cn/$wmlfile"
189
-
190
-				# Remove last three lines in file
191
-				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/zh-cn/$wmlfile"
192
-
193
-				# Include foot.wmi
194
-				echo "#include <foot.wmi>" >> "$wmldir/$subdir/zh-cn/$wmlfile"
195
-			fi
170
+			lang="zh-cn"
171
+			subdir
196 172
 		fi
197 173
 
198 174
 		# If the current language is "nb" use "no" instead
199 175
 		if [ $lang = "nb" ]
200 176
 		then
201
-			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/no/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
202
-
203
-			# Check to see if the file was written
204
-			if [ -e "$wmldir/$subdir/no/tmp-$wmlfile" ]
205
-			then
206
-				mv "$wmldir/$subdir/no/tmp-$wmlfile" "$wmldir/$subdir/no/$wmlfile"
207
-
208
-				# Remove last three lines in file
209
-				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/no/$wmlfile"
210
-
211
-				# Include foot.wmi
212
-				echo "#include <foot.wmi>" >> "$wmldir/$subdir/no/$wmlfile"
213
-			fi
177
+			lang="no"
178
+			subdir
214 179
 		fi
215 180
 
216 181
 		# If the current language is "sv" use "se" instead
217 182
 		if [ $lang = "sv" ]
218 183
 		then
219
-			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/se/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
220
-
221
-			# Check to see if the file was written
222
-			if [ -e "$wmldir/$subdir/se/tmp-$wmlfile" ]
223
-			then
224
-				mv "$wmldir/$subdir/se/tmp-$wmlfile" "$wmldir/$subdir/se/$wmlfile"
225
-
226
-				# Remove last three lines in file
227
-				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/se/$wmlfile"
228
-
229
-				# Include foot.wmi
230
-				echo "#include <foot.wmi>" >> "$wmldir/$subdir/se/$wmlfile"
231
-			fi
184
+			lang="se"
185
+			subdir
232 186
 		fi
233 187
 		
234 188
 		# Convert everything else
235 189
 		if [[ $lang != "en" && $lang != "zh_CN" && $lang != "nb" && $lang != "sv" ]]
236 190
 		then
237
-			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/$lang/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
238
-
239
-			# Check to see if the file was written
240
-			if [ -e "$wmldir/$subdir/$lang/tmp-$wmlfile" ]
241
-			then
242
-				mv "$wmldir/$subdir/$lang/tmp-$wmlfile" "$wmldir/$subdir/$lang/$wmlfile"
243
-
244
-				# Remove last three lines in file
245
-				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$lang/$wmlfile"
246
-
247
-				# Include foot.wmi
248
-				echo "#include <foot.wmi>" >> "$wmldir/$subdir/$lang/$wmlfile"
249
-			fi
191
+			subdir
250 192
 		fi
251 193
 	fi
252 194
 done