]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/create-weblinks-itexi.py
Add full example node translation script with output to create-weblinks.
[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 # don't add your language to this list unless you have all the
19 # items.
20 # Hmm, is this a feature -- why not keep original english as a fallback?
21 langs = ['', 'es', 'nl']
22
23 # Get/update node translations
24 '''
25 for i in es fr nl de hu ja it; do
26     echo "'"$i"': {"
27     (echo '--' ; grep -nH -B1 translationof Documentation/$i/web/*) \
28         | pytt '^--\n.*@(?:unnum|sub)[^ ]* (.*)\n.*@translationof (.*)\n' "'\2': '\1',\n" \
29         | grep -E 'Source|Learning|Glossary|Essay|Notation|Usage|Snippets|Web|Changes|Extending|Internals|Contributor'
30     echo "},"
31 done
32 '''
33
34 translations = {
35     'es': {
36         'Source': 'Código fuente',
37
38         'Learning': 'Aprendizaje',
39         'Music glossary': 'Glosario',
40         'Essay': 'Ensayo',
41         'Notation': 'Notación',
42         'Usage': 'Utilización',
43         'Snippets': 'Fragmentos',
44         'Web': 'Web',
45         'Changes': 'Cambios',
46         'Extending': 'Extensión',
47         'Internals': 'Funcionamiento interno',
48         'Contributor': 'Guía del colaborador',
49
50 # keep the spaces!
51         ' (split HTML)': ' (HTML seccionado)',
52         ' (big HTML)': ' (HTML monolítico)',
53
54         'Regression tests for ': 'Pruebas de regresión para ',
55         'PDF of regtests for ': 'Pruebas en PDF para ',
56         'MusicXML Regression tests for ': 'Pruebas de regresión de MusicXML para ',
57         'PDF of MusicXML regtests for ': 'Pruebas de MusicXML en PDF para ',
58
59         'Doc tarball for ': 'Tarball de la documentación para ',
60         ' (did not exist in 2.12)': ' (no existía en la versión 2.12)',
61      },
62     'fr': {
63         'Source': 'Sources',
64         'Learning': 'Initiation',
65         'Music glossary': 'Glossaire',
66         'Essay': 'Essai',
67         'Notation': 'Notation',
68         'Usage': 'Utilisation',
69         'Snippets': 'Morceaux choisis',
70         'Web': 'Web',
71         'Changes': 'Nouveautés',
72         'Internals': 'Propriétés internes',
73
74         #TODO
75         },
76     'nl': {
77         'Source': 'Broncode',
78
79         'Learning': 'Beginnen',
80         'Music glossary': 'Terminologie',
81         'Essay': 'Essay',
82         'Notation': 'Notatie',
83         'Usage': 'Gebruik',
84         'Snippets': 'Snippers',
85         'Web': 'Web',
86         'Changes': 'Veranderingen',
87         'Extending': 'Uitbreidingen',
88         'Internals': 'Internals',
89         'Contributor': 'Contributor',
90
91 # keep the spaces!
92         ' (split HTML)': ' (opgesplitste HTML)',
93         ' (big HTML)': ' (grote pagina HTML)',
94
95         'Regression tests for ': 'Regressietesten voor ',
96         'PDF of regtests for ': 'PDF van regressietesten voor ',
97         'MusicXML Regression tests for ': 'MusicXML regressietesten voor ',
98         'PDF of MusicXML regtests for ': 'MusicXML regressietesten voor ',
99
100         'Doc tarball for ': 'Tarball met documentation voor ',
101         ' (did not exist in 2.12)': ' (bestond nog niet in 2.12)',
102      },
103     'de': {
104         'Source': 'Quellen',
105         'Learning': 'Einführung',
106         'Music glossary': 'Glossar',
107         'Essay': 'Aufsatz',
108         'Notation': 'Notation',
109         'Usage': 'Benutzung',
110         'Snippets': 'Schnipsel',
111         'Web': 'Web',
112         'Changes': 'Änderungen',
113         'Internals': 'Interna',
114
115         #TODO
116         },
117     'hu': {
118         'Source': 'Forrás',
119         'Learning': 'Tankönyv',
120         'Music glossary': 'Fogalomtár',
121         'Essay': 'Esszé',
122         'Notation': 'Kottaírás',
123         'Usage': 'Használat',
124         'Snippets': 'Kódrészletek',
125         'Web': 'Web',
126         'Changes': 'Változások',
127         'Internals': 'Belső működés',
128
129         #TODO
130         },
131     'ja': {
132         'Source': 'ソース',
133         'Learning': '学習',
134         'Music glossary': '用語集',
135         'Essay': 'エッセー',
136         'Notation': '記譜法',
137         'Usage': '使用方法',
138         'Snippets': 'コード断片集',
139         'Web': 'Web',
140         'Changes': '変更点',
141         'Internals': '内部リファレンス',
142
143         #TODO
144         },
145     }
146
147
148
149
150 ### actual program
151
152
153 VERSION_STABLE = ""
154 VERSION_DEVEL = ""
155
156 try:
157     topDir = sys.argv[1]
158 except:
159     myDir = os.path.dirname(sys.argv[0])
160     # use two abspaths to work around some windows python bug
161     topDir = os.path.join(os.path.abspath(myDir)+os.sep+'..'+os.sep+'..'+os.sep)
162     topDir = os.path.abspath( topDir )
163
164
165 # TODO: this might be useful for other scripts; can we make it available?
166 manuals = map(lambda x: os.path.splitext(x)[0],
167               map(os.path.basename,
168                   glob.glob(os.path.join(topDir,'Documentation', '*.te??'))))
169 #manuals = map(lambda x: 'glossary' if x=='music-glossary' else x, manuals)
170 manuals.append('internals')
171
172
173 version_file_path = os.path.join(topDir, "VERSION")
174
175 version_contents = open(version_file_path).readlines()
176 major = 0
177 minor = 0
178 patch = 0
179 for line in version_contents:
180     if (line.startswith('MAJOR_VERSION')):
181         major = line[14:-1]
182     if (line.startswith('MINOR_VERSION')):
183         minor = line[14:-1]
184     if (line.startswith('PATCH_LEVEL')):
185         patch = line[12:-1]
186     if (line.startswith('VERSION_STABLE')):
187         VERSION_STABLE = line[15:-1]
188     if (line.startswith('VERSION_DEVEL')):
189         VERSION_DEVEL = line[14:-1]
190
191 VERSION = str(major)+'.'+str(minor)+'.'+str(patch)
192
193 def getTrans(text, lang):
194     if (lang != ''):
195         text = translations[lang][text]
196     return text
197
198 def macroLang(name, lang):
199     if (lang != ''):
200         return name + '-' + lang
201     return name
202
203 def make_macro(name, string):
204     print "@macro", name
205     print string
206     print "@end macro"
207     print ""
208
209 def make_download(name, osA, osB, version, revision, text):
210     string = "@uref{http://download.linuxaudio.org/lilypond/binaries/"
211     string += osA + "lilypond-"
212     string += version + "-" + revision
213     string += "." + osB + ",\n"
214     string += text
215     string += ": LilyPond "
216     string += version + "-" + revision
217     string += "}"
218     make_macro(name, string)
219
220 def make_download_source(name, vstring, version, lang):
221     string = "@uref{http://download.linuxaudio.org/lilypond/sources/"
222     string += vstring + "/"
223     string += "lilypond-" + version + ".tar.gz"
224     string += ", "
225     string += getTrans("Source", lang)
226     string += ": lilypond-" + version + ".tar.gz"
227     string += "}"
228     make_macro(macroLang(name,lang), string)
229
230 def make_all_downloads(macroName, version):
231     make_download("download"+macroName+"LinuxNormal", "linux-x86/",
232         "linux-x86.sh",    version, "1", "Linux x86")
233     make_download("download"+macroName+"LinuxBig", "linux-64/",
234         "linux-64.sh", version, "1", "Linux 64")
235     make_download("download"+macroName+"LinuxPPC", "linux-ppc/",
236         "linux-ppc.sh", version, "1", "Linux PPC")
237
238     make_download("download"+macroName+"FreeBSDNormal", "freebsd-x86/",
239         "freebsd-x86.sh", version, "1", "FreeBSD i386")
240     make_download("download"+macroName+"FreeBSDBig", "freebsd-64/",
241         "freebsd-64.sh", version, "1", "FreeBSD amd64")
242
243     make_download("download"+macroName+"DarwinNormal", "darwin-x86/",
244         "darwin-x86.tar.bz2", version, "1", "MacOS X x86")
245     make_download("download"+macroName+"DarwinPPC", "darwin-ppc/",
246         "darwin-ppc.tar.bz2", version, "1", "MacOS X PPC")
247
248     make_download("download"+macroName+"Windows", "mingw/",
249         "mingw.exe", version, "1", "Windows")
250
251 def make_ver_link(macroname, url, linktext):
252     string = "@uref{"
253     string += url
254     string += ","
255     string += linktext
256     string += "}"
257     make_macro(macroname, string)
258
259 # TODO: this kind of thing should really be in a central place for
260 # lilypond python build scripts
261 def translateNameToUrl(manual, version):
262     ver_split = version.split('.')
263     ver_minor = ver_split[0] + '.' + ver_split[1]
264     url = depth + "doc/v" + ver_minor + "/Documentation/"
265
266     if (ver_minor == '2.13'):
267         return url+manual
268     if (ver_minor == '2.12'):
269         if (manual=='learning'):
270             return url+'user/lilypond-learning'
271         elif (manual=='internals'):
272             return url+'user/lilypond-internals'
273         elif (manual=='notation'):
274             return url+'user/lilypond'
275         elif (manual=='usage'):
276             return url+'user/lilypond-program'
277         elif (manual=='snippets'):
278             return url+'../input/lsr/lilypond-snippets'
279         elif (manual=='changes'):
280             return url+'topdocs/NEWS.html'
281         elif (manual=='music-glossary'):
282             return url+'user/music-glossary'
283         elif (manual=='essay'):
284             return url+'user/lilypond-learning/Background.html'
285         elif (manual=='extending'):
286             return url+'user/lilypond/Interfaces-for-programmers.html'
287         else:
288             return ''
289
290
291 def make_manual_links(name, version, lang):
292     """Here is where all the macros manualStableLearningSplit,
293     manualStableLearningBig, manualStableLearningSplitNoName, etc. are
294     created on the fly.  Hopefully this documentation string will help
295     others a bit while grepping for those.
296     """
297     for m in manuals:
298         manual = m
299         # TODO: this is a stupid way of doing it
300         if (m=='music-glossary'):
301             mshort = 'Glossary'
302         else:
303             mshort = m.capitalize()
304         if (manual=='music-glossary'):
305             manual = 'Music glossary'
306         url = translateNameToUrl(m, version)
307
308         if (url == ''):
309             # can't have a comma here due to texinfo
310             make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
311                 "http://lilypond.org",
312                 mshort+getTrans(" (did not exist in 2.12)",lang))
313             make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
314                 "http://lilypond.org",
315                 mshort+getTrans(" (did not exist in 2.12)",lang))
316             make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
317                 "http://lilypond.org",
318                 mshort+getTrans(" (did not exist in 2.12)",lang))
319             make_ver_link(macroLang("manual"+name+mshort+'SplitNoName',lang),
320                 "http://lilypond.org",
321                 mshort+getTrans(" (did not exist in 2.12)",lang))
322             continue
323         make_ver_link(macroLang("manual"+name+mshort+'Pdf',lang),
324                   url + '.pdf',
325                   getTrans(manual.capitalize(),lang) + '.pdf')
326         make_ver_link(macroLang("manual"+name+mshort+'Split',lang),
327                   url + '/index.html',
328                   getTrans(manual.capitalize(),lang) +
329                   getTrans(' (split HTML)',lang))
330         make_ver_link(macroLang("manual"+name+mshort+'Big',lang),
331                   url + '-big-page.html',
332                   getTrans(manual.capitalize(),lang) +
333                   getTrans(' (big HTML)',lang))
334         # this is stupid and I shouldn't have bothered trying
335         # to support the 2.12 docs and it will be deleted once
336         # 2.14 is out and the website won't be visible to users
337         # until 2.14 is out.  -gp
338         if (url.endswith('.html')):
339             newurl = url
340         else:
341             newurl = url + '/index.html'
342         make_ver_link(macroLang("manual"+name+mshort+'SplitNoName',lang),
343                   newurl,
344                   getTrans(manual.capitalize(),lang))
345
346 def make_regtest_links(name, version, lang):
347     ver_split = version.split('.')
348     ver_minor = ver_split[0] + '.' + ver_split[1]
349     url = depth + "doc/v" + ver_minor + "/input/regression/"
350
351     make_ver_link(macroLang("regtest"+name, lang),
352         url+"collated-files.html",
353         getTrans("Regression tests for ", lang)+version)
354     make_ver_link(macroLang("regtest"+name+"Pdf", lang),
355         url+"collated-files.pdf",
356         getTrans("PDF of regtests for ", lang)+version)
357     make_ver_link(macroLang("regtest"+name+"Xml", lang),
358         url+"musicxml/collated-files.html",
359         getTrans("MusicXML Regression tests for ", lang)+version)
360     make_ver_link(macroLang("regtest"+name+"XmlPdf", lang),
361          url+"musicxml/collated-files.html",
362         getTrans("PDF of MusicXML regtests for ", lang)+version)
363
364 def make_doctarball_links(name, version, lang):
365     url = depth + "download/binaries/documentation/lilypond-"
366     # ugly FIXME, but proper build number support isn't Critical.
367     url += version + "-1"
368     url += ".documentation.tar.bz2"
369     make_ver_link(macroLang("doctarball"+name, lang),
370         url, getTrans("Doc tarball for ", lang)+version)
371
372 print "@c ************************ Download binaries ************"
373 make_all_downloads("Stable", VERSION_STABLE)
374 make_all_downloads("Devel", VERSION_DEVEL)
375
376 print "@c ************************ Download source ************"
377 # FIXME: icky hard-coding!  -gp
378 for lang in langs:
379     print "@c *********", lang, "***"
380     make_download_source("downloadStableSource","v2.12",VERSION_STABLE,lang)
381     make_download_source("downloadDevelSource","v2.13",VERSION_DEVEL,lang)
382
383 print "@c ************************ Manual links ************"
384 for lang in langs:
385     print "@c *********", lang, "***"
386     make_manual_links("Stable", VERSION_STABLE,lang)
387     make_manual_links("Devel", VERSION_DEVEL,lang)
388
389     make_doctarball_links("Stable", VERSION_STABLE,lang)
390     make_doctarball_links("Devel", VERSION_DEVEL,lang)
391
392 print "@c ************************ Regtest links ************"
393 for lang in langs:
394     print "@c *********", lang, "***"
395     make_regtest_links("Stable", VERSION_STABLE,lang)
396     make_regtest_links("Devel", VERSION_DEVEL,lang)
397
398