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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
|
# -*- 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
# Maximum number of items per row in the current table
Global: max_items
0
# Row index of the last separator row in the current table
Global: separator_row
0
# Dictionary of file name translations
Global: translist
{}
# Dictionary of cross-reference identifiers
Global: id_table
{}
# Override the default file name creation method
Function: create_file_name l, base
"""Create new output file name"""
if xtrans.attr["LINGUA"].has_key("LANG"):
lang = xtrans.attr["LINGUA"]["LANG"] + "/"
else:
lang = ""
a = xtrans.get_attribute("PAGENO")
if a == None:
return "%s%s.%s" % (lang, base, xtrans.targetformat)
else:
n = a["PAGENO"]
a["PAGENO"] = n + 1
if n == 0:
return "%s%s.%s" % (lang, base, xtrans.targetformat)
else:
return "%s%s_%02d.%s" % (lang, base, n, xtrans.targetformat)
Function: translate_name name
if xtrans.translist.has_key(name):
return xtrans.translist[name]
return name
Function: translate_name_id n
return xtrans.translate_name(xtrans.filenames[n])
# 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
Function: get_attribute name, attr=None
if attr != None and attr.has_key(name):
return attr
for i in range(len(xtrans.tagstack),0,-1):
if xtrans.attr.has_key(xtrans.tagstack[i-1]) \
and xtrans.attr[xtrans.tagstack[i-1]].has_key(name):
return xtrans.attr[xtrans.tagstack[i-1]]
return None
Function: get_attrval name, defval, attr=None
a = xtrans.get_attribute(name, attr)
if a == None:
return defval
return a[name]
# Expand quoted tags in TEXT. Quoted tags are tags in the form {TAG}{/TAG}
# This is a way to compensate for lack of proper quoting and recursive tags (a la m4).
# Some time later I should definitely add both features to eXtrans.
# FIXME: 1) Tag delimiters are hardcoded.
# 2) The function ignores any attributes in tags
Function: expand_text text
r = re.compile("{(\w+)}", re.UNICODE);
e = re.compile("{/(\w+)}", re.UNICODE);
while 1:
m = r.search(text)
if m:
xtrans.output.write(text[:m.start()])
text = text[m.end():]
# FIXME: Attrs
xtrans.finish_starttag(m.group(1), {})
k = e.search(text)
if k:
xtrans.content[k.group(1)] = text[:k.start()]
xtrans.finish_endtag(k.group(1))
else:
raise "Not found end tag for " + m.group(1)
text = text[k.end():]
continue
else:
break
xtrans.output.write(text)
# Create a template for a page
Function: PageTemplate title
xtrans.output.write("""
<BODY>
<TABLE class="main" WIDTH="99%%" ALIGN="CENTER" CELLSPACING="0" CELLPADDING="10%%" RULES="COLS">
<TR>
<TD VALIGN=top CLASS="contentpanel">
<H1 ALIGN=CENTER>""")
xtrans.expand_text(title)
xtrans.output.write("""</H1>
<HR>
""")
# 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">
<LINK REL="stylesheet" TYPE="text/css" HREF="%s">
</HEAD>
"""
xtrans.output.write(hb % (title,
xtrans.email,
xtrans.generator,
xtrans.content["KEYWORDS"],
base,
xtrans.prefix("mainstyle.css")))
if xtrans.attr["PAGE"].has_key("HEADER"):
title = xtrans.attr["PAGE"]["HEADER"]
xtrans.PageTemplate(title)
Function: ClosePage
xtrans.output.write("""
</TD>
<TD class="navbar" VALIGN=TOP width="20%%">
<IMG SRC="graphics/gnu-head-sm.jpg" ALIGN="top" ALT=" [A GNU head] "><P>
<TABLE class="navbar" WIDTH="100%%" ALIGN="LEFT" CELLSPACING="0" CELLPADDING="10%%" BORDER="0">
[TOC]
<TR><TD class="group"><DIV ALIGN="CENTER">%s</DIV></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>
<TR><TD><a href="http://jigsaw.w3.org/css-validator/check/referer">
<img border="0" src="graphics/valid-css.png"
alt="[ Valid CSS! ]" height="31" width="88"></A></TD></TR>
</TABLE>
</TD>
</TR>
<TR>
<TD colspan=\"2\">
<hr>
%s <A HREF="mailto:%s">%s</A>;
</TD>
</TR>
</TABLE>
</BODY></HTML>
"""
% (
xtrans.gettext("Information"),
xtrans.attr["AUTHOR"]["HOMEPAGE"],
xtrans.gettext("Home Page"),
xtrans.gettext("For information about this site contact"),
xtrans.attr["AUTHOR"]["EMAIL"],
xtrans.attr["AUTHOR"]["CONTACT"]))
Starttag: LINGUA
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_id(fn-1),
x.gettext("Previous Page"))
if fn + 1 < len(x.filenames):
x.put_menu_item(0, x.translate_name_id(fn+1),
x.gettext("Next Page"))
xtrans.attr["LINGUA"]["DICT"] = dictref
xtrans.attr["LINGUA"]["NAVIGATION"] = navigation
xtrans.attr["LINGUA"]["MENU"] = []
Endtag: LINGUA
pass
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>')
Function: get_prefix attr, defval
return xtrans.get_attrval("PREFIX", defval, attr)
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]
if xtrans.attr["PAGE"].has_key("HEADER"):
label = xtrans.attr["PAGE"]["HEADER"]
else:
label = xtrans.labels[-1]
xtrans.menu_append_ref(ref, label)
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()
Function: begin_block attr
if attr.has_key("ID"):
xtrans.put('<A NAME="%s"></A>\n' % attr["ID"])
if xtrans.id_table.has_key(attr["ID"]):
raise "ID already defined: " + attr["ID"]
xtrans.id_table[attr["ID"]] = xtrans.filenames[-1]
Starttag: CHAPTER
xtrans.begin_block(xtrans.attr["CHAPTER"])
xtrans.attr["CHAPTER"]["PAGENO"]=0
xtrans.attr["CHAPTER"]["MENU"] = []
Endtag: CHAPTER
xtrans.menu_append_menu(xtrans.attr["CHAPTER"]["MENU"], "")
Starttag: SECTION
xtrans.begin_block(xtrans.attr["SECTION"])
Endtag: SECTION
xtrans.put("<HR>")
Starttag: SUBSECTION
xtrans.begin_block(xtrans.attr["SUBSECTION"])
Starttag: SUBSUBSECTION
xtrans.begin_block(xtrans.attr["SUBSUBSECTION"])
Starttag: PAGEGROUP
if xtrans.attr["PAGEGROUP"].has_key("PREFIX"):
xtrans.attr["PAGEGROUP"]["PAGENO"]=0
xtrans.attr["PAGEGROUP"]["MENU"] = []
Endtag: PAGEGROUP
xtrans.menu_append_menu(xtrans.attr["PAGEGROUP"]["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: XREF
if xtrans.attr["XREF"].has_key("URL"):
xtrans.put("<A HREF=\"%s\">" % xtrans.attr["XREF"]["URL"])
elif xtrans.id_table.has_key(xtrans.attr["XREF"]["REF"]):
fname = xtrans.id_table[xtrans.attr["XREF"]["REF"]]
xtrans.put('<A HREF="')
if fname != xtrans.filenames[-1]:
xtrans.put(xtrans.prefix(xtrans.translate_name(fname)))
xtrans.put('#%s">' % xtrans.attr["XREF"]["REF"])
else:
raise "Undefined or forward reference " + xtrans.attr["XREF"]["REF"]
Endtag: XREF
xtrans.put("</A>")
Starttag: PARA nostrip
xtrans.put("\n<P>")
Endtag: PARA
# FIXME: This may generate empty <P> blocks
if not xtrans.attr["PARA"].has_key("__CLOSED__"):
xtrans.put("</P>\n")
Starttag: HEADER nostrip
if xtrans.is_parent("SECTION"):
n = 2
elif xtrans.is_parent("SUBSECTION"):
n = 3
elif xtrans.is_parent("SUBSUBSECTION"):
n = 4
else:
n = 1
xtrans.begin_block(xtrans.attr["HEADER"])
xtrans.output.write('\n<H%d ALIGN="CENTER">' % n)
Endtag: HEADER
if xtrans.is_parent("SECTION"):
n = 2
elif xtrans.is_parent("SUBSECTION"):
n = 3
elif xtrans.is_parent("SUBSUBSECTION"):
n = 4
else:
n = 1
xtrans.output.write("</H%d>\n" % n)
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, backref=0
xtrans.put('<A ')
if backref:
xtrans.put('NAME="id%s" ' % xtrans.dict_encode_string(word))
xtrans.put('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
# Return effective row index
# Rows are numbered from 1, column headings are not counted
Function: eff_row_index
if xtrans.attr["TABULAR"].has_key("COLHEADING"):
return xtrans.row_index
else:
return xtrans.row_index + 1
# Return effective column (item) index
# Columns are numbered from 1, row headings are not counted
Function: eff_col_index
if xtrans.attr["TABULAR"].has_key("ROWHEADING"):
return xtrans.item_index
else:
return xtrans.item_index + 1
Starttag: ENITEM nostrip
xtrans.put('\n<LI>')
Endtag: ENITEM
xtrans.put('</LI>\n')
# Map structure: [ start-col, end-col, start-row, end-row, need-ref? ]
Function: parse_dictref str
map = [-1,-1,-1,-1, 0]
for s in str.split(";"):
x = s.split(":")
if x[0] == "col":
n = 0
elif x[0] == "row":
n = 2
elif x[0] == "ref":
map[4] = 1
continue
else:
raise "Unknown modifier " + x[0]
map[n] = int(x[1])
if len(x) == 3:
map[n+1] = int(x[2])
else:
map[n+1] = 0
if map[0] == -1 and map[2] != -1:
map[0] = 1
map[1] = 1
elif map[2] == -1 and map[0] != -1:
map[2] = 1
map[3] = 1
return map
Function: need_dictref
if xtrans.attr["TABULAR"].has_key("DICTREF"):
map = xtrans.parse_dictref(xtrans.attr["TABULAR"]["DICTREF"])
if (map[0] != -1 \
and (map[0] == 0 or map[0] <= xtrans.eff_col_index()) \
and (map[1] == 0 or map[1] >= xtrans.eff_col_index()))\
and (map[2] != -1 \
and (map[2] == 0 or map[2] <= xtrans.eff_row_index()) \
and (map[3] == 0 or map[3] >= xtrans.eff_row_index())):
return map[4] + 1
else:
return 0
# NOTE: Expansion of quoted tags is performed only for:
# 1) Enumeration items
# 2) Row headings in tables
# 3) Table items, for which no DICTREF is requested
# 4) Page items
Endtag: ITEM
if xtrans.is_parent("ENUMERATE"):
xtrans.put('<LI>')
xtrans.expand_text(xtrans.content["ITEM"])
xtrans.put('</LI>')
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["ITEM"].has_key("SPAN"):
if xtrans.attr["ITEM"]["SPAN"] == "0":
n = xtrans.max_items
else:
n = xtrans.attr["ITEM"]["SPAN"]
xtrans.put(' COLSPAN="%s" ALIGN="CENTER"' % n)
if xtrans.item_index == 0 and xtrans.attr["TABULAR"].has_key("ROWHEADING"):
xtrans.put(' CLASS="%s"' % xtrans.attr["TABULAR"]["ROWHEADING"])
xtrans.put(">")
if xtrans.item_index == 0 and xtrans.attr["TABULAR"].has_key("ROWHEADING"):
xtrans.expand_text(xtrans.content["ITEM"])
else:
x = xtrans.need_dictref()
if x:
xtrans.dict_reference(xtrans.restore_word(),
xtrans.item_text(), x)
else:
xtrans.expand_text(xtrans.item_text())
xtrans.put("</%s>" % eltname)
xtrans.item_index = xtrans.item_index + 1
if xtrans.max_items < xtrans.item_index:
xtrans.max_items = xtrans.item_index
elif xtrans.is_parent("GROUP"):
xtrans.menu_append_function(xtrans.content["ITEM"])
elif xtrans.is_parent("PAGE"):
xtrans.put('<H2>')
xtrans.expand_text(xtrans.content["ITEM"])
xtrans.put('</H2>')
else:
xtrans.put('<DD>')
xtrans.expand_text(xtrans.content["ITEM"])
xtrans.put('</DD>')
Endtag: FLECT
if xtrans.attr["FLECT"].has_key("SPLIT"):
str = ""
for s in xtrans.content["FLECT"].split(xtrans.attr["FLECT"]["SPLIT"]):
if str == "" :
str = "-" + s
else:
str = str + " " + ", -" + s
xtrans.put('<B>%s</B>' % str)
else:
xtrans.put('<B>-%s</B>' % (xtrans.content["FLECT"]))
Endtag: PREF
xtrans.put('<B>%s</B>' % (xtrans.content["PREF"]))
Endtag: SUFF
xtrans.put('<B>%s</B>' % (xtrans.content["SUFF"]))
Endtag: DICTREF
xtrans.dict_reference(xtrans.content["DICTREF"],
xtrans.content["DICTREF"])
#Starttag: MENU
# xtrans.menu[xtrans.attr["MENU"]["NAME"]] = []
Starttag: ENUMERATE
if xtrans.is_parent("PARA"):
xtrans.attr["PARA"]["__CLOSED__"] = 1
xtrans.put("\n</P>\n")
xtrans.put('<UL>\n')
Endtag: ENUMERATE
xtrans.put('</UL>\n')
Endtag: EMPH nostrip
xtrans.put("""<B>%s</B>""" % (xtrans.content["EMPH"]))
Endtag: SUBSCRIPT nostrip
xtrans.put("""<sub>%s</sub>""" % (xtrans.content["SUBSCRIPT"]))
Endtag: DFN nostrip
xtrans.put("""<DFN>%s</DFN>""" % (xtrans.content["DFN"]))
Endtag: IT nostrip
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.is_parent("PARA"):
xtrans.attr["PARA"]["__CLOSED__"] = 1
xtrans.put("\n</P>\n")
if xtrans.attr["TABULAR"].has_key("SPACE"):
for i in range(int(xtrans.attr["TABULAR"]["SPACE"])):
xtrans.put('<BR>')
if xtrans.attr["TABULAR"].has_key("ALIGN"):
if xtrans.attr["TABULAR"]["ALIGN"] != "NONE":
xtrans.alignment(xtrans.attr["TABULAR"]["ALIGN"])
else:
xtrans.alignment("CENTER")
xtrans.put('<TABLE CELLPADDING="10%" ')
if xtrans.attr["TABULAR"].has_key("TYPE"):
if xtrans.attr["TABULAR"]["TYPE"] == "EXAMPLE":
xtrans.attr["TABULAR"]["NOFRAME"] = 1
if not xtrans.attr["TABULAR"].has_key("NOFRAME"):
xtrans.put(' frame="box"')
if not xtrans.attr["TABULAR"].has_key("BESTFIT"):
xtrans.put(' WIDTH="95%"')
if xtrans.attr["TABULAR"].has_key("CLASS"):
xtrans.put(' class="%s"' % (xtrans.attr["TABULAR"]["CLASS"]))
xtrans.put(">\n")
if xtrans.attr["TABULAR"].has_key("TYPE"):
if xtrans.attr["TABULAR"]["TYPE"] == "EXAMPLE":
xtrans.put('<COL REPEAT=2 WIDTH="50%">\n')
xtrans.row_index = 0
xtrans.max_items = 0
xtrans.separator_row = 0
Endtag: TABULAR
xtrans.put("</TABLE>\n")
if not xtrans.attr["TABULAR"].has_key("ALIGN") \
or xtrans.attr["TABULAR"]["ALIGN"] != "NONE":
xtrans.alignment("")
if xtrans.attr["TABULAR"].has_key("AFTERSPACE"):
for i in range(int(xtrans.attr["TABULAR"]["AFTERSPACE"])):
xtrans.put('<BR>')
Starttag: ROW
xtrans.item_index = 0
if xtrans.row_index == 0 and xtrans.attr["TABULAR"].has_key("COLHEADING"):
xtrans.put('<THEAD class="%s">' % xtrans.attr["TABULAR"]["COLHEADING"]);
xtrans.put("<TR>\n")
else:
xtrans.put("<TR")
if xtrans.attr["TABULAR"].has_key("ALTERNATE"):
if (xtrans.row_index - xtrans.separator_row) % 2 == 0:
xtrans.put(' class="even"')
else:
xtrans.put(' class="odd"')
xtrans.put(">\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: SEPARATOR
if xtrans.attr["SEPARATOR"].has_key("SPAN"):
max_items = int(xtrans.attr["SEPARATOR"]["SPAN"])
else:
max_items = xtrans.max_items
xtrans.put('\n<TR><TD COLSPAN="%d" class="separator">' % max_items)
Endtag: SEPARATOR
xtrans.put('</TD></TR>\n')
if xtrans.attr["SEPARATOR"].has_key("INITCOUNT"):
xtrans.separator_row = xtrans.row_index = 0
else:
xtrans.separator_row = xtrans.row_index
Function: class_begin attr, class_name
if xtrans.is_parent("ROW"):
tag = "TD"
elif xtrans.is_parent("TABULAR"):
xtrans.put('<TR class="%s">' % (class_name))
tag = "TD"
elif attr.has_key("TYPE"):
if attr["TYPE"] == "INLINE":
tag = "SPAN"
else:
tag = "DIV"
elif attr.has_key("ALIGN"):
tag = "DIV ALIGN=\"" + attr["ALIGN"] + "\""
else:
tag = "SPAN"
xtrans.put('<%s class="%s">' % (tag, class_name))
Function: class_end attr
if xtrans.is_parent("ROW"):
tag = "TD"
elif xtrans.is_parent("TABULAR"):
tag = "TD"
elif attr.has_key("TYPE"):
if attr["TYPE"] == "INLINE":
tag = "SPAN"
else:
tag = "DIV"
elif attr.has_key("ALIGN"):
tag = "DIV"
else:
tag = "SPAN"
xtrans.put('</%s>' % tag)
if xtrans.is_parent("TABULAR"):
xtrans.put('</TR>')
Starttag: EXAMPLE nostrip
xtrans.class_begin(xtrans.attr["EXAMPLE"], "example")
Endtag: EXAMPLE
xtrans.class_end(xtrans.attr["EXAMPLE"])
Starttag: TRANS nostrip
xtrans.class_begin(xtrans.attr["TRANS"], "translation")
Endtag: TRANS
xtrans.class_end(xtrans.attr["TRANS"])
Starttag: SAMP
xtrans.put('<SPAN class="sample">')
Endtag: SAMP
xtrans.put('</SPAN>')
Endtag: NOTREADY
xtrans.put("""<table class="notready">
<tr>
<td><img border="0" src="graphics/construction.jpg" alt="[ Construction Bar ]" width="300" height="28"></img></td>
<td class="notready">%s</td>
<td><img border="0" src="graphics/construction.jpg" alt="[ Construction Bar ]" width="300" height="28"></img></td>
</table>""" % (xtrans.content["NOTREADY"]))
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, level=0
xtrans.put('<TR><TD>')
if level > 0:
for i in range(level-1):
xtrans.put('>')
if cur:
xtrans.expand_text(label)
else:
xtrans.put('<A HREF="%s">' % xtrans.prefix(ref))
xtrans.expand_text(label)
xtrans.put('</A>')
xtrans.put('</TD></TR>\n')
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:
if xtrans.is_cur(menu[i], fileno):
return 1
elif menu[i][0] == 1:
if xtrans.is_cur_menu(menu[i][1], fileno):
return 1
return 0
Function: out_menu menu, fileno=-1, cutlevel=-1, level=0, start=0
for i in range(start,len(menu)):
if menu[i][0] == 0:
xtrans.put_menu_item(xtrans.is_cur(menu[i], fileno), menu[i][1], menu[i][2], level)
elif menu[i][0] == 1:
if cutlevel == -1 or level < cutlevel:
if menu[i][2] != "":
xtrans.put('<TR><TD class="group"><DIV ALIGN="CENTER">%s</DIV></TD></TR>\n' % menu[i][2])
xtrans.out_menu(menu[i][1], fileno, cutlevel, level+1)
elif level == cutlevel:
if 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],
level)
if xtrans.is_cur_menu(menu[i][1], fileno):
xtrans.out_menu(menu[i][1], fileno, cutlevel+1,
level+1, 1)
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">' % (xtrans.prefix(menu[i][1])))
xtrans.expand_text(menu[i][2])
xtrans.put('</A></LI>\n')
elif menu[i][0] == 1:
if menu[i][2] != "":
xtrans.put('<LI>')
xtrans.expand_text(menu[i][2])
xtrans.menu_map(menu[i][1])
xtrans.put('</LI>')
else:
submenu = menu[i][1]
xtrans.put('<LI><A HREF="%s">' % (xtrans.prefix(submenu[0][1])))
xtrans.expand_text(submenu[0][2])
xtrans.put('</A>\n')
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)
|