]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/create-weblinks-itexi.py
Merge branch 'translation' into staging
[lilypond.git] / scripts / build / create-weblinks-itexi.py
1 #!@PYTHON@
2 # -*- coding: utf-8 -*-
3 # create-weblinks-itexi.py
4
5 """ when being called on lilypond.org, pass it the location of the
6 top source dir on the command-line. """
7
8 import sys
9 import os
10 import glob
11
12 ### translation data -- shouldn't be here; see issue
13 ### http://code.google.com/p/lilypond/issues/detail?id=1050
14
15 import langdefs
16 # GUB only has python 2.4 !!!
17 # langs = [i.code if i.code != 'en' else '' for i in langdefs.WEB_LANGUAGES]
18 langs = []
19 for lang in langdefs.WEB_LANGUAGES:
20     if lang.code == 'en':
21         langs.append('')
22     else:
23         langs.append(lang.code)
24
25
26 # these links are relative from /website/ on lilypond.org
27 depth = "../"
28
29 # Get/update node translations
30 '''
31 for i in cs de es fr hu it ja nl zh; do
32     echo "'"$i"': {"
33     (echo '--' ; grep -nH -B1 translationof Documentation/$i/web/* ) \
34         | pytt '^--\n.*@(?:unnum|sub)[^ ]* (.*)\n.*@translationof (.*)\n' "'\2': '\1',\n" \
35         | grep -E 'Source|Learning|Glossary|Essay|Notation|Usage|Snippets|Web|Changes|Extending|Internals|Contributor'
36     echo "},"
37 done
38 '''
39
40 translations = {
41     'de': {
42         'Source': 'Quellen',
43         'Learning': 'Einführung',
44         'Music glossary': 'Glossar',
45         'Essay': 'Aufsatz',
46         'Notation': 'Notation',
47         'Usage': 'Benutzung',
48         'Snippets': 'Schnipsel',
49         'Web': 'Web',
50         'Changes': 'Änderungen',
51
52         'Extending': 'Erweitern',
53         'Internals': 'Interna',
54         'Contributor': 'Beitragen',
55
56         ' (split HTML)': ' (geteiltes HTML)',
57         ' (big HTML)': ' (großes HTML)',
58
59         'Regression tests for ': 'Regressionstests für ',
60         'PDF of regtests for ': 'PDF der Regressionstests für ',
61         'abc2ly Regression tests for ': 'abc2ly Regressionstests für ',
62         'PDF of abc2ly regtests for ': 'PDF der abc2ly Regressionstests für ',
63         'lilypond-book Regression tests for ': 'lilypond-book Regressionstests für ',
64         'PDF of lilypond-book regtests for ': 'PDF der lilypond-book Regressionstests für ',
65         'MusicXML Regression tests for ': 'MusicXML Regressionstests für ',
66         'PDF of MusicXML regtests for ': 'PDF der MusicXML Regressionstests für ',
67
68         'Doc tarball for ': 'Dokumentation tar-gepackt für ',
69         ' (did not exist in 2.12)': ' (nicht existent in 2.12)',
70         },
71     'es': {
72         'Source': 'Código fuente',
73
74         'Learning': 'Aprendizaje',
75         'Music glossary': 'Glosario',
76         'Essay': 'Ensayo',
77         'Notation': 'Notación',
78         'Usage': 'Utilización',
79         'Snippets': 'Fragmentos',
80         'Web': 'Web',
81         'Changes': 'Cambios',
82         'Extending': 'Extensión',
83         'Internals': 'Funcionamiento interno',
84         'Contributor': 'Guía del colaborador',
85
86 # keep the spaces!
87         ' (split HTML)': ' (HTML seccionado)',
88         ' (big HTML)': ' (HTML monolítico)',
89
90         'Regression tests for ': 'Pruebas de regresión para ',
91         'PDF of regtests for ': 'Pruebas en PDF para ',
92         'abc2ly Regression tests for ': 'Pruebas de regresión de abc2ly para ',
93         'PDF of abc2ly regtests for ': 'Pruebas de abc2ly en PDF para ',
94         'lilypond-book Regression tests for ': 'Pruebas de regresión de lilypond-book para ',
95         'PDF of lilypond-book regtests for ': 'Pruebas de lilypond-book en PDF para ',
96         'MusicXML Regression tests for ': 'Pruebas de regresión de MusicXML para ',
97         'PDF of MusicXML regtests for ': 'Pruebas de MusicXML en PDF para ',
98
99         'Doc tarball for ': 'Tarball de la documentación para ',
100         ' (did not exist in 2.12)': ' (no existía en la versión 2.12)',
101      },
102     'fr': {
103         'Source': 'Sources',
104
105         'Learning': 'Initiation',
106         'Music glossary': 'Glossaire',
107         'Essay': 'Essai',
108         'Notation': 'Notation',
109         'Usage': 'Utilisation',
110         'Snippets': 'Morceaux choisis',
111         'Web': 'Web',
112         'Changes': 'Nouveautés',
113         'Extending': 'Extension',
114         'Internals': 'Propriétés internes',
115         'Contributor': 'Guide du contributeur',
116
117 # keep the spaces!
118         ' (split HTML)': ' (HTML multipages)',
119         ' (big HTML)': ' (HTML en page unique)',
120
121         'Regression tests for ': 'Tests de régression pour ',
122         'PDF of regtests for ': 'PDF des tests de régression pour ',
123         'abc2ly Regression tests for ': 'Tests de régression de abc2ly pour ',
124         'PDF of abc2ly regtests for ': 'PDF des tests de régression de abc2ly pour ',
125         'lilypond-book Regression tests for ': 'Tests de régression de lilypond-book pour ',
126         'PDF of lilypond-book regtests for ': 'PDF des tests de régression de lilypond-book pour ',
127         'MusicXML Regression tests for ': 'Tests de régression de MusicXML pour ',
128         'PDF of MusicXML regtests for ': 'PDF des tests de régression de MusicXML pour ',
129
130         'Doc tarball for ': 'Archive de la documentation pour ',
131         ' (did not exist in 2.12)': ' (non disponible pour la version 2.12)',
132         },
133     'hu': {
134         'Source': 'Forrás',
135         'Learning': 'Tankönyv',
136         'Music glossary': 'Fogalomtár',
137         'Essay': 'Esszé',
138         'Notation': 'Kottaírás',
139         'Usage': 'Használat',
140         'Snippets': 'Kódrészletek',
141         'Web': 'Web',
142         'Changes': 'Változások',
143         'Extending': 'Bővítés',
144         'Internals': 'Belső működés',
145         'Contributor': 'Közreműködés',
146
147         ' (split HTML)': ' (HTML oldalak)',
148         ' (big HTML)': ' (egy nagy HTML oldal)',
149
150         'Regression tests for ': 'Regressziós tesztek - verzió: ',
151         'PDF of regtests for ': 'PDF formátumban - verzió: ',
152         'abc2ly Regression tests for ': 'abc2ly regressziós tesztek - verzió: ',
153         'PDF of abc2ly regtests for ': 'PDF formátumban - verzió: ',
154         'lilypond-book Regression tests for ': 'lilypond-book regressziós tesztek - verzió: ',
155         'PDF of lilypond-book regtests for ': 'PDF formátumban - verzió: ',
156         'MusicXML Regression tests for ': 'MusicXML regressziós tesztek - verzió: ',
157         'PDF of MusicXML regtests for ': 'PDF formátumban - verzió: ',
158
159         'Doc tarball for ': 'Tömörített csomag - verzió: ',
160         ' (did not exist in 2.12)': ' (nem létezett a 2.12-es verzióban)',
161         },
162     'ja': {
163         'Source': 'ソース',
164         'Learning': '学習',
165         'Music glossary': '用語集',
166         'Essay': 'エッセー',
167         'Notation': '記譜法',
168         'Usage': '使用方法',
169         'Snippets': 'コード断片集',
170         'Web': 'Web',
171         'Changes': '変更点',
172
173         #TODO
174         'Extending': '拡張',
175         'Internals': '内部リファレンス',
176         'Contributor': '貢献者向けガイド',
177
178 # keep the spaces!
179         ' (split HTML)': ' (ページ毎に分割された HTML)',
180         ' (big HTML)': ' (1 つの大きな HTML)',
181
182         'Regression tests for ': '回帰テスト バージョン ',
183         'PDF of regtests for ': '回帰テスト (PDF 版) バージョン ',
184         'abc2ly Regression tests for ': 'abc2ly 回帰テスト バージョン ',
185         'PDF of abc2ly regtests for ': 'abc2ly 回帰テスト (PDF 版) バージョン ',
186         'lilypond-book Regression tests for ': 'lilypond-book 回帰テスト バージョン ',
187         'PDF of lilypond-book regtests for ': 'lilypond-book 回帰テスト (PDF 版) バージョン ',
188         'MusicXML Regression tests for ': 'MusicXML 回帰テスト バージョン ',
189         'PDF of MusicXML regtests for ': 'MusicXML 回帰テスト (PDF 版) バージョン ',
190
191         'Doc tarball for ': 'ドキュメント アーカイブ バージョン ',
192         ' (did not exist in 2.12)': ' (バージョン 2.12 には存在しません)',
193
194         },
195     'nl': {
196         'Source': 'Broncode',
197
198         'Learning': 'Beginnen',
199         'Music glossary': 'Terminologie',
200         'Essay': 'Essay',
201         'Notation': 'Notatie',
202         'Usage': 'Gebruik',
203         'Snippets': 'Snippers',
204         'Web': 'Web',
205         'Changes': 'Veranderingen',
206         'Extending': 'Uitbreidingen',
207         'Internals': 'Internals',
208         'Contributor': 'Contributor',
209
210 # keep the spaces!
211         ' (split HTML)': ' (opgesplitste HTML)',
212         ' (big HTML)': ' (grote pagina HTML)',
213
214         'Regression tests for ': 'Regressietesten voor ',
215         'PDF of regtests for ': 'PDF van regressietesten voor ',
216         'abc2ly Regression tests for ': 'abc2ly regressietesten voor ',
217         'PDF of abc2ly regtests for ': 'abc2ly regressietesten voor ',
218         'lilypond-book Regression tests for ': 'lilypond-book regressietesten voor ',
219         'PDF of lilypond-book regtests for ': 'lilypond-book regressietesten voor ',
220         'MusicXML Regression tests for ': 'MusicXML regressietesten voor ',
221         'PDF of MusicXML regtests for ': 'MusicXML regressietesten voor ',
222
223         'Doc tarball for ': 'Tarball met documentation voor ',
224         ' (did not exist in 2.12)': ' (bestond nog niet in 2.12)',
225      },
226     'zh': {
227         'Source': '源码',
228         'Learning': '学习',
229         'Music glossary': '音乐术语表',
230         'Essay': '文章',
231         'Notation': '记谱法',
232         'Usage': '使用',
233         'Snippets': '片断',
234         'Web': 'Web',
235         'Changes': '变化',
236
237         'Extending': '扩展',
238         'Internals': '内部机制',
239         'Contributor': '贡献者',
240
241 # keep the spaces!
242         ' (split HTML)': ' (分开的 HTML)',
243         ' (big HTML)': ' (大的 HTML)',
244
245         'Regression tests for ': '回归测试 ',
246         'PDF of regtests for ': '回归测试的 PDF ',
247         'abc2ly Regression tests for ': 'abc2ly 回归测试 ',
248         'PDF of abc2ly regtests for ': 'abc2ly 的 PDF 回归测试 ',
249         'lilypond-book Regression tests for ': 'lilypond-book 回归测试 ',
250         'PDF of lilypond-book regtests for ': 'lilypond-book 的 PDF 回归测试 ',
251         'MusicXML Regression tests for ': 'MusicXML 回归测试 ',
252         'PDF of MusicXML regtests for ': 'MusicXML 的 PDF 回归测试 ',
253
254         'Doc tarball for ': '为文档压缩包',
255         ' (did not exist in 2.12)': ' (在 2.12 中不存在)',
256         },
257     }
258
259
260
261
262 ### actual program
263
264
265 VERSION_STABLE = ""
266 VERSION_DEVEL = ""
267
268 try:
269     topDir = sys.argv[1]
270 except:
271     myDir = os.path.dirname(sys.argv[0])
272     # use two abspaths to work around some windows python bug
273     topDir = os.path.join(os.path.abspath(myDir)+os.sep+'..'+os.sep+'..'+os.sep)
274     topDir = os.path.abspath( topDir )
275
276
277 # TODO: this might be useful for other scripts; can we make it available?
278 manuals = map(lambda x: os.path.splitext(x)[0],
279               map(os.path.basename,
280                   glob.glob(os.path.join(topDir,'Documentation', '*.te??'))))
281 #manuals = map(lambda x: 'glossary' if x=='music-glossary' else x, manuals)
282 manuals.append('internals')
283
284
285 version_file_path = os.path.join(topDir, "VERSION")
286
287 version_contents = open(version_file_path).readlines()
288 major = 0
289 minor = 0
290 patch = 0
291 for line in version_contents:
292     if (line.startswith('MAJOR_VERSION')):
293         major = line[14:-1]
294     if (line.startswith('MINOR_VERSION')):
295         minor = line[14:-1]
296     if (line.startswith('PATCH_LEVEL')):
297         patch = line[12:-1]
298     if (line.startswith('VERSION_STABLE')):
299         VERSION_STABLE = line[15:-1]
300     if (line.startswith('VERSION_DEVEL')):
301         VERSION_DEVEL = line[14:-1]
302
303 VERSION = str(major)+'.'+str(minor)+'.'+str(patch)
304
305 def _ (string, lang):
306     return translations.get (lang.split ('_')[0], {}).get (string, None)
307
308 getTrans = _
309 # let's not barf, but print a warning when something's missing
310 def getTrans(text, lang):
311     if not lang:
312         return text
313     trans = _ (text, lang)
314     if not trans:
315         trans = text
316         sys.stderr.write ('create-weblinks-itexi: warning: [%(lang)s]: translation missing for: %(text)s\n' % locals ())
317     return trans
318
319 def macroLang(name, lang):
320     if lang:
321         return name + '-' + lang
322     return name
323
324 def make_macro(name, string):
325     print "@macro", name
326     print string
327     print "@end macro"
328     print ""
329
330 def make_download(name, osA, osB, version, revision, text):
331     string = "@uref{http://download.linuxaudio.org/lilypond/binaries/"
332     string += osA + "lilypond-"
333     string += version + "-" + revision
334     string += "." + osB + ",\n"
335     string += text
336     string += ": LilyPond "
337     string += version + "-" + revision
338     string += "}"
339     make_macro(name, string)
340
341 def make_download_source(name, version, lang):
342     assert "." in version
343     vstring = "v%s.%s" % tuple(version.split(".", 2)[0:2])
344     string = "@uref{http://download.linuxaudio.org/lilypond/sources/"
345     string += vstring + "/"
346     string += "lilypond-" + version + ".tar.gz"
347     string += ", "
348     string += getTrans("Source", lang)
349     string += ": lilypond-" + version + ".tar.gz"
350     string += "}"
351     make_macro(macroLang(name,lang), string)
352
353 def make_all_downloads(macroName, version):
354     make_download("download"+macroName+"LinuxNormal", "linux-x86/",
355         "linux-x86.sh",    version, "1", "GNU/Linux x86")
356     make_download("download"+macroName+"LinuxBig", "linux-64/",
357         "linux-64.sh", version, "1", "GNU/Linux 64")
358     make_download("download"+macroName+"LinuxPPC", "linux-ppc/",
359         "linux-ppc.sh", version, "1", "GNU/Linux PPC")
360
361     make_download("download"+macroName+"FreeBSDNormal", "freebsd-x86/",
362         "freebsd-x86.sh", version, "1", "FreeBSD i386")
363     make_download("download"+macroName+"FreeBSDBig", "freebsd-64/",
364         "freebsd-64.sh", version, "1", "FreeBSD amd64")
365
366     make_download("download"+macroName+"DarwinNormal", "darwin-x86/",
367         "darwin-x86.tar.bz2", version, "1", "MacOS X x86")
368     make_download("download"+macroName+"DarwinPPC", "darwin-ppc/",
369         "darwin-ppc.tar.bz2", version, "1", "MacOS X PPC")
370
371     make_download("download"+macroName+"Windows", "mingw/",
372         "mingw.exe", version, "1", "Windows")
373
374 def make_ver_link(macroname, url, linktext):
375     string = "@uref{"
376     string += url
377     string += ","
378     string += linktext
379     string += "}"
380     make_macro(macroname, string)
381
382 # TODO: this kind of thing should really be in a central place for
383 # lilypond python build scripts
384 def translateNameToUrl(manual, version):
385     ver_split = version.split('.')
386     ver_minor = ver_split[0] + '.' + ver_split[1]
387     url = depth + "doc/v" + ver_minor + "/Documentation/"
388
389     if (ver_minor == '2.12'):
390         if (manual=='learning'):
391             return url+'user/lilypond-learning'
392         elif (manual=='internals'):
393             return url+'user/lilypond-internals'
394         elif (manual=='notation'):
395             return url+'user/lilypond'
396         elif (manual=='usage'):
397             return url+'user/lilypond-program'
398         elif (manual=='snippets'):
399             return url+'../input/lsr/lilypond-snippets'
400         elif (manual=='changes'):
401             return url+'topdocs/NEWS.html'
402         elif (manual=='music-glossary'):
403             return url+'user/music-glossary'
404         elif (manual=='essay'):
405             return url+'user/lilypond-learning/Background.html'
406         elif (manual=='extending'):
407             return url+'user/lilypond/Interfaces-for-programmers.html'
408         else:
409             return ''
410     else:
411         return url+manual
412
413 def addLang(url, lang):
414     if lang:
415         base, ext = os.path.splitext(url)
416         return base + '.' + lang + ext
417     else:
418         return url
419
420 def make_manual_links(name, version, lang):
421     """Here is where all the macros manualStableLearningSplit,
422     manualStableLearningBig, manualStableLearningSplitNoName, etc. are
423     created on the fly.  Hopefully this documentation string will help
424     others a bit while grepping for those.
425     """
426     for m in manuals:
427         manual = m
428         # TODO: this is a stupid way of doing it
429         if (m=='music-glossary'):
430             mshort = 'Glossary'
431         else:
432             mshort = m.capitalize()
433         if (manual=='music-glossary'):
434             manual = 'Music glossary'
435         url = translateNameToUrl(m, version)
436
437         if (url == ''):
438             # can't have a comma here due to texinfo
439             make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
440                 "http://lilypond.org",
441                 mshort+getTrans(" (did not exist in 2.12)",lang))
442             make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
443                 "http://lilypond.org",
444                 mshort+getTrans(" (did not exist in 2.12)",lang))
445             make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
446                 "http://lilypond.org",
447                 mshort+getTrans(" (did not exist in 2.12)",lang))
448             make_ver_link(macroLang("manual"+name+mshort+'SplitNoName',lang),
449                 "http://lilypond.org",
450                 mshort+getTrans(" (did not exist in 2.12)",lang))
451             continue
452         # this is stupid and I shouldn't have bothered trying
453         # to support the 2.12 docs and it will be deleted once
454         # 2.14 is out and the website won't be visible to users
455         # until 2.14 is out.  -gp
456         if (url.endswith('.html')):
457             make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
458                       addLang(url, lang),
459                       getTrans(manual.capitalize(),lang) + '.pdf')
460             make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
461                       addLang(url, lang),
462                       getTrans(manual.capitalize(),lang) +
463                       getTrans(' (split HTML)',lang))
464             make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
465                       addLang(url, lang),
466                       getTrans(manual.capitalize(),lang) +
467                       getTrans(' (big HTML)',lang))
468             newurl = url
469         else:
470             make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
471                       # TODO: this is an even stupider way of doing it
472                       addLang(url+'.pdf', lang),
473                       getTrans(manual.capitalize(),lang) + '.pdf')
474             make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
475                       addLang(url + '/index.html', lang),
476                       getTrans(manual.capitalize(),lang) +
477                       getTrans(' (split HTML)',lang))
478             make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
479                       addLang(url + '-big-page.html', lang),
480                       getTrans(manual.capitalize(),lang) +
481                       getTrans(' (big HTML)',lang))
482             newurl = url + '/index.html'
483         make_ver_link(macroLang("manual"+name+mshort+'SplitNoName',lang),
484                   addLang(newurl, lang),
485                   getTrans(manual.capitalize(),lang))
486
487 def make_regtest_links(name, version, lang):
488     ver_split = version.split('.')
489     ver_minor = ver_split[0] + '.' + ver_split[1]
490     url = depth + "doc/v" + ver_minor + "/input/regression/"
491
492     make_ver_link(macroLang("regtest"+name, lang),
493         url+"collated-files.html",
494         getTrans("Regression tests for ", lang)+version)
495     make_ver_link(macroLang("regtest"+name+"Pdf", lang),
496         url+"collated-files.pdf",
497         getTrans("PDF of regtests for ", lang)+version)
498     make_ver_link(macroLang("regtest"+name+"Xml", lang),
499         url+"musicxml/collated-files.html",
500         getTrans("MusicXML Regression tests for ", lang)+version)
501     make_ver_link(macroLang("regtest"+name+"Abc", lang),
502         url+"abc2ly/collated-files.html",
503         getTrans("abc2ly Regression tests for ", lang)+version)
504     make_ver_link(macroLang("regtest"+name+"LilypondBook", lang),
505         url+"lilypond-book/collated-files.html",
506         getTrans("lilypond-book Regression tests for ", lang)+version)
507     make_ver_link(macroLang("regtest"+name+"XmlPdf", lang),
508          url+"musicxml/collated-files.pdf",
509         getTrans("PDF of MusicXML regtests for ", lang)+version)
510     make_ver_link(macroLang("regtest"+name+"AbcPdf", lang),
511          url+"abc2ly/collated-files.pdf",
512         getTrans("PDF of abc2ly regtests for ", lang)+version)
513     make_ver_link(macroLang("regtest"+name+"LilypondBookPdf", lang),
514          url+"lilypond-book/collated-files.pdf",
515         getTrans("PDF of lilypond-book regtests for ", lang)+version)
516
517 def make_doctarball_links(name, version, lang):
518     url = depth + "download/binaries/documentation/lilypond-"
519     # ugly FIXME, but proper build number support isn't Critical.
520     url += version + "-1"
521     url += ".documentation.tar.bz2"
522     make_ver_link(macroLang("doctarball"+name, lang),
523         url, getTrans("Doc tarball for ", lang)+version)
524
525 print "@c This file was autogenerated"
526 print "@c     from: VERSION"
527 print "@c     by:   %s" % sys.argv[0]
528 print ""
529 print "@c ************************ Download binaries ************"
530 print ""
531
532 make_all_downloads("Stable", VERSION_STABLE)
533 make_all_downloads("Devel", VERSION_DEVEL)
534
535 print "@c ************************ Download source ************"
536 print ""
537
538 for lang in langs:
539     print "@c *********", lang or "en", "***"
540     make_download_source("downloadStableSource", VERSION_STABLE, lang)
541     make_download_source("downloadDevelSource", VERSION_DEVEL, lang)
542
543 print "@c ************************ Manual links ************"
544 print ""
545
546 for lang in langs:
547     print "@c *********", lang or "en", "***"
548     make_manual_links("Stable", VERSION_STABLE, lang)
549     make_manual_links("Devel", VERSION_DEVEL, lang)
550
551     make_doctarball_links("Stable", VERSION_STABLE, lang)
552     make_doctarball_links("Devel", VERSION_DEVEL, lang)
553
554 print "@c ************************ Regtest links ************"
555 print ""
556
557 for lang in langs:
558     print "@c *********", lang or "en", "***"
559     make_regtest_links("Stable", VERSION_STABLE, lang)
560     make_regtest_links("Devel", VERSION_DEVEL, lang)
561 print "@c ***************************************************"