4 ##### This is website_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': 'Altres idiomes',
20 'Other languages': 'Jiné jazyky',
24 'Other languages': 'Andere Sprachen',
28 'Other languages': 'Otros idiomas',
31 'English': 'Français',
32 'Other languages': 'Autres langues',
36 'Other languages': 'Más nyelvek',
39 'English': 'Italiano',
40 'Other languages': 'Altre lingue',
44 'Other languages': '他の言語',
47 'English': 'Nederlands',
48 'Other languages': 'Andere talen',
52 'Other languages': '其他语言',
56 # needs at least: make -C po or make -C Documentation/po
59 #### this breaks on lilypond.org
60 # Keep some freakin' gettext compatibility
62 # import lilylib as ly;
64 #else: # poor mans translation
65 # def _ (string, lang=os.environ['LANG']):
66 # return translations.get (lang.split ('_')[0], {}).get (string, string)
68 #### this works on lilypond.org
70 return translations.get (lang.split ('_')[0], {}).get (string, string)
85 html_files = glob.glob( '*.html' )
88 ### messy way to get all languages
90 for file in html_files:
91 file_split = file.split('.')
92 if (len(file_split) == 2):
95 elif (len(file_split) == 3):
98 # make sure it's a translated language
101 langs = list(langs_set)
106 def addLangExt(filename, lang, ext):
109 for dir in exclude_manuals:
110 if (text.find(dir) >= 0):
112 if (not (exclude or (lang==""))):
117 def makeFooter (filename, currentLang):
118 footer = '''<p id="languages">
119 <!-- These links were autogenerated by %(me)s -->
127 str = '''<a href="%(file_name)s">%(language_name)s</a>'''
128 file_name = addLangExt (filename, lang, 'html')
129 language_name = _ ('English', lang)
130 return str % locals ()
131 lst = ', '.join ([link (lang) for lang in langs if lang != currentLang])
132 other = _ ('Other languages', currentLang)
133 browser_lang = _ ('About <a href="%s">automatic language selection</a>.', currentLang)
134 browser_language_url = "http://www.lilypond.org/website/misc/browser-language"
135 browser_language = browser_lang % browser_language_url
136 return footer % locals ()
138 def getLocalHref(line):
139 match = re.search(r'href=[\'"]?([^\'" >]+)', line)
141 url = match.group(0)[6:]
142 if (url[0:7] == "http://"):
156 for file in html_files:
157 ### we want to strip the .html and get the lang
158 file_split = file.split('.')
159 file_base = os.path.basename( file_split[0] )
160 if (len(file_split) == 2):
163 # possibly necessary for automatic language selection
164 file_symlink = file.replace(".html", ".en.html")
165 if not os.path.lexists (file_symlink):
166 os.symlink (file, file_symlink)
167 elif (len(file_split) == 3):
178 ### we need to replace parts of the file
179 lines = open(file).readlines()
181 outfile = open(file, 'w')
183 lang_footer = makeFooter (file_base, lang)
187 ### alter links as appropriate
188 link = getLocalHref(line)
191 if (not link.startswith("../doc/")):
192 if (link.endswith(".html")):
193 langlink = addLangExt(link[:-5], lang, "html")
194 line = line.replace(link, langlink)
195 if (link.endswith(".pdf")):
196 langlink = addLangExt(link[:-4], lang, "pdf")
197 line = line.replace(link, langlink)
198 ### add google tracker header
199 if (line.find("</head>") >= 0):
200 outfile.write("""<!-- Google tracking !-->
202 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
203 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
204 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
205 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
207 ga('create', 'UA-68969-1', 'auto');
208 ga('send', 'pageview');
212 #### add google tracker goals
213 if (line.find("href=\"http://download.linuxaudio.org") >= 0):
214 # TODO: more ugly hardcoding to make releases hard. :(
215 if (line.find('2.16') >= 0):
216 line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.16\');\" href=')
217 elif (line.find('2.17') >= 0):
218 line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.17\');\" href=')
219 ### add language selection footer
220 if (line.find("<div id=\"verifier_texinfo\">") >= 0):
221 outfile.write("<div id=\"footer\">\n")
222 outfile.write( lang_footer )
223 if (line.find("</body") >= 0):
224 outfile.write("</div>\n")