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