4 ##### This is web_post.py. This script deals with translations
5 ##### in the "make website" target.
12 ###### Translation data
20 'es': 'Otros idiomas: ',
21 'fr': 'Autres langues : ',
22 '': 'Other languages: '
37 html_files = glob.glob( '*.html' )
40 ### messy way to get all languages
42 for file in html_files:
43 file_split = file.split('.')
44 if (len(file_split) == 2):
47 elif (len(file_split) == 3):
50 # make sure it's a translated language
51 if (not (lang == "en")):
53 langs = list(langs_set)
58 def addLangExt(filename, lang, ext):
65 def makeFooter(filename, currentLang):
66 text = "<p id=\"languages\">\n"
67 text += lang_other_langs[currentLang]
68 for i in range(len(langs)):
70 if (lang == currentLang):
73 text += addLangExt(filename, lang, "html")
75 text += lang_lookup[lang]
77 if (i < len(langs)-2):
81 # TODO: add link to automatic language selection?
82 # still need to include this page in the new webpages somewhere
86 def getLocalHref(line):
87 match = re.search(r'href=[\'"]?([^\'" >]+)', line)
89 url = match.group(0)[6:]
90 if (url[0:7] == "http://"):
104 for file in html_files:
105 ### we want to strip the .html and get the lang
106 file_split = file.split('.')
107 file_base = os.path.basename( file_split[0] )
108 if (len(file_split) == 2):
111 # possibly necessary for automatic language selection
112 file_symlink = file.replace(".html", ".en.html")
113 if (not (os.path.exists(file_symlink))):
114 os.symlink (file, file_symlink)
115 elif (len(file_split) == 3):
126 ### we need to replace parts of the file
127 lines = open(file).readlines()
129 outfile = open(file, 'w')
131 lang_footer = makeFooter(file_base, lang)
136 ### alter links as appropriate
137 link = getLocalHref(line)
139 link_base = link.split('.')[0]
140 if (link.endswith(".html")):
141 langlink = addLangExt(link_base, lang, "html")
142 line = line.replace(link, langlink)
143 if (link.endswith(".pdf")):
144 langlink = addLangExt(link_base, lang, "pdf")
145 line = line.replace(link, langlink)
146 ### add language selection footer
147 if (line.find("<!-- FOOTER -->") >= 0):
148 outfile.write( lang_footer )