]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/build/website_post.py
Web: add Chinese webpage by Ben Luo, thanks!
[lilypond.git] / scripts / build / website_post.py
index 619693c4926389ac5c552f780afe7b75eb0d1ee8..ba2432e1967e6fe585acaf9f38f299de325cb18c 100644 (file)
@@ -9,24 +9,68 @@ 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 = {
+    'cs': {
+        'English': 'Česky',
+        'Other languages': 'Other languages',
+        },
+    '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': '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
@@ -48,7 +92,7 @@ for file in html_files:
         # it's a translation
         lang = file_split[1]
     # make sure it's a translated language
-    if (not (lang == "en")):
+    if lang != "en":
         langs_set.add(lang)
 langs = list(langs_set)
 langs.sort()
@@ -57,31 +101,30 @@ 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 = "<p id=\"languages\">\n"
-    text += lang_other_langs[currentLang]
-    for i in range(len(langs)):
-        lang = langs[i]
-        if (lang == currentLang):
-            continue
-        text += "<a href=\""
-       text += addLangExt(filename, lang, "html")
-        text += "\">"
-        text += lang_lookup[lang]
-        text += "</a>"
-        if (i < len(langs)-2):
-            text += ", "
-        else:
-            text += ".\n"
+def makeFooter (filename, currentLang):
     # TODO: add link to automatic language selection?
     # still need to include this page in the new webpages somewhere
-    text += "</p>\n"
-    return text
+    footer = '''<p id="languages">
+%(other)s: %(lst)s.
+</p>
+'''
+    def link (lang):
+        str = '''<a href="%(file_name)s">%(language_name)s</a>'''
+        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)
+    return footer % locals ()
 
 def getLocalHref(line):
     match = re.search(r'href=[\'"]?([^\'" >]+)', line)
@@ -128,24 +171,45 @@ for file in html_files:
     os.remove(file)
     outfile = open(file, 'w')
 
-    lang_footer = makeFooter(file_base, lang)
-
+    lang_footer = makeFooter (file_base, lang)
 
     ### alter file
     for line in lines:
         ### alter links as appropriate
         link = getLocalHref(line)
         if (link != ""):
-            link_base = link.split('.')[0]
-            if (link.endswith(".html")):
-               langlink = addLangExt(link_base, lang, "html")
-                line = line.replace(link, langlink)
-            if (link.endswith(".pdf")):
-               langlink = addLangExt(link_base, lang, "pdf")
-                line = line.replace(link, langlink)
+            # 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("</head>") >= 0):
+            outfile.write("""<!-- Google tracking !-->
+<script src="http://www.google-analytics.com/urchin.js"
+type="text/javascript">
+</script>
+<script type="text/javascript">
+_uacct = "UA-68969-1";
+urchinTracker();
+</script>
+""");
+        #### 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.12') >= 0):
+                line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.12\');\" href=')
+            elif (line.find('2.13') >= 0):
+                line = line.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.13\');\" href=')
         ### add language selection footer
-        if (line.find("<!-- FOOTER -->") >= 0):
+        if (line.find("<div id=\"verifier_texinfo\">") >= 0):
+            outfile.write("<div id=\"footer\">\n")
             outfile.write( lang_footer )
+        if (line.find("</body") >= 0):
+            outfile.write("</div>\n")
         outfile.write(line)
     outfile.close()