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': 'Italiano',
32 'Other languages': 'Altre lingue',
35 'English': 'Japanese',
36 'Other languages': '他の言語',
39 'English': 'Nederlands',
40 'Other languages': 'Andere talen',
44 # needs at least: make -C po or make- C Documentation/po
47 #### this breaks on lilypond.org
48 # Keep some freakin' gettext compatibility
50 # import lilylib as ly;
52 #else: # poor mans translation
53 # def _ (string, lang=os.environ['LANG']):
54 # return translations.get (lang.split ('_')[0], {}).get (string, string)
56 #### this works on lilypond.org
58 return translations
.get (lang
.split ('_')[0], {}).get (string
, string
)
73 html_files
= glob
.glob( '*.html' )
76 ### messy way to get all languages
78 for file in html_files
:
79 file_split
= file.split('.')
80 if (len(file_split
) == 2):
83 elif (len(file_split
) == 3):
86 # make sure it's a translated language
89 langs
= list(langs_set
)
94 def addLangExt(filename
, lang
, ext
):
97 for dir in exclude_manuals
:
98 if (text
.find(dir) >= 0):
100 if (not (exclude
or (lang
==""))):
105 def makeFooter (filename
, currentLang
):
106 # TODO: add link to automatic language selection?
107 # still need to include this page in the new webpages somewhere
108 footer
= '''<p id="languages">
113 str = '''<a href="%(file_name)s">%(language_name)s</a>'''
114 file_name
= addLangExt (filename
, lang
, 'html')
115 language_name
= _ ('English', lang
)
116 return str % locals ()
117 lst
= ', '.join ([link (lang
) for lang
in langs
if lang
!= currentLang
])
118 other
= _ ('Other languages', currentLang
)
119 return footer
% locals ()
121 def getLocalHref(line
):
122 match
= re
.search(r
'href=[\'"]?([^\'" >]+)', line)
124 url = match.group(0)[6:]
125 if (url[0:7] == "http://"):
139 for file in html_files
:
140 ### we want to strip the .html and get the lang
141 file_split
= file.split('.')
142 file_base
= os
.path
.basename( file_split
[0] )
143 if (len(file_split
) == 2):
146 # possibly necessary for automatic language selection
147 file_symlink
= file.replace(".html", ".en.html")
148 if (not (os
.path
.exists(file_symlink
))):
149 os
.symlink (file, file_symlink
)
150 elif (len(file_split
) == 3):
161 ### we need to replace parts of the file
162 lines
= open(file).readlines()
164 outfile
= open(file, 'w')
166 lang_footer
= makeFooter (file_base
, lang
)
170 ### alter links as appropriate
171 link
= getLocalHref(line
)
174 if (link
.endswith(".html")):
175 langlink
= addLangExt(link
[:-5], lang
, "html")
176 line
= line
.replace(link
, langlink
)
177 if (link
.endswith(".pdf")):
178 langlink
= addLangExt(link
[:-4], lang
, "pdf")
179 line
= line
.replace(link
, langlink
)
180 ### add google tracker header
181 if (line
.find("</head>") >= 0):
182 outfile
.write("""<!-- Google tracking !-->
183 <script src="http://www.google-analytics.com/urchin.js"
184 type="text/javascript">
186 <script type="text/javascript">
187 _uacct = "UA-68969-1";
191 #### add google tracker goals
192 if (line
.find("href=\"http://download.linuxaudio.org") >= 0):
193 # TODO: more ugly hardcoding to make releases hard. :(
194 if (line
.find('2.12') >= 0):
195 line
= line
.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.12\');\" href=')
196 elif (line
.find('2.13') >= 0):
197 line
= line
.replace('a href=', 'a onClick=\"javascript:urchinTracker(\'/download/v2.13\');\" href=')
198 ### add language selection footer
199 if (line
.find("<div id=\"verifier_texinfo\">") >= 0):
200 outfile
.write("<div id=\"footer\">\n")
201 outfile
.write( lang_footer
)
202 if (line
.find("</body") >= 0):
203 outfile
.write("</div>\n")