Hi,
I am currently working on a websiteproject for learning chinese. To help the readers to understand the texts better, I want to annotate the Chinese Characters with popup translations from the HanDeDict (German-Chinese Dictionary).
I already downloaded the dictionary but the file seems to be too big to work with properly.
To get an impression of what I mean you can visit: http://www.dersinologe.de/hdd1py-working3 (Just mouseover the chinese text at the very end of the site and some tooltip dialoges will show)
Now I need your help. How can I annotate the whole text? Below you can see my php-code so far. Is there a better way of doing it? The biggest problem seems to be working with the Dictionary file. As the file is about 12 MB big, I want to pre-annotate the text and then upload the annotated text - so the site won't load for hours.
<?php
$pos=0;
$len=6;
$text='成人業余高中中国中成人玩具的人二千七百成人業余高中成人業余高中零一就像小炸弹,不二流子小心就会爆炸。 虽然他们的样子看起来很平和,但阿巴多是心里藏二流子着很大的攻击性。几十年二千七百零一前毛成人玩具泽东就利用了这一点去建立他心目中的中国,但也是因为这一点很多人在1949年至1977年间失去了生命。攻击性其实是一种很可怕的武器,没人控制得了。一旦失控就不容易停止,要等到人们的情绪慢慢平静下来 。';
echo '$text = <br>'.$text.'<br /><br />';
$textpart=mb_substr($text,$pos,$len,'UTF-8');
$str='';
while($pos<=mb_strlen($text,'UTF-8')){
$textpart=mb_substr($text,$pos,$len,'UTF-8');
if (!$dict[$textpart]['de'] && $len>=1){
$len--;
}
elseif ($dict[$textpart]['de'] && $len>=1){
$textpart='<span class="tttword">'.$textpart.'<span class="ttt">'.$textpart.' - '.$dict[$textpart]['py'].'<br>'.$dict[$textpart]['de'].'</span></span>';
$str=$str.$textpart;
$pos=$pos+$len;
$len=5;
}
elseif ($len<=0){
$textpart=mb_substr($text,$pos,1,'UTF-8');
$str=$str.$textpart;
$pos++;
$len=6;
}
}
echo $str;
?>
I hope you understand my problem and can point me into the right direction, maybe even give some useful code/links/persons that could help me ;-)
Thanks,
Malaoshi