Re: Localization Structure Model



Hi,

I'd like to throw in my 2 cents for internationalization of a web site. My
company has a website with 5 million hits per day and that is translated in
5 languages. We use text in a database, but it is cached in files on the
hard drive to speed things up.
First, the following should only be considered if using the normal gettext
turns out to be too slow/inflexible. If it would do, that would be the
easiest and cleanest way. If not:

Proposal:
A database with language translations, with a table +/- like this:

varchar(2) lang,
text       key,
text       domain,
text       text
primary key(lang, domain, key)

The domain field is to be able to make a distinction between let's say the
title on developer.gnome.org and www.gnome.org.
Next, we write a custom function getText (please conside this pseudocode):

function getText($lang, $key, $site) {
  if exists "/tmp/textcache/$site/$lang" and not older then 24 hours {
    include "/tmp/textcache/$site/$lang";
  } else {
    build_file_from_database($site, $lang);
    include "/tmp/textcache/$site/$lang";
  }
  return $strings['$key'];
}

The file that we would include would look like this (this would be the file
/tmp/textcache/www.gnome.org/en:
<?
  $strings['free_software']="GNOME is part of the GNU project, and is free
software";
  $strings['news']="Gnome news";
  $strings['copyright']="All the content on this site is GPL'ed";
?>

And so on. Every language would have it's own file, of course.
The function build_file_from_database just does a select on the table with
the correct parameters:
SELECT * FROM translations WHERE lang='$lang' AND key='$key'
and then write this into the file:
$filename = fopen("/tmp/textcache/$site/$lang");
while($DB->next()){
  fputs($filename, "\$strings['" . $DB->f('key') . "'] = \"" .
$DB->f('text') . "\";"
}

I probably used the functions wrong, but you get the idea I hope. 
So, now making the pages is very simple:

echo "<table><tr><td class=header>",
  getText($lang, "news", $site),
  "</td></tr></table>";

$lang and $site can be set in a property of a session object Visitor, or
just normal session variables, depending on the architecture of the rest of
the site.

We could make some web applications to allow easy translations, or write a
tool to import .po files to this database so that translators can use
existing translation tools. We'd have to write .po files so that the key
would appear in a comment or something, but that can be done.


cheers,

roel







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]