]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/website_post.py
Web build: add translations for "Other languages"
[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):
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=\"index"
57                 if (not (l=="")):
58                         text += "." + l
59                 text += ".html\">"
60                 text += lang_lookup[l]
61                 text += "</a>"
62                 if (i < len(langs)-2):
63                         text += ", "
64                 else:
65                         text += ".\n"
66         # TODO: add link to automatic language selection?
67         # still need to include this page in the new webpages somewhere
68         text += "</p>\n"
69         return text
70
71
72 for file in html_files:
73         file_split = file.split('.')
74         # we want to strip the .html
75         out_filename = os.path.basename(file_split[0])
76         if (len(file_split) == 2):
77                 # it's English
78                 lang = ''
79         else:
80                 # it's a translation
81                 lang = file_split[1]
82         out_filename += '.'+lang
83
84 # I can't get the previous name to work
85         out_filename = os.path.basename(file)
86
87         # translation links should point to translations
88         lines = open(file).readlines()
89         # ick
90         os.remove(file)
91
92         lang_footer = makeFooter(lang)
93         
94         outfile = open( os.path.join(outdir, out_filename), 'w')
95         for line in lines:
96                 # avoid external links
97                 if ((line.find("href") >= 0) and (line.find("http")==-1)):
98 # eventually we want to do this, but I can't get it to work.
99 # waiting for help with apache (?)
100 #                       line = line.replace(".html", "."+lang)
101                         text = ""
102                         if (not (lang=="")):
103                                 text += "." + lang
104                         text += ".html"
105                         line = line.replace(".html", text)
106                 if (line.find("<!-- FOOTER -->") >= 0):
107                         outfile.write( lang_footer )
108                 outfile.write(line)
109         outfile.close()
110