View Profile Email Personal Message (Online)
Re: Adding FULL support for other regions/country/languages
« Reply #4 on: May 02, 2008, 01:53:17 pm »
Reply with quoteQuote Modify messageModify Remove messageRemove
Hi All!
I tried to translate the Linux MCE to Russion , please find my scripts which perform a first automatic translation:
First script , which takes the string from DB and traslate it to russion( Every one could change this to it lamgauge):
#### Global variables
lang_id=4;
base_lang_id=1;
lang_desc='Russian';
###char_set='utf8';
###char_set='koi8r';
###char_set='cp1251';
char_set='cp866';
dbuser='odbcuser';
dbip='localhost'
#### End Global variables
### create language entry
mysql -u$dbuser -h$dbip -e "insert into \`pluto_main\`.\`Language\` (PK_Language, Description , psc_id) values ($lang_id ,\"$lang_desc\",$lang_id );"
### clean the xisting language from DB
mysql -u$dbuser -h$dbip -e "delete from pluto_main.Text_LS where FK_Language =$lang_id;"
### Read the first string id for english language
fk_text_=`mysql -u$dbuser -h$dbip -e "SELECT FK_Text FROM pluto_main.Text_LS where FK_Text > 0 and FK_Language=$base_lang_id and Description not like '%<\%%' order by FK_Text Limit 1"`;
### clean field name
fk_text=`echo $fk_text_ | cut -f 2 -d " "`
#### do this operation for each record in DB
while [ "$fk_text" != "" ] ; do
### Read the text for string id which stored in fk_text
description_=`mysql -u$dbuser -h$dbip -e "select Description from pluto_main.Text_LS where FK_Text=$fk_text and FK_Language =$base_lang_id;"`
### clean field name
description=`echo $description_ | sed 's/Description //' | sed 's/\\\n//'`;
### tralsation of the string
description_rus=`echo $description | ./trans e2r` ;
### print for debug purpose
echo -----------------------
echo fk_text ::$fk_text::
echo description::$description::
echo description_rus::$description_rus::
echo -----------------------
#### insert the translated string back to DB
mysql -u$dbuser -h$dbip -e "insert into \`pluto_main\`.\`Text_LS\` (FK_Text,FK_Language,Description) values($fk_text,$lang_id,\"$description_rus\");" --default-character-set=$char_set
### Read the next string id for english language
fk_text_=`mysql -u$dbuser -h$dbip -e "SELECT FK_Text FROM pluto_main.Text_LS where FK_Text > $fk_text and FK_Language=$base_lang_id and Description not like '%<\%%' order by FK_Text Limit 1"`;
### clean field name
fk_text=`echo $fk_text_ | cut -f 2 -d " "`
done;
The second script is a perl script which perform an automatic translation from internet ( not such good , but for first time is good enough)
Second script, name "trans":
#!/usr/bin/perl -w
use WWW::Babelfish;
# Dummy UserAgent
use constant AGENT =>
'Mozilla/4.73 [en] (X11; U; Linux)';
# Supported Languages
my @languages = qw(English French German Italian
Portuguese Russian Spanish);
# Build hash that assigns language abbreviations
# to languages (e=>English, g=>German, ...)
foreach my $language (@languages) {
my $initial = substr($language, 0, 1);
$i2full{lc($initial)} = $language;
}
# All abbreviations in one string (efgpirs)
my $chars = join '', keys %i2full;
# Conversion direction from the
# command line (g2e, e2f, ...)
my $way = shift;
usage() unless defined $way;
usage("Scheme $way not supported") unless
($from, $to) = $way =~ /^([$chars])2([$chars])$/;
# Read in text to be translated
my $data = join '', <>;
# Contact Babelfish
my $babel = WWW::Babelfish->new(agent => AGENT);
usage("Cannot connect to Babelfish") unless
defined $babel;
# Perform translation
my $transtext = $babel->translate(
source => $i2full{$from},
destination => $i2full{$to},
text => $data
);
die("Error: " . $babel->error) unless
defined($transtext);
print $transtext, "\n";
##################################################
sub usage {
##################################################
my $msg = shift;
my $prog = $0;
print "usage: $prog ",
"[${chars}]2[${chars}] file ...\n";
foreach $c (sort split //, $chars) {
print " $c: $i2full{$c}\n";
}
exit(1);
}
My scripts are support currently 6 languages :
English French German Italian Portuguese Russian Spanish
You only have to modify them a little to change the language.
The translation are taken from Babelfish.
the second script I took from some Linux forum.( I am really sorry , I forgot who wrote it originally).
However it is not enough.The OrbiterGen could not recognize the fonts.I found in code that if font are not updated , the arial will be used.
Anyone has an ideas where in DB , I need to update the fonts?
Even French and German , which exist in DB could not be recognized well enough.
BTW: How could I add the scripts to the distro?