"locale_help", "admin" => "locale_admin", "locale" => "locale_locale"); function locale_help() { ?>

Normally programs are written and documented in English, and use English to interact with users. This is true for a great deal of websites. However, most people are less comfortable with English than with their own native language, and would prefer to use their mother tongue as much as possible. Many people love see their website showing a lot less of English, and far more of their own language.

Therefore drupal provides a framework to setup a multi-lingual website, or to overwrite the default texts in English. We explored the various alternatives to support internationalization and decided to design the framework in such a way that the impact of internationalization on drupal's sources is minimized, modular and that it doesn't require a HTML or PHP wizard to maintain translations. Maintaining translations had to be simple so it became as easy as filling out forms on the administration page. A side effect is that translation support adds significant overhead to the dynamic generation of your website. If you don't need translation support, consider to turn it off.

Adding a new language

Adding a new language requires you to edit your configuration file and to edit your SQL database. Assuming you want to support Dutch (ISO 639 code: "nl") and French (ISO 639 code: "fr"), you add the following line to your configuration file's $languages-variable:

    $languages = array("nl" => "Dutch / Nederlands", "fr" => "French / Francais");
  

Note that the default language must come first and that if you want to overwrite the default text you can add an entry for English (ISO 639 code: "en"):

    $languages = array("en" => "English", "nl" => "Dutch / Nederlands", "fr" => "French / Francais");
  

After having edited your configuration file, make sure your SQL table "locales" has the required database fields setup to host your new translations. You can add the required rows to your "locales" table from the MySQL prompt:

    mysql> ALTER TABLE locales ADD en TEXT DEFAULT '' NOT NULL;
    mysql> ALTER TABLE locales ADD nl TEXT DEFAULT '' NOT NULL;
    mysql> ALTER TABLE locales ADD fr TEXT DEFAULT '' NOT NULL;
  
$value) { db_query("UPDATE locales SET $key = '". check_input($value) ."' WHERE id = '$id'"); } } function locale_edit($id) { global $languages; $result = db_query("SELECT * FROM locales WHERE id = '$id'"); if ($translation = db_fetch_object($result)) { $output .= "
\n"; $output .= "Original string:
\n"; $output .= "
". wordwrap(check_output($translation->string)) ."

"; foreach ($languages as $code=>$language) { $output .= "$language:
"; $output .= (strlen($translation->string) > 30) ? "

" : "$code) ."\">

"; } $output .= "\n"; $output .= "\n"; $output .= "

\n"; print $output; } } function locale_languages($translation) { global $languages; foreach ($languages as $key=>$value) { $output .= ($translation->$key) ? "$key " : "$key "; } return $output; } function locale_display() { $result = db_query("SELECT * FROM locales ORDER BY string"); $output .= "\n"; $output .= " \n"; while ($locale = db_fetch_object($result)) { $languages = locale_languages($locale); $output .= " "; } $output .= "
stringlanguagesoperations
". check_output($locale->string) ."
$locale->location
$languagesid\">editid\">delete
\n"; print $output; } function locale_admin() { global $id, $edit, $op; print "overview | help
\n"; switch ($op) { case "delete": locale_delete(check_input($id)); locale_display(); break; case "help": locale_help(); break; case "edit": locale_edit(check_input($id)); break; case "Save translations": locale_save(check_input($id), $edit); // fall through default: locale_display(); } } function locale($string) { global $locale; if ($locale) { $result = db_query("SELECT id, $locale FROM locales WHERE STRCMP(string, '". addslashes($string) ."') = 0"); if ($translation = db_fetch_object($result)) $string = ($translation->$locale) ? check_output($translation->$locale) : $string; else db_query("INSERT INTO locales (string, location) VALUES ('". addslashes($string) ."', '". check_input(getenv("REQUEST_URI")) ."')"); } return $string; } ?>