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):
61 for dir in exclude_manuals:
62 if (text.find(dir) >= 0):
64 if (not (exclude or (lang==""))):
69 def makeFooter(filename, currentLang):
70 text = "<p id=\"languages\">\n"
71 text += lang_other_langs[currentLang]
72 for i in range(len(langs)):
74 if (lang == currentLang):
77 text += addLangExt(filename, lang, "html")
79 text += lang_lookup[lang]
81 if (i < len(langs)-2):
85 # TODO: add link to automatic language selection?
86 # still need to include this page in the new webpages somewhere
90 def getLocalHref(line):
91 match = re.search(r'href=[\'"]?([^\'" >]+)', line)
93 url = match.group(0)[6:]
94 if (url[0:7] == "http://"):
108 for file in html_files:
109 ### we want to strip the .html and get the lang
110 file_split = file.split('.')
111 file_base = os.path.basename( file_split[0] )
112 if (len(file_split) == 2):
115 # possibly necessary for automatic language selection
116 file_symlink = file.replace(".html", ".en.html")
117 if (not (os.path.exists(file_symlink))):
118 os.symlink (file, file_symlink)
119 elif (len(file_split) == 3):
130 ### we need to replace parts of the file
131 lines = open(file).readlines()
133 outfile = open(file, 'w')
135 lang_footer = makeFooter(file_base, lang)
140 ### alter links as appropriate
141 link = getLocalHref(line)
144 if (link.endswith(".html")):
145 langlink = addLangExt(link[:-5], lang, "html")
146 line = line.replace(link, langlink)
147 if (link.endswith(".pdf")):
148 langlink = addLangExt(link[:-4], lang, "pdf")
149 line = line.replace(link, langlink)
150 ### add language selection footer
151 if (line.find("<!-- FOOTER -->") >= 0):
152 outfile.write( lang_footer )