X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fbuild%2Fwebsite_post.py;h=a6fafdc01251bb38559f84d2dc3c337855881029;hb=59edf02a1acae41e21a080617aa7bd8673125762;hp=9d64cb18b098df00fc2dcffe9180516aeb627bb7;hpb=d0a646e2fe26bad80e178d0331ba3c4684bb9017;p=lilypond.git diff --git a/scripts/build/website_post.py b/scripts/build/website_post.py index 9d64cb18b0..a6fafdc012 100644 --- a/scripts/build/website_post.py +++ b/scripts/build/website_post.py @@ -1,7 +1,7 @@ #!@PYTHON@ #-*- coding: utf-8 -*- -##### This is web_post.py. This script deals with translations +##### This is website_post.py. This script deals with translations ##### in the "make website" target. import sys @@ -9,24 +9,72 @@ import os import glob import re -###### Translation data -lang_lookup = { - 'fr': 'français', - 'es': 'español', - '': 'english' -} - -lang_other_langs = { - 'es': 'Otros idiomas: ', - 'fr': 'Autres langues : ', - '': 'Other languages: ' -} - -exclude_pages = [ - 'music-glossary', - 'snippets', - 'internals', - 'contributor' +###### Translation data, move out, see create-weblinks-itexi.py +translations = { + 'ca': { + 'English': 'Català', + 'Other languages': 'Altres idiomes', + }, + 'cs': { + 'English': 'Česky', + 'Other languages': 'Jiné jazyky', + }, + 'de': { + 'English': 'Deutsch', + 'Other languages': 'Andere Sprachen', + }, + 'es': { + 'English': 'Español', + 'Other languages': 'Otros idiomas', + }, + 'fr': { + 'English': 'Français', + 'Other languages': 'Autres langues', + }, + 'hu': { + 'English': 'Magyar', + 'Other languages': 'Más nyelvek', + }, + 'it': { + 'English': 'Italiano', + 'Other languages': 'Altre lingue', + }, + 'ja': { + 'English': '日本語', + 'Other languages': '他の言語', + }, + 'nl': { + 'English': 'Nederlands', + 'Other languages': 'Andere talen', + }, + 'zh': { + 'English': '中文', + 'Other languages': '其他语言', + }, + } + +# needs at least: make -C po or make -C Documentation/po +HAVE_GETTEXT = False + +#### this breaks on lilypond.org +# Keep some freakin' gettext compatibility +#if HAVE_GETTEXT: +# import lilylib as ly; +# global _;_=ly._ +#else: # poor mans translation +# def _ (string, lang=os.environ['LANG']): +# return translations.get (lang.split ('_')[0], {}).get (string, string) + +#### this works on lilypond.org +def _ (string, lang): + return translations.get (lang.split ('_')[0], {}).get (string, string) + + +exclude_manuals = [ + '/music-glossary', + '/snippets', + '/internals', + '/contributor' ] ###### Actual program @@ -47,9 +95,9 @@ for file in html_files: elif (len(file_split) == 3): # it's a translation lang = file_split[1] - # make sure it's a translated language - if (not (lang == "en")): - langs_set.add(lang) + # make sure it's a translated language + if lang != "en": + langs_set.add(lang) langs = list(langs_set) langs.sort() @@ -57,31 +105,35 @@ langs.sort() ### helper functions def addLangExt(filename, lang, ext): text = filename - if (not (lang=="")): + exclude = 0 + for dir in exclude_manuals: + if (text.find(dir) >= 0): + exclude = 1 + if (not (exclude or (lang==""))): text += "." + lang text += "." + ext return text -def makeFooter(filename, currentLang): - text = "

\n" - text += lang_other_langs[currentLang] - for i in range(len(langs)): - lang = langs[i] - if (lang == currentLang): - continue - text += "" - text += lang_lookup[lang] - text += "" - if (i < len(langs)-2): - text += ", " - else: - text += ".\n" - # TODO: add link to automatic language selection? - # still need to include this page in the new webpages somewhere - text += "

\n" - return text +def makeFooter (filename, currentLang): + footer = '''

+ +%(other)s: %(lst)s. +
+%(browser_language)s +

+''' + me = sys.argv[0] + def link (lang): + str = '''%(language_name)s''' + file_name = addLangExt (filename, lang, 'html') + language_name = _ ('English', lang) + return str % locals () + lst = ', '.join ([link (lang) for lang in langs if lang != currentLang]) + other = _ ('Other languages', currentLang) + browser_lang = _ ('About automatic language selection.', currentLang) + browser_language_url = "http://www.lilypond.org/website/misc/browser-language" + browser_language = browser_lang % browser_language_url + return footer % locals () def getLocalHref(line): match = re.search(r'href=[\'"]?([^\'" >]+)', line) @@ -110,7 +162,7 @@ for file in html_files: lang = '' # possibly necessary for automatic language selection file_symlink = file.replace(".html", ".en.html") - if (not (os.path.exists(file_symlink))): + if not os.path.lexists (file_symlink): os.symlink (file, file_symlink) elif (len(file_split) == 3): # it's a translation @@ -128,21 +180,44 @@ for file in html_files: os.remove(file) outfile = open(file, 'w') - lang_footer = makeFooter(file_base, lang) + lang_footer = makeFooter (file_base, lang) - - ### replace links as appropraite + ### alter file for line in lines: + ### alter links as appropriate link = getLocalHref(line) if (link != ""): - link_base = link.split('.')[0] - if (line.endswith(".html")): - langlink = addLangExt(link_base, lang, "html") - line.replace(link, langlink) - if (line.endswith(".pdf")): - langlink = addLangExt(link_base, lang, "pdf") - if (line.find("") >= 0): + # questionable + if (not link.startswith("../doc/")): + if (link.endswith(".html")): + langlink = addLangExt(link[:-5], lang, "html") + line = line.replace(link, langlink) + if (link.endswith(".pdf")): + langlink = addLangExt(link[:-4], lang, "pdf") + line = line.replace(link, langlink) + ### add google tracker header + if (line.find("") >= 0): + outfile.write(""" + + +"""); + #### add google tracker goals + if (line.find("href=\"http://download.linuxaudio.org") >= 0): + # TODO: more ugly hardcoding to make releases hard. :( + if (line.find('2.16') >= 0): + line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.16\');\" href=') + elif (line.find('2.17') >= 0): + line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.17\');\" href=') + ### add language selection footer + if (line.find("
") >= 0): + outfile.write("
\n") outfile.write( lang_footer ) + if (line.find("= 0): + outfile.write("
\n") outfile.write(line) outfile.close() -