1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
# -*- mode: indented-text -*-
# Copyright (C) 2004 Sergey Poznyakoff
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
Import: copy
Import: string
Import: posix
Include: i18n.inc
# Index of the current item withing the item group (e.g. ROW,
# ENUMERATE, etc
Global: item_index
0
# Index of the current row within the row group (TABULAR)
Global: row_index
0
Global: translist
{}
Function: translate_name n
name = xtrans.filenames[n];
if xtrans.translist.has_key(name):
return xtrans.translist[name]
return name
# Encode the UTF-8 WORD into the hex notation suitable for passing it
# as a GET argument to the CGI invocation.
Function: dict_encode_string word
str = ""
for i in range(len(word)):
if ord(word[i]) > 127:
str = str + "%" + hex(ord(word[i]))[2:]
else:
str = str + word[i]
return str
# Create a template for a page
Function: PageTemplate title
hb = """
<BODY BGCOLOR="#000080" TEXT="#000000" LINK="#1F00FF" ALINK="#FF0000" VLINK="#9900DD">
<TABLE WIDTH="99%%" ALIGN="CENTER" CELLSPACING="0" CELLPADDING="10%%" BORDER="0" BGCOLOR="#FFFFFF">
<TR>
<TD VALIGN=TOP width="20%%">
<IMG SRC="graphics/gnu-head-sm.jpg" ALIGN="top" ALT=" [A GNU head] "><P>
<TABLE WIDTH="100%%" ALIGN="LEFT" CELLSPACING="0" CELLPADDING="10%%" BORDER="0" BGCOLOR="#FFFFFF">
[TOC]
<TR><TD BGCOLOR="#0063C1"><CENTER><STRONG><FONT color="white">%s</FONT></STRONG></CENTER></TD></TR>
<TR><TD><A HREF="%s">%s</A></TD></TR>
<TR><TD><A HREF="http://validator.w3.org/check/referer">
<img border="0" src="graphics/valid-html401.png"
alt="[ Valid HTML 4.01! ]" height="31" width="88"></A></TD></TR>
</TABLE>
</TD>
<TD VALIGN=top>
<H1 ALIGN=CENTER>%s</H1>
<HR>
"""
xtrans.output.write(hb %
(xtrans.gettext("Πληροφορίες"),
xtrans.attr["AUTHOR"]["HOMEPAGE"],
xtrans.gettext("Αρχική σελίδα"),
title))
# Create and open a new page
Function: OpenPage title, prefix
xtrans.SetLocale(xtrans.attr["LINGUA"]["LANG"])
xtrans.set_output(title, prefix)
if xtrans.content.has_key("AUTHOR") and xtrans.attr["AUTHOR"].has_key("EMAIL"):
xtrans.email = xtrans.attr["AUTHOR"]["EMAIL"]
else:
xtrans.email = "gray@gnu.org"
if xtrans.attr["LINGUA"].has_key("BASE"):
base = xtrans.attr["LINGUA"]["BASE"]
else:
base = posix.environ['BASE_HREF']
hb = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>%s</TITLE>
<LINK REV="made" HREF="mailto:%s">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="%s">
<META NAME="keywords" CONTENT="%s">
<BASE HREF="%s">
</HEAD>
"""
xtrans.output.write(hb % (title,
xtrans.email,
xtrans.generator,
xtrans.content["KEYWORDS"],
base))
xtrans.PageTemplate(title)
Function: ClosePage
xtrans.output.write("""
</TD>
</TR>
<TR>
<TD colspan=\"2\">
<hr>
%s <A HREF="mailto:%s">%s</A>;
</TD>
</TR>
</TABLE>
</BODY></HTML>
"""
% (
xtrans.gettext("Για προτάσεις ή απορίες σχετικά με αυτήν τη σελίδα επικοινωνήστε στο"),
xtrans.attr["AUTHOR"]["EMAIL"],
xtrans.attr["AUTHOR"]["CONTACT"]))
Starttag: LINGUA
if xtrans.attr["LINGUA"].has_key("LANG"):
lang = xtrans.attr["LINGUA"]["LANG"] + "/"
else:
lang = ""
def namegen(xmlprefix, l, base, targetformat, pfx=lang, x=xtrans):
if x.is_parent("CHAPTER"):
n = x.attr["CHAPTER"]["PAGENO"]
x.attr["CHAPTER"]["PAGENO"] = n + 1
else:
n = 0
if n == 0:
return "%s%s.%s" % (pfx, base, targetformat)
else:
return "%s%s_%02d.%s" % (pfx, base, n, targetformat)
def dictref(x=xtrans):
return '/cgi-bin/dict.cgi?LANG=' + \
x.attr["LINGUA"]["LANG"] + \
'_' + \
x.attr["LINGUA"]["TER"]
def navigation(fn, x=xtrans):
if fn > 0:
x.put_menu_item(0, x.translate_name(fn-1),
x.gettext("προηγούμενη σελίδα"))
if fn + 1 < len(x.filenames):
x.put_menu_item(0, x.translate_name(fn+1),
x.gettext("ερχόμενη σελίδα"))
xtrans.attr["NAMEGEN"] = namegen
xtrans.attr["LINGUA"]["DICT"] = dictref
xtrans.attr["LINGUA"]["NAVIGATION"] = navigation
xtrans.attr["LINGUA"]["MENU"] = []
Endtag: LINGUA
xtrans.i18n_cleanup
Starttag: MSGSTR
pass
Endtag: MSGSTR
xtrans.msgid(xtrans.attr["MSGSTR"]["ID"], xtrans.content["MSGSTR"])
Starttag: TITLE nostrip
if xtrans.is_parent("TABULAR"):
xtrans.put('<CAPTION>')
Endtag: TITLE
if xtrans.is_parent("TABULAR"):
xtrans.put('</CAPTION>')
## FIXME: This does not work. WHY?
## Function: get_prefix attr, defval
## if attr.has_key("PREFIX"):
## return attr["PREFIX"]
## for i in range(len(xtrans.tagstack)-1,0,-1):
## if xtrans.attr[xtrans.tagstack[i]].has_key("PREFIX"):
## return xtrans.attr[xtrans.tagstack[i]]["PREFIX"]
## return defval
Function: get_prefix attr, defval
if attr.has_key("PREFIX"):
return attr["PREFIX"]
if xtrans.is_parent("CHAPTER"):
if xtrans.attr["CHAPTER"].has_key("PREFIX"):
return xtrans.attr["CHAPTER"]["PREFIX"]
if xtrans.is_parent("LINGUA"):
if xtrans.attr["LINGUA"].has_key("PREFIX"):
return xtrans.attr["LINGUA"]["PREFIX"]
Function: menu_append_ref filename, label
menu = xtrans.attr[xtrans.tagstack[-1]]["MENU"]
menu.append([0, filename, label])
Function: menu_append_menu submenu, label
menu = xtrans.attr[xtrans.tagstack[-1]]["MENU"]
menu.append([1, submenu, label])
Function: menu_append_function name
menu = xtrans.attr[xtrans.tagstack[-1]]["MENU"]
menu.append([2, name])
Starttag: PAGE
xtrans.OpenPage(xtrans.attr["PAGE"]["TITLE"],
xtrans.get_prefix(xtrans.attr["PAGE"], "prefix"))
if xtrans.attr["PAGE"].has_key("REF"):
name = xtrans.attr["PAGE"]["REF"]
ref = xtrans.attr["LINGUA"][name]()
xtrans.translist[xtrans.filenames[-1]] = ref
else:
ref = xtrans.filenames[-1]
xtrans.menu_append_ref(ref, xtrans.labels[-1])
xtrans.attr["PAGE"]["MENU"] = []
Function: has_group
for i in range(len(xtrans.tagstack)-1,0,-1):
if xtrans.tagstack[i] == "GROUP":
return 1
return 0
Endtag: PAGE
xtrans.ClosePage()
Starttag: CHAPTER
xtrans.attr["CHAPTER"]["PAGENO"]=0
xtrans.attr["CHAPTER"]["MENU"] = []
Endtag: CHAPTER
xtrans.menu_append_menu(xtrans.attr["CHAPTER"]["MENU"], "")
Starttag: SECTION
xtrans.attr["SECTION"]["PAGENO"]=0
xtrans.attr["SECTION"]["MENU"] = []
Endtag: SECTION
xtrans.menu_append_menu(xtrans.attr["SECTION"]["MENU"], "")
Starttag: GROUP
xtrans.attr["GROUP"]["MENU"] = []
Endtag: GROUP
if not xtrans.attr["GROUP"].has_key("HIDDEN"):
xtrans.menu_append_menu(xtrans.attr["GROUP"]["MENU"],
xtrans.attr["GROUP"]["TITLE"])
Endtag: DFN
xtrans.put('<EM>%s</EM>' % xtrans.content["DFN"])
Endtag: CMD
xtrans.put('<CODE>%s</CODE>' % xtrans.content["CMD"])
Endtag: PROG
xtrans.put('<B>%s</B>' % xtrans.content["PROG"])
Endtag: QUOTE
xtrans.put('<I>%s</I>' % xtrans.content["QUOTE"])
# UNUSED?
Function: canonical_name file
s = file[len(xtrans.targetdir):]
if s[0] == '/':
s = s[1:]
return s
Starttag: SEEALSO
xtrans.put("""<A HREF="%s">""" % (xtrans.attr["SEEALSO"]["HREF"]))
Endtag: SEEALSO
xtrans.put("</A>")
Starttag: PARA nostrip
xtrans.put("\n<P>")
Endtag: PARA
xtrans.put("</P>\n")
Endtag: HEADER
if xtrans.is_parent("ITEMIZE"):
attr = xtrans.attr["ITEMIZE"]
n = 5
xtrans.put("<DT>")
xtrans.output.write("\n<H%d>" % n)
if attr.has_key("HREF"):
xtrans.put("""<A HREF="#%s" NAME="%s">""" %
(attr["HREF"], attr["NAME"]))
xtrans.put(xtrans.content["HEADER"])
if attr.has_key("HREF"):
xtrans.put("</A>")
xtrans.put("</H%d>\n" % n)
if xtrans.is_parent("ITEMIZE"):
xtrans.put("</DT>")
Starttag: ITEMIZE
xtrans.put("<DL>")
Endtag: ITEMIZE
xtrans.put("</DL>")
# Split the given text string at split delimiters. Print each part
# except the first one in bold face and indent it one space from
# the previous one
Function: item_split text
if xtrans.attr["TABULAR"].has_key("SPLIT"):
delim = xtrans.attr["TABULAR"]["SPLIT"]
str = ""
for s in text.split(delim):
if str == "" :
str = s
else:
str = str + " <B>" + s + "</B>"
return str;
return text
# Print the contents of the current item using splitting rules.
# SPLIT attribute introduces a split delimiter.
# OR attribute introduces an "or" delimiter
Function: item_text
if xtrans.attr["TABULAR"].has_key("OR"):
delim = xtrans.attr["TABULAR"]["OR"]
str = ""
for s in xtrans.content["ITEM"].split(delim):
if str == "" :
str = xtrans.item_split(s)
else:
str = str + " " + delim + " " + xtrans.item_split(s)
return str;
else:
return xtrans.item_split(xtrans.content["ITEM"])
# Remove any split delimiters from the given text string
Function: restore_single_word text
if xtrans.attr["TABULAR"].has_key("SPLIT"):
delim = xtrans.attr["TABULAR"]["SPLIT"]
str = ""
for s in text.split(delim):
str = str + s
return str;
return text
# Restore the "canonical" form of the item text by removing any split
# delimiters from it and gluing the resulting parts together. If the
# item has several parts separated by "or" delimiters, only the first
# part is acted upon.
Function: restore_word
if xtrans.attr["TABULAR"].has_key("OR"):
delim = xtrans.attr["TABULAR"]["OR"]
return xtrans.restore_single_word(xtrans.content["ITEM"].split(delim)[0])
else:
return xtrans.restore_single_word(xtrans.content["ITEM"])
# Create a dictionary reference for a given WORD. REFTEXT gives the
# reference text.
Function: dict_reference word, reftext
xtrans.put('<A HREF="cgi-bin/dict.cgi?LANG=%s_%s&IDENT=%s">%s</A>'
% (xtrans.attr["LINGUA"]["LANG"],
xtrans.attr["LINGUA"]["TER"],
xtrans.dict_encode_string(word),
reftext))
# Return true if we are on the very first data row in a table. Colon
# headings are not counted as data row.
Function: is_first_data_row
if xtrans.attr["TABULAR"].has_key("COLHEADING"):
return xtrans.row_index == 1
else:
return xtrans.row_index == 0
Starttag: ENITEM
xtrans.put('\n<LI>')
Endtag: ENITEM
xtrans.put('</LI>\n')
Endtag: ITEM
if xtrans.is_parent("ENUMERATE"):
xtrans.put('<LI>%s</LI>' % (xtrans.content["ITEM"]))
elif xtrans.is_parent("ROW"):
if xtrans.row_index == 0 and xtrans.attr["TABULAR"].has_key("COLHEADING"):
eltname = "TH"
else:
eltname = "TD"
xtrans.put(" <%s" % eltname)
if xtrans.attr["TABULAR"].has_key("ALTERNATE"):
if xtrans.row_index % 2 == 0:
xtrans.put(' BGCOLOR="#FFFFFF"')
else:
xtrans.put(' BGCOLOR="#CCCCEE"')
xtrans.put(">")
if xtrans.item_index == 0 and xtrans.attr["TABULAR"].has_key("ROWHEADING"):
if xtrans.attr["TABULAR"]["ROWHEADING"] == "ITALICS":
xtrans.put('<I>%s</I>' % (xtrans.content["ITEM"]))
elif xtrans.attr["TABULAR"]["ROWHEADING"] == "BOLD":
xtrans.put('<B>%s</B>' % (xtrans.content["ITEM"]))
else:
xtrans.put('%s' % (xtrans.content["ITEM"]))
else:
if xtrans.is_first_data_row() \
and xtrans.attr["TABULAR"].has_key("DICTREF") \
and xtrans.item_index >= int(xtrans.attr["TABULAR"]["DICTREF"]) \
and (not xtrans.attr["TABULAR"].has_key("DICTREFMAX") \
or xtrans.item_index <= int(xtrans.attr["TABULAR"]["DICTREFMAX"])):
xtrans.dict_reference(xtrans.restore_word(),
xtrans.item_text())
else:
xtrans.put(xtrans.item_text())
xtrans.put(" </%s>" % eltname)
xtrans.item_index = xtrans.item_index + 1
elif xtrans.is_parent("GROUP"):
xtrans.menu_append_function(xtrans.content["ITEM"])
elif xtrans.is_parent("PAGE"):
xtrans.put('<H2>%s</H2>' % (xtrans.content["ITEM"]))
else:
xtrans.put('<DD>%s</DD>' % (xtrans.content["ITEM"]))
Endtag: FLECT
xtrans.put('<B>-%s</B>' % (xtrans.content["FLECT"]))
#Starttag: MENU
# xtrans.menu[xtrans.attr["MENU"]["NAME"]] = []
Starttag: ENUMERATE
xtrans.put("""
<UL>
""")
Endtag: ENUMERATE
xtrans.put("""
</UL>
""")
Endtag: BOLD
xtrans.put("""<B>%s</B>""" % (xtrans.content["BOLD"]))
Endtag: UBOLD
xtrans.put("""<U><B>%s</B></U>""" % (xtrans.content["UBOLD"]))
Endtag: IT
xtrans.put('<I>%s</I>' % (xtrans.content["IT"]))
Function: alignment align
if align == "":
xtrans.put('</DIV>\n')
else:
xtrans.put('<DIV ALIGN="%s">' % (align))
Starttag: TABULAR
if xtrans.attr["TABULAR"].has_key("ALIGN"):
xtrans.alignment(xtrans.attr["TABULAR"]["ALIGN"])
xtrans.put('<TABLE CELLPADDING="10%"')
if not xtrans.attr["TABULAR"].has_key("BESTFIT"):
xtrans.put(' WIDTH="100%"')
if xtrans.attr["TABULAR"].has_key("SHADE"):
xtrans.put(" BGCOLOR=\"COCOCO\"")
xtrans.row_index = 0
xtrans.put(">\n")
Endtag: TABULAR
xtrans.put("</TABLE>\n")
if xtrans.attr["TABULAR"].has_key("ALIGN"):
xtrans.alignment("")
Starttag: ROW
xtrans.item_index = 0
if xtrans.row_index == 0 and xtrans.attr["TABULAR"].has_key("COLHEADING"):
xtrans.put("<THEAD>");
xtrans.put("<TR>\n")
Endtag: ROW
xtrans.put("</TR>")
if xtrans.row_index == 0 and xtrans.attr["TABULAR"].has_key("COLHEADING"):
xtrans.put("</THEAD>");
xtrans.put("\n")
xtrans.row_index = xtrans.row_index + 1
Starttag: LOCALIZATION
pass
Endtag: MSGSTR
xtrans.msgid(xtrans.attr["MSGSTR"]["ID"], xtrans.content["MSGSTR"])
Function: prefix ref
if ref[0] == '/':
return ref[1:]
elif xtrans.attr["LINGUA"].has_key("TARGETDIR"):
return xtrans.attr["LINGUA"]["TARGETDIR"] + "/" + ref
else:
return posix.environ['TARGET_DIR'] + "/" + ref
return ref
Function: put_menu_item cur, ref, label
if cur:
xtrans.put('<TR><TD>%s</TD></TR>\n' % label)
else:
xtrans.put('<TR><TD><A HREF="%s">%s</A></TD></TR>\n' %
(xtrans.prefix(ref), label))
Function: is_cur menu_item, fileno
if fileno == -1:
return 0
else:
return menu_item[1] == xtrans.filenames[fileno]
Function: is_cur_menu menu, fileno
for i in range(len(menu)):
if menu[i][0] == 0 and xtrans.is_cur(menu[i], fileno):
return 1
return 0
Function: out_menu menu, fileno=-1, cutlevel=-1, level=0
for i in range(len(menu)):
if menu[i][0] == 0:
xtrans.put_menu_item(xtrans.is_cur(menu[i], fileno), menu[i][1], menu[i][2])
elif menu[i][0] == 1:
if cutlevel == -1 or level < cutlevel:
if menu[i][2] != "":
xtrans.put('<TR><TD BGCOLOR="#0063C1"><CENTER><STRONG><FONT color="white">%s</FONT></STRONG></CENTER></TD></TR>\n' % menu[i][2])
xtrans.out_menu(menu[i][1], fileno, cutlevel, level+1)
elif level == cutlevel:
if xtrans.is_cur_menu(menu[i][1], fileno):
xtrans.out_menu(menu[i][1], fileno, cutlevel+1, level+1)
elif menu[i][2] == "" and menu[i][1][0][0] == 0:
xtrans.put_menu_item(xtrans.is_cur(menu[i][1][0], fileno),
menu[i][1][0][1], menu[i][1][0][2])
elif menu[i][0] == 2:
xtrans.attr["LINGUA"][menu[i][1]](fileno)
else:
raise "Unknown menu item " + menu[i][0]
# Debugging call
Function: p_menu menu
for i in range(len(menu)):
item = menu[i]
print("IND ", i, "TAG ", item[0], "IT ", item[1], "TW", item[2])
if item[0] == 0:
print("ITEM" , item[1])
elif item[0] == 1:
print("SUB", item[1])
xtrans.p_menu(item[1])
else:
print("MALFORMED MENU")
Postmacro: TOC
menu = xtrans.attr["LINGUA"]["MENU"]
xtrans.out_menu(menu, currentfileno, 1)
Function: menu_map menu, start=0
xtrans.put('<UL>')
for i in range(start,len(menu)):
if menu[i][0] == 0:
xtrans.put('<LI><A HREF="%s">%s</A></LI>\n' %
(xtrans.prefix(menu[i][1]), menu[i][2]))
elif menu[i][0] == 1:
if menu[i][2] != "":
xtrans.put('<LI>%s' % menu[i][2])
xtrans.menu_map(menu[i][1])
xtrans.put('</LI>')
else:
submenu = menu[i][1]
xtrans.put('<LI><A HREF="%s">%s</A>\n' %
(xtrans.prefix(submenu[0][1]), submenu[0][2]))
xtrans.menu_map(submenu, 1)
xtrans.put('\n</LI>\n')
else:
pass
xtrans.put('</UL>')
Postmacro: SITEMAP
menu = xtrans.attr["LINGUA"]["MENU"]
xtrans.menu_map(menu)
|