From 22a718ea89bb78e25532d5256dc212cd0bcba94e Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 7 Apr 2011 03:53:31 +0200 Subject: Replace translation engine with php-gettext. Signed-off-by: Lukas Fleischer --- web/lib/aur.inc | 8 ++++---- web/lib/translator.inc | 16 ++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) (limited to 'web') diff --git a/web/lib/aur.inc b/web/lib/aur.inc index 0e494a2d..744b31e6 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -248,10 +248,10 @@ function db_query($query="", $db_handle="") { # set up the visitor's language # function set_lang() { - global $_t; global $LANG; global $SUPPORTED_LANGS; global $PERSISTENT_COOKIE_TIMEOUT; + global $streamer, $l10n; $update_cookie = 0; if (isset($_REQUEST['setlang'])) { @@ -292,9 +292,9 @@ function set_lang() { setcookie("AURLANG", $LANG, $cookie_time, "/"); } - if ($LANG != "en" ) { - include_once("$LANG.po"); - } + $streamer = new FileReader('../locale/' . $LANG . + '/LC_MESSAGES/aur.mo'); + $l10n = new gettext_reader($streamer, true); return; } diff --git a/web/lib/translator.inc b/web/lib/translator.inc index 6bb93588..c4508a9e 100644 --- a/web/lib/translator.inc +++ b/web/lib/translator.inc @@ -22,12 +22,14 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR # print __("This is a %hmajor%h problem!", "", ""); include_once('config.inc'); +include_once('gettext.php'); +include_once('streams.php'); -global $_t; +global $streamer, $l10n; function __() { - global $_t; global $LANG; + global $l10n; # Create the translation. $args = func_get_args(); @@ -35,14 +37,8 @@ function __() { # First argument is always string to be translated $tag = $args[0]; - # If there is no translation, just print the given string. - if (empty($_t[$tag])) { - $translated = $tag; - } - else { - $translated = $_t[$tag]; - } - + # Translate using gettext_reader initialized before. + $translated = $l10n->translate($tag); $translated = htmlspecialchars($translated, ENT_QUOTES); $num_args = sizeof($args); -- cgit v1.2.3-24-g4f1b