4 ##### This is web_post.py. This script deals with translations
5 ##### in the "make website" target.
12 ###### Translation data, move out, see create-weblinks-itexi.py
16 'Other languages': 'Andere Sprachen',
20 'Other languages': 'Otros idiomas',
23 'English': 'Français',
24 'Other languages': 'Autres langues',
28 'Other languages': 'Más nyelvek',
31 'English': 'Japanese',
32 'Other languages': '他の言語',
35 'English': 'Nederlands',
36 'Other languages': 'Andere talen',
40 # needs at least: make -C po or make- C Documentation/po
43 # Keep some freakin' gettext compatibility
47 else: # poor mans translation
48 def _ (string, lang=os.environ['LANG']):
49 return translations.get (lang.split ('_')[0], {}).get (string, string)
64 html_files = glob.glob( '*.html' )
67 ### messy way to get all languages
69 for file in html_files:
70 file_split = file.split('.')
71 if (len(file_split) == 2):
74 elif (len(file_split) == 3):
77 # make sure it's a translated language
80 langs = list(langs_set)
85 def addLangExt(filename, lang, ext):
88 for dir in exclude_manuals:
89 if (text.find(dir) >= 0):
91 if (not (exclude or (lang==""))):
96 def makeFooter (filename, currentLang):
97 # TODO: add link to automatic language selection?
98 # still need to include this page in the new webpages somewhere
99 footer = '''<p id="languages">
104 str = '''<a href="%(file_name)s">%(language_name)s</a>'''
105 file_name = addLangExt (filename, lang, 'html')
106 language_name = _ ('English', lang)
107 return str % locals ()
108 lst = ', '.join ([link (lang) for lang in langs if lang != currentLang])
109 other = _ ('Other languages', currentLang)
110 return footer % locals ()
112 def getLocalHref(line):
113 match = re.search(r'href=[\'"]?([^\'" >]+)', line)
115 url = match.group(0)[6:]
116 if (url[0:7] == "http://"):
130 for file in html_files:
131 ### we want to strip the .html and get the lang
132 file_split = file.split('.')
133 file_base = os.path.basename( file_split[0] )
134 if (len(file_split) == 2):
137 # possibly necessary for automatic language selection
138 file_symlink = file.replace(".html", ".en.html")
139 if (not (os.path.exists(file_symlink))):
140 os.symlink (file, file_symlink)
141 elif (len(file_split) == 3):
152 ### we need to replace parts of the file
153 lines = open(file).readlines()
155 outfile = open(file, 'w')
157 lang_footer = makeFooter (file_base, lang)
161 ### alter links as appropriate
162 link = getLocalHref(line)
165 if (link.endswith(".html")):
166 langlink = addLangExt(link[:-5], lang, "html")
167 line = line.replace(link, langlink)
168 if (link.endswith(".pdf")):
169 langlink = addLangExt(link[:-4], lang, "pdf")
170 line = line.replace(link, langlink)
171 ### add language selection footer
172 if (line.find("<!-- FOOTER -->") >= 0):
173 outfile.write( lang_footer )