Replace translation engine with php-gettext.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2011-04-07 03:53:31 +02:00
parent 779ecc8c3a
commit 22a718ea89
2 changed files with 10 additions and 14 deletions

View file

@ -248,10 +248,10 @@ function db_query($query="", $db_handle="") {
# set up the visitor's language # set up the visitor's language
# #
function set_lang() { function set_lang() {
global $_t;
global $LANG; global $LANG;
global $SUPPORTED_LANGS; global $SUPPORTED_LANGS;
global $PERSISTENT_COOKIE_TIMEOUT; global $PERSISTENT_COOKIE_TIMEOUT;
global $streamer, $l10n;
$update_cookie = 0; $update_cookie = 0;
if (isset($_REQUEST['setlang'])) { if (isset($_REQUEST['setlang'])) {
@ -292,9 +292,9 @@ function set_lang() {
setcookie("AURLANG", $LANG, $cookie_time, "/"); setcookie("AURLANG", $LANG, $cookie_time, "/");
} }
if ($LANG != "en" ) { $streamer = new FileReader('../locale/' . $LANG .
include_once("$LANG.po"); '/LC_MESSAGES/aur.mo');
} $l10n = new gettext_reader($streamer, true);
return; return;
} }

View file

@ -22,12 +22,14 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR
# print __("This is a %hmajor%h problem!", "<b>", "</b>"); # print __("This is a %hmajor%h problem!", "<b>", "</b>");
include_once('config.inc'); include_once('config.inc');
include_once('gettext.php');
include_once('streams.php');
global $_t; global $streamer, $l10n;
function __() { function __() {
global $_t;
global $LANG; global $LANG;
global $l10n;
# Create the translation. # Create the translation.
$args = func_get_args(); $args = func_get_args();
@ -35,14 +37,8 @@ function __() {
# First argument is always string to be translated # First argument is always string to be translated
$tag = $args[0]; $tag = $args[0];
# If there is no translation, just print the given string. # Translate using gettext_reader initialized before.
if (empty($_t[$tag])) { $translated = $l10n->translate($tag);
$translated = $tag;
}
else {
$translated = $_t[$tag];
}
$translated = htmlspecialchars($translated, ENT_QUOTES); $translated = htmlspecialchars($translated, ENT_QUOTES);
$num_args = sizeof($args); $num_args = sizeof($args);