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 text = "<p id=\"languages\">\n"
98 text += _ ('Other languages: ', currentLang)
100 if (lang == currentLang):
103 text += addLangExt(filename, lang, "html")
105 text += _ ('English', lang)
107 text = text[:-2] + '.\n'
108 # TODO: add link to automatic language selection?
109 # still need to include this page in the new webpages somewhere
113 def getLocalHref(line):
114 match = re.search(r'href=[\'"]?([^\'" >]+)', line)
116 url = match.group(0)[6:]
117 if (url[0:7] == "http://"):
131 for file in html_files:
132 ### we want to strip the .html and get the lang
133 file_split = file.split('.')
134 file_base = os.path.basename( file_split[0] )
135 if (len(file_split) == 2):
138 # possibly necessary for automatic language selection
139 file_symlink = file.replace(".html", ".en.html")
140 if (not (os.path.exists(file_symlink))):
141 os.symlink (file, file_symlink)
142 elif (len(file_split) == 3):
153 ### we need to replace parts of the file
154 lines = open(file).readlines()
156 outfile = open(file, 'w')
158 lang_footer = makeFooter(file_base, lang)
162 ### alter links as appropriate
163 link = getLocalHref(line)
166 if (link.endswith(".html")):
167 langlink = addLangExt(link[:-5], lang, "html")
168 line = line.replace(link, langlink)
169 if (link.endswith(".pdf")):
170 langlink = addLangExt(link[:-4], lang, "pdf")
171 line = line.replace(link, langlink)
172 ### add language selection footer
173 if (line.find("<!-- FOOTER -->") >= 0):
174 outfile.write( lang_footer )