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 #### this breaks on lilypond.org
44 # Keep some freakin' gettext compatibility
46 # import lilylib as ly;
48 #else: # poor mans translation
49 # def _ (string, lang=os.environ['LANG']):
50 # return translations.get (lang.split ('_')[0], {}).get (string, string)
52 #### this works on lilypond.org
54 return translations.get (lang.split ('_')[0], {}).get (string, string)
69 html_files = glob.glob( '*.html' )
72 ### messy way to get all languages
74 for file in html_files:
75 file_split = file.split('.')
76 if (len(file_split) == 2):
79 elif (len(file_split) == 3):
82 # make sure it's a translated language
85 langs = list(langs_set)
90 def addLangExt(filename, lang, ext):
93 for dir in exclude_manuals:
94 if (text.find(dir) >= 0):
96 if (not (exclude or (lang==""))):
101 def makeFooter (filename, currentLang):
102 # TODO: add link to automatic language selection?
103 # still need to include this page in the new webpages somewhere
104 footer = '''<p id="languages">
109 str = '''<a href="%(file_name)s">%(language_name)s</a>'''
110 file_name = addLangExt (filename, lang, 'html')
111 language_name = _ ('English', lang)
112 return str % locals ()
113 lst = ', '.join ([link (lang) for lang in langs if lang != currentLang])
114 other = _ ('Other languages', currentLang)
115 return footer % locals ()
117 def getLocalHref(line):
118 match = re.search(r'href=[\'"]?([^\'" >]+)', line)
120 url = match.group(0)[6:]
121 if (url[0:7] == "http://"):
135 for file in html_files:
136 ### we want to strip the .html and get the lang
137 file_split = file.split('.')
138 file_base = os.path.basename( file_split[0] )
139 if (len(file_split) == 2):
142 # possibly necessary for automatic language selection
143 file_symlink = file.replace(".html", ".en.html")
144 if (not (os.path.exists(file_symlink))):
145 os.symlink (file, file_symlink)
146 elif (len(file_split) == 3):
157 ### we need to replace parts of the file
158 lines = open(file).readlines()
160 outfile = open(file, 'w')
162 lang_footer = makeFooter (file_base, lang)
166 ### alter links as appropriate
167 link = getLocalHref(line)
170 if (link.endswith(".html")):
171 langlink = addLangExt(link[:-5], lang, "html")
172 line = line.replace(link, langlink)
173 if (link.endswith(".pdf")):
174 langlink = addLangExt(link[:-4], lang, "pdf")
175 line = line.replace(link, langlink)
176 ### add language selection footer
177 if (line.find("<!-- FOOTER -->") >= 0):
178 outfile.write( lang_footer )