aUCBLogo Demos and Tests / translate_help_examples_split


setCaseIgnored false

be translate_help_examples_split
clearText
   
language="de
   
basepath="D:\temp\help_de
   
load word language "/startup.lg
   
startup_de
   
load "en/startup.lg
   
startup_en
   
setCaseIgnored false
   
translation_en_de=reverse translation_de
   
foreach tolist translation_en
   
[   t=translation_en_de.(?.2)
      
if != []
      
[   i=?.1
;         (pr i t)
         
translation_en_de.i=t
         
i=lowercase ?.1
         
translation_en_de.i=t
         
i=uppercase ?.1
         
translation_en_de.i=t
      
]
   
]
   
translation_en_de=(merge 
      
lowerCase translation_en_de
      
translation_en_de)
   
translation_en_de=(merge 
      
upperCase translation_en_de
      
translation_en_de)
;   print translation_en_de

   
changeDir basepath
   
fl=(files [aucblogo_all_de.hrf.txt])
   
foreach fl
   
[   translateFile ?
   
]
   
   
be myform num width fillch
      
local [w]
      
w=(word num)
      
if (count w) < width
      
[   repeat width-count w
         
[   w=word fillch w
         
]
      
]
      
output w
   
end
   
   
be arform ar m
      
local [w]
      
w="
      
repeat min count ar m
      
[   w=(word w myform ar.repcount "0 "\ )
      
]
      
output w
   
end
   
   
be translateFile in
      
in_en="aucblogo.hrf
      
openRead in_en
      
setReader in_en
      
le=array readListFlatRaw
      
setWriter []
      
