]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/website_post.py
Web build: translation and pdf links.
[lilypond.git] / scripts / build / website_post.py
1 #!@PYTHON@
2 #-*- coding: utf-8 -*-
3
4 ## This is web_post.py. This script deals with translations
5 ## in the "make website" target.
6
7 import sys
8 import os
9 import glob
10
11 #### Translation data
12 lang_lookup = {
13   'fr': 'français',
14   'es': 'español',
15   '': 'english'
16 }
17
18 lang_other_langs = {
19   'es': 'Blargle flop: ',
20   'fr': 'lirer des autres langs: ',
21   '': 'Other languages: '
22 }
23
24
25 #### Actual program
26
27 #indir, outdir = sys.argv[1:]
28
29 # FIXME: looks dangerous!
30 indir = sys.argv[1]
31 outdir=indir
32
33 html_files = glob.glob( os.path.join(indir, '*.html') )
34
35 # messy way to get all languages
36 langs_set = set()
37 for file in html_files:
38         file_split = file.split('.')
39         if (len(file_split) == 2):
40                 # it's English
41                 lang = ''
42         else:
43                 # it's a translation
44                 lang = file_split[1]
45         langs_set.add(lang)
46 langs = list(langs_set)
47 langs.sort()
48
49 def makeFooter(currentLang, currentPage):
50         text = "<p id=\"languages\">\n"
51         text += lang_other_langs[currentLang]
52         for i in range(len(langs)):
53                 l = langs[i]
54                 if (l == currentLang):
55                         continue
56                 text += "<a href=\""
57                 text += currentPage
58                 if (not (l=="")):
59                         text += "." + l
60                 text += ".html\">"
61                 text += lang_lookup[l]
62                 text += "</a>"
63                 if (i < len(langs)-2):
64                         text += ", "
65                 else:
66                         text += ".\n"
67         # TODO: add link to automatic language selection?
68         # still need to include this page in the new webpages somewhere
69         text += "</p>\n"
70         return text
71
72
73 for file in html_files:
74         file_split = file.split('.')
75         # we want to strip the .html
76         out_filename = os.path.basename(file_split[0])
77         if (len(file_split) == 2):
78                 # it's English
79                 lang = ''
80         else:
81                 # it's a translation
82                 lang = file_split[1]
83         out_filename += '.'+lang
84
85 # I can't get the previous name to work
86         out_filename = os.path.basename(file)
87
88         # translation links should point to translations
89         lines = open(file).readlines()
90         # ick
91         os.remove(file)
92
93         # ick
94         lang_footer = makeFooter(lang, out_filename.split('.')[0])
95         
96         outfile = open( os.path.join(outdir, out_filename), 'w')
97         for line in lines:
98                 # avoid external links
99                 if ((line.find("href") >= 0) and (line.find("http")==-1)):
100 # eventually we want to do this, but I can't get it to work.
101 # waiting for help with apache (?)
102 #                       line = line.replace(".html", "."+lang)
103                         text = ""
104                         if (not (lang=="")):
105                                 text += "." + lang
106                         text += ".html"
107                         line = line.replace(".html", text)
108                 if ((line.find("href") >= 0) and
109                     (line.find("http")==-1) and
110                     (line.find("pdf") >= 0)):
111                         text = ""
112                         if (not (lang=="")):
113                                 text += "." + lang
114                         text += ".pdf"
115                         line = line.replace(".pdf", text)
116
117
118                 if (line.find("<!-- FOOTER -->") >= 0):
119                         outfile.write( lang_footer )
120                 outfile.write(line)
121         outfile.close()
122