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': 'Jiné jazyky',
20 'Other languages': 'Andere Sprachen',
24 'Other languages': 'Otros idiomas',
27 'English': 'Français',
28 'Other languages': 'Autres langues',
32 'Other languages': 'Más nyelvek',
35 'English': 'Italiano',
36 'Other languages': 'Altre lingue',
40 'Other languages': '他の言語',
43 'English': 'Nederlands',
44 'Other languages': 'Andere talen',
48 'Other languages': '其它语言',
52 # needs at least: make -C po or make- C Documentation/po
55 #### this breaks on lilypond.org
56 # Keep some freakin' gettext compatibility
58 # import lilylib as ly;
60 #else: # poor mans translation
61 # def _ (string, lang=os.environ['LANG']):
62 # return translations.get (lang.split ('_')[0], {}).get (string, string)
64 #### this works on lilypond.org
66 return translations.get (lang.split ('_')[0], {}).get (string, string)
81 html_files = glob.glob( '*.html' )
84 ### messy way to get all languages
86 for file in html_files:
87 file_split = file.split('.')
88 if (len(file_split) == 2):
91 elif (len(file_split) == 3):
94 # make sure it's a translated language
97 langs = list(langs_set)
102 def addLangExt(filename, lang, ext):
105 for dir in exclude_manuals:
106 if (text.find(dir) >= 0):
108 if (not (exclude or (lang==""))):
113 def makeFooter (filename, currentLang):
114 footer = '''<p id="languages">
121 str = '''<a href="%(file_name)s">%(language_name)s</a>'''
122 file_name = addLangExt (filename, lang, 'html')
123 language_name = _ ('English', lang)
124 return str % locals ()
125 lst = ', '.join ([link (lang) for lang in langs if lang != currentLang])
126 other = _ ('Other languages', currentLang)
127 browser_lang = _ ('About <a href="%s">automatic language selection</a>.', currentLang)
128 browser_language_url = "http://www.lilypond.org/website/misc/browser-language"
129 browser_language = browser_lang % browser_language_url
130 return footer % locals ()
132 def getLocalHref(line):
133 match = re.search(r'href=[\'"]?([^\'" >]+)', line)
135 url = match.group(0)[6:]
136 if (url[0:7] == "http://"):
150 for file in html_files:
151 ### we want to strip the .html and get the lang
152 file_split = file.split('.')
153 file_base = os.path.basename( file_split[0] )
154 if (len(file_split) == 2):
157 # possibly necessary for automatic language selection
158 file_symlink = file.replace(".html", ".en.html")
159 if not os.path.lexists (file_symlink):
160 os.symlink (file, file_symlink)
161 elif (len(file_split) == 3):
172 ### we need to replace parts of the file
173 lines = open(file).readlines()
175 outfile = open(file, 'w')
177 lang_footer = makeFooter (file_base, lang)
181 ### alter links as appropriate
182 link = getLocalHref(line)
185 if (not link.startswith("../doc/")):
186 if (link.endswith(".html")):
187 langlink = addLangExt(link[:-5], lang, "html")
188 line = line.replace(link, langlink)
189 if (link.endswith(".pdf")):
190 langlink = addLangExt(link[:-4], lang, "pdf")
191 line = line.replace(link, langlink)
192 ### add google tracker header
193 if (line.find("</head>") >= 0):
194 outfile.write("""<!-- Google tracking !-->
195 <script src="http://www.google-analytics.com/urchin.js"
196 type="text/javascript">
198 <script type="text/javascript">
199 _uacct = "UA-68969-1";
203 #### add google tracker goals
204 if (line.find("href=\"http://download.linuxaudio.org") >= 0):
205 # TODO: more ugly hardcoding to make releases hard. :(
206 if (line.find('2.14') >= 0):
207 line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.14\');\" href=')
208 elif (line.find('2.15') >= 0):
209 line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.15\');\" href=')
210 ### add language selection footer
211 if (line.find("<div id=\"verifier_texinfo\">") >= 0):
212 outfile.write("<div id=\"footer\">\n")
213 outfile.write( lang_footer )
214 if (line.find("</body") >= 0):
215 outfile.write("</div>\n")