Skip to content

Commit

Permalink
Initial language class as a wrapper for using phpgettext as a class a…
Browse files Browse the repository at this point in the history
…nd reading .mo files directly.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/phpsurveyor@2014 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
David Olivier committed Aug 23, 2006
1 parent 54289fc commit 9e0eb9d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions classes/core/language.php
@@ -0,0 +1,37 @@
<?php
/* Wrapper to use phpgettext as a class and omit having an english translation
USAGE:
require_once(dirname(__FILE__).'classes/core/language.php');
$locale = new phpsurveyor_lang('en'); // Char code
print $locale->getTranslation("Hello World!");
*/

require_once(dirname(__FILE__).'/classes/php-gettext/gettext.php');
require_once(dirname(__FILE__).'/classes/php-gettext/streams.php');

class phpsurveyor_lang {

var $gettextclass;

function phpsurveyor_lang($langcode){
if ( $langcode != "en" ) {
$streamer = new FileReader(dirname(__FILE__).'/locale/'.$langcode.'/LC_MESSAGES/'.$langcode.'.mo');
$this->gettextclass = new gettext_reader($streamer);
} else {
$this->gettextclass = false;
}
}

function getTranslation($string)
{
if ($this->gettextclass)
{
return $this->gettextclass->translate($string);
} else {
return $string;
}
}

}

?>

0 comments on commit 9e0eb9d

Please sign in to comment.