-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-local-slides.py
executable file
·77 lines (60 loc) · 2.04 KB
/
generate-local-slides.py
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
#!/usr/bin/python
import os, sys, glob, subprocess
import json
if len(sys.argv) > 1:
distro = sys.argv[1]
else:
print("Usage: %s <distro>" % sys.argv[0]);
sys.exit(-1)
if not subprocess.call(["which", "po4a-translate"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0:
print("Error: po4a is not available.")
sys.exit(1)
source_dir = '.'
po_dir = os.path.join(source_dir, 'po', distro)
build_dir = 'build'
build_slides = os.path.join(build_dir, distro, 'slides')
template_slides = glob.glob(os.path.join(build_slides, '*.html'))
template_slides.remove(os.path.join(build_slides, 'index.html'))
directory = {}
for locale_file in glob.glob( os.path.join(po_dir, '*.po') ):
locale_name = os.path.basename(locale_file).rstrip('.po')
locale_slides = os.path.join(build_slides, 'l10n', locale_name)
print("Working on locale %s" % locale_name)
directory[locale_name] = {
'slides' : [],
'media' : []
}
for template_slide in template_slides:
slide_name = os.path.basename(template_slide)
output_slide = os.path.join(locale_slides, slide_name)
try:
os.makedirs(locale_slides)
except OSError:
# Directory already exists
pass
if os.path.exists(output_slide):
os.remove(output_slide)
# -k 1 -> if there are any translations at all, keep it.
subprocess.call(['po4a-translate',
'-M', 'UTF-8',
'-f', 'xhtml',
'-m', template_slide,
'-p', locale_file,
'-l', output_slide,
'-k', '1',
'-o', 'attributes="data-translate"'])
if os.path.exists(output_slide):
directory[locale_name]['slides'].append(slide_name)
else:
#print("\t%s was not translated for locale %s" \
# % (slide_name, locale_name))
try:
os.rmdir(locale_slides)
except OSError:
# Directory is not empty
pass
directory_file = open(os.path.join(build_slides, 'directory.jsonp'), 'w')
content = json.dumps(directory)
directory_file.write('ubiquitySlideshowDirectoryCb(%s);' % content)
directory_file.close()