close in_en

      
out=(word in ".txt)
      
(print in "=> out)
      
openRead in
      
setReader in
      
ld=array readListFlatRaw
      
setReader []
      
close in

      
l=le
      
cnt=count l
      
sections=[]
      
examples=Table 1021
      
esectab=Table 1021
      
linenr=1
      
example=[]
      
exline="
      
exnr=0
      
for [cnt]
      
[   w=l.i
         
ifelse cnt-3
         
[   ifelse (and w=="
            
l.(i+1)=="\    l.(i+2)=="\   )
            
[   i=i+3
;               (print)
               
linenr=linenr+1
;               (type "#\   \   )
               
exline="\   \   
               
while [and not (and l.== "
                      
(first l.(i+1)) !="\    
                      
(first l.(i+2)) !="\    )
                  
i<cnt-2]
               
[   w=l.i
                  
t=translation_en_de.w
                  
ifelse != [] 
                  
[   w=t
                  
][   
                  
]
;                  (type w)
                  
exline=lput w exline
                  
i=i+1
               
]
               
i=i-1
               
example=lput exline example
            
][
               
ifelse (or i==(and 
                  
w=="
                  
l.(i+1) !="\    
                  
l.(i+1) !="= 
                  
l.(i+1) !="-
                  
(first l.(i+2)) !="\    ))
               
[
                  
examples.exnr=example
                  
example=[]               
                  
exnr=exnr+1
;                  (type w)
;                  (print)
                  
linenr=linenr+1
                  
j=i+2
                  
ifelse (and l.!="
                     
;[l.(j+1) !="
                     ;]
                     
[(first l.(j+1)) !="\   j<cnt-1)
                  
[   title="   ;(word linenr "\   )
;                     (type title)
                  
][   title=[]
                  
]
                  
while [(and l.!="
                     
j<cnt-1)]
                  
[   title=lput l.j title
;                     (type l.j)
                     
j=j+1
                  
]
                  
if (and 
                     
(first l.(j+1)) != "-
                     
(first l.(j+1)) != "=
                     
j<cnt-1)
                  
[
                     
while [(and not (and 
                        
l.=="
                        
l.(j+1) =="
                        
j<cnt-1)]
                     
[
   
;                     (type l.j)
                        
if l.j=="
                        
[   linenr=linenr+1
                        
]
                        
j=j+1
                     
]
                  
]
                  
if title != []
                  
[;   title=lput l.j title
                     
sections=fput title sections
                     
esectab.exnr=title
                  
]
                  
i=j-1
               
][
;               (type w)
               
]
            
]
         
][
;            (type w)
         
]
         
if w=="
         
[   linenr=linenr+1
         
]
      
]
      
examples.exnr=example
      
esections=reverse sections
      
elinenr=linenr

      
l=ld
      
cnt=count l
      
sections=[]
      
dirs=[]
      
linenr=1
      
exnr=0
      
exlnr=1
      
example=[]
      
level=0
      
path=[]
      
secnr={0 0 0}
      
o="
      
ftitle="nothing.txt
      
ftitles=[]
      
abspaths=[]
      
for [cnt]
      
[   w=l.i
         
ifelse cnt-3
         
[   ifelse (and w=="
            
l.(i+1)=="\    l.(i+2)=="\   )
            
[   i=i+3
               
(print)
               
linenr=linenr+1
;               (type "#\   \   )
               
ifelse (count example) >= exlnr
               
[   (type example.exlnr)
               
][
                  
(type "######\  exnr)
               
]
               
while [and not (and l.== "
                      
(first l.(i+1)) !="\    
                      
(first l.(i+2)) !="\    )
                  
i<cnt-2]
               
[   w=l.i
                  
i=i+1
               
]
               
i=i-1
               
exlnr=exlnr+1
            
][
               
ifelse (or i==(and 
                  
w=="
                  
l.(i+1) !="\    
                  
l.(i+1) !="= 
                  
l.(i+1) !="-
                  
(first l.(i+2)) !="\    ))
               
[   exnr=exnr+1
                  
example=examples.exnr
                  
exlnr=1
                  
o=w
                  
if i>1 
                  
[   o=word "
                  
]
                  
linenr=linenr+1
                  
j=i+2
                  
if member? ftitle allopen [close ftitle]
                  
ifelse (and l.!="
                     
[(first l.(j+1)) !="\   j<cnt-1)
                  
[   title="   ;(word linenr "\   )
                  
][   title=[]
                  
]
                  
while [(and l.!= "
                     
j<cnt-1)]
                  
[   title=lput l.j title
                     
o=word o l.j
                     
j=j+1
                  
]
                  
ifelse l.(j+1)=="=
                  
[   ;if level==1 [changeDir "..]
                     
level=1
                     
secnr.1=secnr.1+1
                     
secnr.2=1
                     
secnr.3=0
                     
ftitle=(word arform secnr title)
                     
path=(List ftitle)
                     
abspath=basepath
                     
changeDir abspath
                     
makeDirectory ftitle
                  
][   if l.(j+1)=="-
                     
[   ifelse level==1
                        
[   level=2
                           
secnr.2=secnr.2+1
                           
secnr.3=0
                           
ftitle=(word arform secnr title)
                           
path=lput ftitle path
                           
abspath=(word basepath "\ first path)
                           
changeDir abspath
                           
makeDirectory ftitle
                        
][   ifelse level==2
                           
[   secnr.2=secnr.2+1
                              
secnr.3=0
                              
ftitle=(word arform secnr title)
                              
path=lput ftitle butlast path
                              
abspath=(word basepath "\ first path)
                              
changeDir abspath
                              
makeDirectory ftitle
                           
][   (print [###title)
                           
]
                        
]
                     
]
                  
]
                  
if title != []
                  
[;   title=lput l.j title
                     
secnr.3=secnr.3+1
                     
dirs=fput path dirs
                     
sections=fput title sections
                     
abspath=basepath
                     
foreach path [abspath=(word abspath "\ ?)]
                     
changeDir abspath
                     
abspaths=fput abspath abspaths
                     
ftitle=(word arform secnr remove "
                        
remove "\    remove "_0 title ".txt)
                     
ftitles=fput ftitle ftitles
                     
openWrite ftitle
                     
setWriter ftitle
                  
]
                  
type o
                  
if (and 
                     
(first l.(j+1)) != "-
                     
(first l.(j+1)) != "=
                     
j<cnt-1)
                  
[
                     
while [(and not (and 
                        
l.=="
                        
l.(j+1) =="
                     
j<cnt-1)]
                     
[   (type l.j)
                        
if l.j=="
                        
[   linenr=linenr+1
                        
]
                        
j=j+1
                     
]
                  
]
                  
i=j-1
               
][
                  
(type w)
               
]
            
]
         
][
            
(type w)
         
]
         
if w=="
         
[   linenr=linenr+1
         
]
      
]
      
dirs=reverse dirs
      
sections=reverse sections
      
ftitles=reverse ftitles
      
abspaths=reverse abspaths
      
setWriter []
      
closeall
      
changeDir basepath
      
index="index_logo.txt
      
openWrite index
      
setWriter index
      
(foreach dirs sections esections 
      
[   foreach ?1 [(type "[ "])]
         
(type "[ ?2 "] "[ ?3 "]) (print)
      
])
      
setWriter []
      
close index
      
      
index="index_dir.txt
      
openWrite index
      
setWriter index
      
(foreach abspaths ftitles 
      
[   (type "" ?1 "\ ?2 "") (print)
      
])
      
setWriter []
      
close index

      
index="index.tex
      
openWrite index
      
setWriter index
      
(foreach abspaths ftitles 
      
[   (type "\include{ ?1 "\ ?2 "}
         )
      
])
      
setWriter []
      
close index
   
end
end